Commit inicial - WordPress Análisis de Precios Unitarios

- WordPress core y plugins
- Tema Twenty Twenty-Four configurado
- Plugin allow-unfiltered-html.php simplificado
- .gitignore configurado para excluir wp-config.php y uploads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-11-03 21:04:30 -06:00
commit a22573bf0b
24068 changed files with 4993111 additions and 0 deletions

View File

@@ -0,0 +1,448 @@
<?php
/******************************************************************************************
* Copyright (C) Smackcoders. - All Rights Reserved under Smackcoders Proprietary License
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* You can contact Smackcoders at email address info@smackcoders.com.
*******************************************************************************************/
namespace Smackcoders\FCSV;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class ACFImport {
private static $acf_instance = null;
public static function getInstance() {
if (ACFImport::$acf_instance == null) {
ACFImport::$acf_instance = new ACFImport;
return ACFImport::$acf_instance;
}
return ACFImport::$acf_instance;
}
function set_acf_values($header_array ,$value_array , $map, $maps, $post_id , $type,$mode, $hash_key,$line_number){
$helpers_instance = ImportHelpers::getInstance();
$helpers_instance = ImportHelpers::getInstance();
$post_values =$helpers_instance->get_header_values($maps , $header_array , $value_array);
$trim_content = array(
'->static' => '',
'->math' => '',
'->cus1' => '',
'->openAI' => '',
);
if(is_array($map)){
foreach($map as $header_keys => $value){
if( strpos($header_keys, '->cus2') !== false) {
if(!empty($value)){
$this->write_to_customfile($value, $header_array, $value_array);
unset($map[$header_keys]);
}
}
else{
$header_trim = strtr($header_keys, $trim_content);
if($header_trim != $header_keys){
unset($map[$header_keys]);
}
$map[$header_trim] = $value;
}
}
foreach($map as $key => $value){
$csv_value= trim($map[$key]);
if(!empty($csv_value) || $csv_value == 0){
//$pattern = "/({([a-z A-Z 0-9 | , _ -]+)(.*?)(}))/";
$pattern = '/{([^}]*)}/';
if(preg_match_all($pattern, $csv_value, $matches, PREG_PATTERN_ORDER)){
$csv_element = $csv_value;
//foreach($matches[2] as $value){
foreach($matches[1] as $value){
$get_key = array_search($value , $header_array);
if(isset($value_array[$get_key])){
$csv_value_element = $value_array[$get_key];
$value = '{'.$value.'}';
$csv_element = str_replace($value, $csv_value_element, $csv_element);
}
}
$math = 'MATH';
if (strpos($csv_element, $math) !== false) {
$equation = str_replace('MATH', '', $csv_element);
$csv_element = $helpers_instance->evalmath($equation);
}
$wp_element= trim($key);
if((!empty($csv_element) || $csv_element == 0) && !empty($wp_element)){
if(is_plugin_active('advanced-custom-fields/acf.php') || is_plugin_active('secure-custom-fields/secure-custom-fields.php')){
$acf_pluginPath = WP_PLUGIN_DIR . '/advanced-custom-fields/pro';
if(is_dir($acf_pluginPath)) {
$this->acfpro_import_function($wp_element ,$post_values, $csv_element ,$type, $post_id,$mode, $hash_key,$line_number);
}
else{
$this->acf_import_function($wp_element ,$post_values, $csv_element ,$type, $post_id,$mode, $hash_key,$line_number);
}
}
}
}
elseif(!in_array($csv_value , $header_array)){
$wp_element= trim($key);
$this->acf_import_function($wp_element ,$post_values, $csv_value ,$type, $post_id,$mode, $hash_key,$line_number);
}
else{
$get_key= array_search($csv_value , $header_array);
if(isset($value_array[$get_key])){
$csv_element = $value_array[$get_key];
$wp_element= trim($key);
if($mode == 'Insert'){
if((!empty($csv_element) || $csv_element == 0) && !empty($wp_element)){
$this->acf_import_function($wp_element ,$post_values, $csv_element ,$type, $post_id,$mode, $hash_key,$line_number);
}
}
else{
if(!empty($csv_element) || !empty($wp_element)){
$this->acf_import_function($wp_element ,$post_values, $csv_element ,$type, $post_id,$mode, $hash_key,$line_number);
}
}
}
}
}
}
}
}
/**
* Imports ACF Free fields
* @param string $acf_wpname_element - acf fields
* @param string $acf_csv_element - csv headers
* @param string $importAs - selected import type
* @param string $post_id - inserted post id
*/
function acf_import_function($acf_wpname_element ,$post_values,$acf_csv_element, $importAs , $post_id,$mode, $hash_key,$line_number){
$acf_wp_name = $acf_wpname_element;
$acf_csv_name = $acf_csv_element;
global $wpdb;
$helpers_instance = ImportHelpers::getInstance();
$media_instance = MediaHandling::getInstance();
$plugin = 'acf';
$get_acf_fields = $wpdb->get_results($wpdb->prepare("select post_content, post_name from {$wpdb->prefix}posts where post_type = %s and post_excerpt = %s", 'acf-field', $acf_wp_name ), ARRAY_A);
foreach($get_acf_fields as $keys => $value_type){
$get_type_field = unserialize($value_type['post_content']);
$field_type = $get_type_field['type'];
$key = $get_acf_fields[0]['post_name'];
// $return_format = $get_type_field['return_format'];
$return_format = isset($get_type_field['return_format']) ? $get_type_field['return_format'] : '';
if($field_type == 'text' || $field_type == 'textarea' || $field_type == 'number' || $field_type == 'email' || $field_type == 'url' || $field_type == 'password' || $field_type == 'range' || $field_type == 'radio' || $field_type == 'true_false' || $field_type == 'time_picker' || $field_type == 'color_picker' || $field_type == 'button_group' || $field_type == 'oembed' || $field_type == 'wysiwyg'){
$map_acf_wp_element = $acf_wp_name;
$map_acf_csv_element = $acf_csv_name;
}
if ($field_type == 'icon_picker') {
$acf_csv_element = explode(',',$acf_csv_element);
$icon_pic_type = !empty($acf_csv_element[0]) ? $acf_csv_element[0] : '';
$map_acf_wp_element = $acf_wp_name;
if($icon_pic_type == 'dashicons'){
$dash_icon_value = !empty($acf_csv_element[1]) ? $acf_csv_element[1] : '';
}
else if($icon_pic_type == 'media_library'){
$dash_media_value = !empty($acf_csv_element[1]) ? $acf_csv_element[1] : '';
$dash_icon_value = $media_instance->image_meta_table_entry($line_number ,'', $post_id ,'', $dash_media_value, $hash_key,'media_library',$importAs,'','','', '','','','');
}else if($icon_pic_type == 'url'){
$dash_icon_value = !empty($acf_csv_element[1]) ? $acf_csv_element[1] : '';
}
if(!empty($dash_icon_value)){
$serialized_value = array(
'type' => $icon_pic_type,
'value' => esc_sql($dash_icon_value)
);
$map_acf_csv_element = $serialized_value;
}
}
if($field_type == 'date_time_picker'){
$dt_var = trim($acf_csv_name);
$dateformat = "Y-m-d H:i:s";
$date_time_of = $helpers_instance->validate_datefield($dt_var,$acf_wp_name,$dateformat,$line_number);
if($mode == 'Insert'){
if($dt_var == 0 || $dt_var == '')
$map_acf_csv_element = $dt_var;
else{
$map_acf_csv_element = $date_time_of;
}
}
else{
if($dt_var == 0 || $dt_var == '')
$map_acf_csv_element = $dt_var;
else{
$map_acf_csv_element = $date_time_of;
}
}
$map_acf_wp_element = $acf_wp_name;
}
if($field_type == 'user'){
$maps_acf_csv_name = $acf_csv_name;
$map_acf_wp_element = $acf_wp_name;
$explo_acf_csv_name = explode(',',trim($acf_csv_name));
foreach($explo_acf_csv_name as $user){
if(!is_numeric($explo_acf_csv_name)){
$userid = $wpdb->get_col($wpdb->prepare("select ID from {$wpdb->prefix}users where user_login = %s",$user));
foreach($userid as $users){
$map_acf_csv_element[] = $users;
}
}
}
if(is_numeric($user)){
$map_acf_csv_element = $user;
}
$bidirectional =$get_type_field ['bidirectional'] ;
if($bidirectional == 1){
$bidirectional_target =$get_type_field ['bidirectional_target'] ;
foreach($bidirectional_target as $bidirectional) {
$field_name = $wpdb->get_results("SELECT post_excerpt FROM {$wpdb->prefix}posts WHERE post_name = '$bidirectional' AND post_status = 'publish'", ARRAY_A);
$field_value = $field_name[0]['post_excerpt'];
$get_relation = $wpdb->get_results("SELECT meta_value FROM {$wpdb->prefix}usermeta WHERE meta_key = '$field_value' AND user_id = '$map_acf_csv_element'", ARRAY_A);
$get_relation_field=$get_relation[0]['meta_value'];
$update_id = unserialize($get_relation_field);
$update_id[] = $post_id;
update_user_meta($map_acf_csv_element, $field_value, $update_id);
update_user_meta($map_acf_csv_element, '_' . $field_value, $bidirectional);
}
}
}
if($field_type == 'post_object'){
if($get_type_field['multiple'] == 0){
$maps_acf_csv_name = $acf_csv_name;
}else{
$explo_acf_csv_name = explode(',',trim($acf_csv_name));
$maps_acf_csv_name = array();
foreach($explo_acf_csv_name as $explo_csv_value){
$maps_acf_csv_name[] = trim($explo_csv_value);
}
}
$map_acf_csv_elements = $maps_acf_csv_name;
if($get_type_field['multiple'] == 0){
if (!is_numeric($map_acf_csv_elements ) ){
$map_acf_csv_elements = $wpdb->_real_escape($map_acf_csv_elements);
$id = $wpdb->get_results("SELECT ID FROM {$wpdb->prefix}posts WHERE post_title = '{$map_acf_csv_elements}' AND post_status = 'publish' order by ID DESC", ARRAY_A);
$map_acf_csv_element = isset($id[0]['ID']) ? $id[0]['ID'] : '';
}
else{
$map_acf_csv_element = $maps_acf_csv_name;
}
}
else{
$map_acf_csv_element = array();
foreach($map_acf_csv_elements as $csv_element){
$csv_element = $wpdb->_real_escape($csv_element);
$id = $wpdb->get_results("SELECT ID FROM {$wpdb->prefix}posts WHERE post_title = '$csv_element' AND post_status = 'publish'", ARRAY_A);
$map_acf_csv_element[] = isset($id[0]['ID']) ? $id[0]['ID'] : '';
}
}
$bidirectional =$get_type_field ['bidirectional'] ;
if($bidirectional == 1){
$bidirectional_target =$get_type_field ['bidirectional_target'] ;
foreach($bidirectional_target as $bidirectional) {
$field_name = $wpdb->get_results("SELECT post_excerpt FROM {$wpdb->prefix}posts WHERE post_name = '$bidirectional' AND post_status = 'publish'", ARRAY_A);
$field_value = $field_name[0]['post_excerpt'];
foreach($map_acf_csv_element as $id){
$get_relation = $wpdb->get_results("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE meta_key = '$field_value' AND post_id = '$id'", ARRAY_A);
$get_object_field=$get_relation[0]['meta_value'];
$update_id = unserialize($get_object_field);
$update_id[] = $post_id;
update_post_meta($id, $field_value, $update_id);
update_post_meta($id, '_' . $field_value, $bidirectional);
}
}
}
$map_acf_wp_element = $acf_wp_name;
}
if($field_type == 'relationship' || $field_type == 'taxonomy'){
$relations = array();
$check_is_valid_term = null;
$get_relations = $acf_csv_name;
if(!empty($get_relations)){
$exploded_relations = explode(',', $get_relations);
foreach ($exploded_relations as $relVal) {
$relationTerm = trim($relVal);
//$relTerm[] = $relationTerm;
$tax_field_type = $get_type_field['field_type'];
if ($field_type == 'taxonomy') {
$taxonomy_name = $get_type_field['taxonomy'];
// $check_is_valid_term = $helpers_instance->get_requested_term_details($post_id, $relTerm, $taxonomy_name);
$check_is_valid_term = $helpers_instance->get_requested_term_details($post_id, array($relationTerm), $taxonomy_name);
//$relations[] = $check_is_valid_term;
if(isset($tax_field_type) && ($tax_field_type == 'select' || $tax_field_type == 'radio')){
$single_relations = $check_is_valid_term;
}
else{
$relations[] = $check_is_valid_term;
}
} else {
$reldata = strlen($relationTerm);
$checkrelid = intval($relationTerm);
$verifiedRelLen = strlen($checkrelid);
if ($reldata == $verifiedRelLen) {
$relations[] = $relationTerm;
} else {
$relVal = $wpdb->_real_escape($relVal);
$relation_id = $wpdb->get_results("SELECT ID FROM {$wpdb->prefix}posts WHERE post_title = '$relVal' AND post_status = 'publish'", ARRAY_A);
if (!empty($relation_id)) {
$relations[] = $relation_id[0]['ID'];
}
}
}
}
}
$bidirectional =$get_type_field ['bidirectional'] ;
if($bidirectional == 1){
$bidirectional_target =$get_type_field ['bidirectional_target'] ;
foreach($bidirectional_target as $bidirectional) {
$field_name = $wpdb->get_results("SELECT post_excerpt FROM {$wpdb->prefix}posts WHERE post_name = '$bidirectional' AND post_status = 'publish'", ARRAY_A);
$field_value = $field_name[0]['post_excerpt'];
foreach($relations as $relation_id) {
if ($field_type == 'taxonomy') {
$get_relation = $wpdb->get_results("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE meta_key = '$field_value' AND term_id = '$relation_id'", ARRAY_A);
}
else{
$get_relation = $wpdb->get_results("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE meta_key = '$field_value' AND post_id = '$relation_id'", ARRAY_A);
}
$get_relation_field=$get_relation[0]['meta_value'];
$update_id = unserialize($get_relation_field);
$update_id[] = $post_id;
if ($field_type == 'taxonomy') {
if(isset($tax_field_type) && ($tax_field_type == 'select' || $tax_field_type == 'radio')){
update_term_meta($relation_id, $field_value, $bidirectional_single);
}
else{
update_term_meta($relation_id, $field_value, $update_id);
}
update_term_meta($relation_id, '_' . $field_value, $bidirectional);
}
else{
if(isset($tax_field_type) && ($tax_field_type == 'select' || $tax_field_type == 'radio')){
update_post_meta($relation_id, $field_value, $bidirectional_single);
}
else{
update_post_meta($relation_id, $field_value, $update_id);
}
update_post_meta($relation_id, '_' . $field_value, $bidirectional);
}
if ($field_type == 'taxonomy') {
update_term_meta($relation_id, $field_value, $update_id);
update_term_meta($relation_id, '_' . $field_value, $bidirectional);
}
else{
update_post_meta($relation_id, $field_value, $update_id);
update_post_meta($relation_id, '_' . $field_value, $bidirectional);
}
}
}
}
if(isset($tax_field_type) && ($tax_field_type == 'select' || $tax_field_type == 'radio')){
$map_acf_csv_element = $single_relations;
}
else{
$map_acf_csv_element = $relations;
}
//$map_acf_csv_element = $relations;
$map_acf_wp_element = $acf_wp_name;
}
if($field_type == 'date_picker'){
$var = trim($acf_csv_name);
$dateformat = 'Ymd';
$date = str_replace('/', '-', "$var");
$date_of = $helpers_instance->validate_datefield($var,$acf_wp_name,$dateformat,$line_number);
if($mode == 'Insert'){
if($var == 0 || $var == '')
$map_acf_csv_element = $var;
else{
$map_acf_csv_element = $date_of;
}
}
else{
if($var == 0 || $var == '')
$map_acf_csv_element = $var;
else{
$map_acf_csv_element = $date_of;
}
}
$map_acf_wp_element = $acf_wp_name;
}
if($field_type == 'select'){
if($get_type_field['multiple'] == 0){
$map_acf_csv_element = $acf_csv_name;
}
$map_acf_wp_element = $acf_wp_name;
}
if($field_type == 'checkbox'){
$explode_acf_csv = explode(',',trim($acf_csv_name));
$explode_acf_csv_name = [];
foreach($explode_acf_csv as $explode_acf_csv_value){
if(!empty($explode_acf_csv_value)){
$explode_acf_csv_name[] = trim($explode_acf_csv_value);
}
}
$map_acf_csv_element = $explode_acf_csv_name;
$map_acf_wp_element = $acf_wp_name;
}
}
if ($importAs == 'Users') {
update_user_meta($post_id, $map_acf_wp_element, $map_acf_csv_element);
update_user_meta($post_id, '_' . $map_acf_wp_element, $key);
} else {
update_post_meta($post_id, $map_acf_wp_element, $map_acf_csv_element);
update_post_meta($post_id, '_' . $map_acf_wp_element, $key);
}
$listTaxonomy = get_taxonomies();
if (in_array($importAs, $listTaxonomy)) {
if($term_meta = 'yes'){
update_term_meta($post_id, $map_acf_wp_element, $map_acf_csv_element);
update_term_meta($post_id, '_' . $map_acf_wp_element, $key);
}else{
$option_name = $importAs . "_" . $post_id . "_" . $map_acf_wp_element;
$option_value = $map_acf_csv_element;
if (is_array($option_value)) {
$option_value = serialize($option_value);
}
update_option("$option_name", "$option_value");
}
}
}
}

View File

@@ -0,0 +1,342 @@
<?php
/**
* WP Ultimate CSV Importer plugin file.
*
* Copyright (C) 2010-2020, Smackcoders Inc - info@smackcoders.com
*/
namespace Smackcoders\FCSV;
if (!defined('ABSPATH')) exit; // Exit if accessed directly
class AllInOneSeoImport
{
private static $all_seo_instance = null;
public static function getInstance()
{
if (AllInOneSeoImport::$all_seo_instance == null)
{
AllInOneSeoImport::$all_seo_instance = new AllInOneSeoImport;
return AllInOneSeoImport::$all_seo_instance;
}
return AllInOneSeoImport::$all_seo_instance;
}
function set_all_seo_values($header_array, $value_array, $map, $post_id, $type, $mode)
{
$post_values = [];
$helpers_instance = ImportHelpers::getInstance();
$post_values = $helpers_instance->get_header_values($map, $header_array, $value_array);
$this->all_seo_import_function($post_values, $type, $post_id, $mode);
}
function all_seo_import_function($data_array, $importas, $pID, $mode)
{
$createdFields = array();
foreach ($data_array as $dkey => $dvalue)
{
$createdFields[] = $dkey;
}
if ($mode == 'Insert')
{
if (isset($data_array['keywords']))
{
$custom_array['_aioseop_keywords'] = $data_array['keywords'];
}
if (isset($data_array['description']))
{
$custom_array['_aioseop_description'] = $data_array['description'];
}
if (isset($data_array['title']))
{
$custom_array['_aioseop_title'] = $data_array['title'];
}
if (isset($data_array['noindex']))
{
$custom_array['_aioseop_noindex'] = $data_array['noindex'];
}
if (isset($data_array['nofollow']))
{
$custom_array['_aioseop_nofollow'] = $data_array['nofollow'];
}
if (isset($data_array['custom_link']))
{
$custom_array['_aioseop_custom_link'] = $data_array['custom_link'];
}
if (isset($data_array['noodp']))
{
$custom_array['_aioseop_noodp'] = $data_array['noodp'];
}
if (isset($data_array['noydir']))
{
$custom_array['_aioseop_noydir'] = $data_array['noydir'];
}
if (isset($data_array['titleatr']))
{
$custom_array['_aioseop_titleatr'] = $data_array['titleatr'];
}
if (isset($data_array['menulabel']))
{
$custom_array['_aioseop_menulabel'] = $data_array['menulabel'];
}
if (isset($data_array['disable']))
{
$custom_array['_aioseop_disable'] = $data_array['disable'];
if ($data_array['disable'] == 'off')
{
unset($custom_array['_aioseop_disable']);
}
}
if (isset($data_array['disable_analytics']))
{
$custom_array['_aioseop_disable_analytics'] = $data_array['disable_analytics'];
if ($data_array['disable_analytics'] == 'off')
{
unset($custom_array['_aioseop_disable_analytics']);
}
}
if (isset($data_array['og_title']))
{
$custom_array['_aioseo_og_title'] = $data_array['og_title'];
}
if (isset($data_array['og_description']))
{
$custom_array['_aioseo_og_description'] = $data_array['og_description'];
}
if (isset($data_array['og_article_section']))
{
$custom_array['_aioseo_og_article_section'] = $data_array['og_article_section'];
}
if (isset($data_array['og_article_tags']))
{
$custom_array['_aioseo_og_article_tags'] = $data_array['og_article_tags'];
}
if (isset($data_array['twitter_title']))
{
$custom_array['_aioseo_twitter_title'] = $data_array['twitter_title'];
}
if (isset($data_array['twitter_description']))
{
$custom_array['_aioseo_twitter_description'] = $data_array['twitter_description'];
}
if (!empty($custom_array))
{
foreach ($custom_array as $custom_key => $custom_value)
{
update_post_meta($pID, $custom_key, $custom_value);
}
}
global $wpdb;
$aioseo_table_name = $wpdb->prefix . "aioseo_posts";
$og_title = isset($data_array['og_title']) ? $data_array['og_title'] : '';
$og_description = isset($data_array['og_description'])?$data_array['og_description']:'';
$canonical_url = isset($data_array['custom_link']) ? $data_array['custom_link'] : '';
$og_image_type = isset($data_array['og_image_type']) ? $data_array['og_image_type'] : '';
$og_image_custom_url = isset($data_array['og_image_custom_url']) ? $data_array['og_image_custom_url'] : '';
$og_video = isset($data_array['og_video']) ? $data_array['og_video'] : '';
$og_object_type = isset($data_array['og_object_type']) ? $data_array['og_object_type'] : '';
$og_article_section = isset($data_array['og_article_section'])?$data_array['og_article_section']:'';
$value['label'] = isset($data_array['og_article_tags'])?$data_array['og_article_tags']:'';
$name['value'] = isset($data_array['og_article_tags'])?$data_array['og_article_tags']:'';
$obj_merged = (object)array_merge((array)$value, (array)$name);
$article_tags = wp_json_encode($obj_merged);
$og_article_tags = '';
$og_article_tags .= '[' . $article_tags . ']';
$twitter_use_og = isset($data_array['twitter_use_og'])?$data_array['twitter_use_og']:'';
$twitter_card = isset($data_array['twitter_card']) ? $data_array['twitter_card'] : '';
$twitter_image_type = isset($data_array['twitter_image_type']) ? $data_array['twitter_image_type'] : '';
$twitter_image_custom_url = isset($data_array['twitter_image_custom_url']) ? $data_array['twitter_image_custom_url'] : '';
$twitter_title = isset($data_array['twitter_title']) ? $data_array['twitter_title'] : '';
$twitter_description = isset($data_array['twitter_description']) ? $data_array['twitter_description'] : '';
$robots_default = isset($data_array['robots_default'])?$data_array['robots_default']:'';
$robots_noindex = isset($data_array['noindex'])?$data_array['noindex']:'';
$robots_noarchive = isset($data_array['robots_noarchive']) ? $data_array['robots_noarchive'] : '';
$robots_nosnippet = isset($data_array['robots_nosnippet']) ? $data_array['robots_nosnippet'] : '';
$robots_nofollow = isset($data_array['nofollow'])?$data_array['nofollow']:'';
$robots_noimageindex = isset($data_array['robots_noimageindex'])?$data_array['robots_noimageindex']:'';
$robots_noodp = isset($data_array['noodp']) ? $data_array['noodp'] : '';
$robots_notranslate = isset($data_array['robots_notranslate']) ? $data_array['robots_notranslate'] : '';
$robots_max_snippet = isset($data_array['robots_max_snippet']) ? $data_array['robots_max_snippet'] : '';
$robots_max_videopreview = isset($data_array['robots_max_videopreview']) ? $data_array['robots_max_videopreview'] : '';
$robots_max_imagepreview = isset($data_array['robots_max_imagepreview']) ? $data_array['robots_max_imagepreview'] : '' ;
$title = isset($data_array['aioseo_title']) ? $data_array['aioseo_title'] : '';
$description = isset($data_array['aioseo_description']) ? $data_array['aioseo_description'] : '';
$keyphrases_val['keyphrase'] = isset($data_array['keyphrases']) ? $data_array['keyphrases'] : '';
$keyphras['focus'] = (object)(array)$keyphrases_val;
$keyphrass = wp_json_encode($keyphras);
$keyphrases = $keyphrass;
$twitter_image_custom_fields = '';
$og_image_custom_fields = '';
if ($twitter_image_type == 'custom')
{
$twitter_image_custom_url = isset($data_array['twitter_image_custom_url']) ? $data_array['twitter_image_custom_url'] : '';
}
if ($og_image_type == 'custom')
{
$og_image_custom_url = isset($data_array['og_image_custom_url']) ? $data_array['og_image_custom_url'] : '';
}
$wpdb->get_results("INSERT INTO $aioseo_table_name
(post_id,og_title ,og_description,canonical_url,og_image_type,og_image_custom_url,og_video,og_object_type,og_article_section,
twitter_use_og,twitter_card,twitter_image_type,twitter_image_custom_url,twitter_title,twitter_description,robots_default,
robots_noindex,robots_noarchive,robots_nosnippet,robots_nofollow,robots_noimageindex,
robots_noodp,robots_notranslate,robots_max_snippet,robots_max_videopreview,robots_max_imagepreview,og_article_tags
,title,keyphrases,description,og_image_custom_fields,twitter_image_custom_fields)
values('$pID','$og_title','$og_description','$canonical_url','$og_image_type','$og_image_custom_url','$og_video','$og_object_type','$og_article_section',
'$twitter_use_og','$twitter_card','$twitter_image_type','$twitter_image_custom_url','$twitter_title','$twitter_description',
'$robots_default','$robots_noindex','$robots_noarchive','$robots_nosnippet','$robots_nofollow',
'$robots_noimageindex','$robots_noodp','$robots_notranslate','$robots_max_snippet',
'$robots_max_videopreview','$robots_max_imagepreview','$og_article_tags','$title','$keyphrases','$description'
,'$og_image_custom_fields','$twitter_image_custom_fields')");
}
if ($mode == 'Update')
{
global $wpdb;
if (isset($data_array['og_title']))
{
$custom_value['og_title'] = $data_array['og_title'];
}
if (isset($data_array['og_description']))
{
$custom_value['og_description'] = $data_array['og_description'];
}
if (isset($data_array['custom_link']))
{
$custom_value['canonical_url'] = $data_array['custom_link'];
}
if (isset($data_array['og_image_type']))
{
$custom_value['og_image_type'] = $data_array['og_image_type'];
}
if (isset($data_array['og_video']))
{
$custom_value['og_video'] = $data_array['og_video'];
}
if (isset($data_array['og_object_type']))
{
$custom_value['og_object_type'] = $data_array['og_object_type'];
}
if (isset($data_array['og_article_section']))
{
$custom_value['og_article_section'] = $data_array['og_article_section'];
}
if (isset($data_array['og_article_tags']))
{
$value['label'] = $data_array['og_article_tags'];
$name['value'] = $data_array['og_article_tags'];
$obj_merged = (object)array_merge((array)$value, (array)$name);
$article_tags = wp_json_encode($obj_merged);
$og_article_tag .= '[' . $article_tags . ']';
$custom_value['og_article_tags'] = $og_article_tag;
}
if (isset($data_array['twitter_use_og']))
{
$custom_value['twitter_use_og'] = $data_array['twitter_use_og'];
}
if (isset($data_array['twitter_card']))
{
$custom_value['twitter_card'] = $data_array['twitter_card'];
}
if (isset($data_array['twitter_image_type']))
{
$custom_value['twitter_image_type'] = $data_array['twitter_image_type'];
}
if (isset($data_array['twitter_title']))
{
$custom_value['twitter_title'] = $data_array['twitter_title'];
}
if (isset($data_array['twitter_description']))
{
$custom_value['twitter_description'] = $data_array['twitter_description'];
}
if (isset($data_array['robots_default']))
{
$custom_value['robots_default'] = $data_array['robots_default'];
}
if (isset($data_array['noindex']))
{
$custom_value['robots_noindex'] = $data_array['noindex'];
}
if (isset($data_array['robots_noarchive']))
{
$custom_value['robots_noarchive'] = $data_array['robots_noarchive'];
}
if (isset($data_array['robots_nosnippet']))
{
$custom_value['robots_nosnippet'] = $data_array['robots_nosnippet'];
}
if (isset($data_array['nofollow']))
{
$custom_value['robots_nofollow'] = $data_array['nofollow'];
}
if (isset($data_array['robots_noimageindex']))
{
$custom_value['robots_noimageindex'] = $data_array['robots_noimageindex'];
}
if (isset($data_array['noodp']))
{
$custom_value['robots_noodp'] = $data_array['noodp'];
}
if (isset($data_array['robots_notranslate']))
{
$custom_value['robots_notranslate'] = $data_array['robots_notranslate'];
}
if (isset($data_array['robots_max_snippet']))
{
$custom_value['robots_max_snippet'] = $data_array['robots_max_snippet'];
}
if (isset($data_array['robots_max_videopreview']))
{
$custom_value['robots_max_videopreview'] = $data_array['robots_max_videopreview'];
}
if (isset($data_array['robots_max_imagepreview']))
{
$custom_value['robots_max_imagepreview'] = $data_array['robots_max_imagepreview'];
}
if (isset($data_array['aioseo_title']))
{
$custom_value['title'] = $data_array['aioseo_title'];
}
if (isset($data_array['aioseo_description']))
{
$custom_value['description'] = $data_array['aioseo_description'];
}
if (isset($data_array['keyphrases']))
{
$keyphrases_val['keyphrase'] = $data_array['keyphrases'];
$keyphras['focus'] = (object)(array)$keyphrases_val;
$keyphrass = wp_json_encode($keyphras);
$custom_value['keyphrases'] = $keyphrass;
}
if (isset($data_array['twitter_image_custom_fields']))
{
if ($custom_value['twitter_image_type'] == 'custom')
{
$custom_value['twitter_image_custom_url'] = $data_array['twitter_image_custom_url'];
}
}
if (isset($data_array['og_image_custom_fields']))
{
if ($custom_value['og_image_type'] == 'custom')
{
$custom_value['og_image_custom_url'] = $data_array['og_image_custom_url'];
}
}
if (!empty($custom_value))
{
foreach ($custom_value as $custom_key => $custom_val)
{
$sql = $wpdb->prepare("UPDATE {$wpdb->prefix}aioseo_posts SET $custom_key = '$custom_val' WHERE post_id = %d;", $pID);
$wpdb->query($sql);
}
}
}
return $createdFields;
}
}

View File

@@ -0,0 +1,164 @@
<?php
/**
* WP Ultimate CSV Importer plugin file.
*
* Copyright (C) 2010-2020, Smackcoders Inc - info@smackcoders.com
*/
namespace Smackcoders\FCSV;
if (!defined('ABSPATH'))
exit; // Exit if accessed directly
class BBPressImport
{
private static $bbpress_instance = null;
public static function getInstance()
{
if (BBPressImport::$bbpress_instance == null) {
BBPressImport::$bbpress_instance = new BBPressImport;
return BBPressImport::$bbpress_instance;
}
return BBPressImport::$bbpress_instance;
}
public function set_bbpress_values($header_array, $value_array, $map, $post_id, $type, $mode){
$post_values = [];
$helpers_instance = ImportHelpers::getInstance();
$post_values = $helpers_instance->get_header_values($map, $header_array, $value_array);
$this->bbpress_values_import($post_values, $post_id, $type, $header_array ,$value_array, $mode);
}
public function bbpress_values_import($post_values, $post_id, $type, $header_array ,$value_array, $mode){
global $wpdb;
if($type == 'forum'){
$forum_type = isset($post_values['_bbp_status']) ? $post_values['_bbp_status'] : 'open';
$forum_status = isset($post_values['_bbp_forum_type']) ? $post_values['_bbp_forum_type'] : 'forum';
update_post_meta($post_id, '_bbp_status', $forum_type);
update_post_meta($post_id, '_bbp_forum_type', $forum_status);
$forum_moderator = isset($post_values['bbp_moderators']) ? $post_values['bbp_moderators'] : '';
if(!empty($forum_moderator)){
$forum_moderators = explode(',', $forum_moderator);
foreach($forum_moderators as $forum_moderator_value){
$forum_moderator_id = username_exists($forum_moderator_value);
if(!empty($forum_moderator_id)){
if($mode == 'Insert'){
add_post_meta($post_id, '_bbp_moderator_id', $forum_moderator_id);
}
elseif($mode == 'Update'){
update_post_meta($post_id, '_bbp_moderator_id', $forum_moderator_id);
}
}
}
}
$forum_visibility = isset($post_values['Visibility']) ? $post_values['Visibility'] : 'public';
$forums = array(
'ID' => $post_id,
'post_status' => $forum_visibility,
);
wp_update_post($forums);
}
if($type== 'topic'){
if(isset($post_values['_bbp_forum_id']) ||isset($post_values['topic_status'])||isset($post_values['author'])){
if(isset($post_values['_bbp_forum_id'])){
if(!is_numeric($post_values['_bbp_forum_id'])){
$forum_title = $post_values['_bbp_forum_id'];
$forum_id = $wpdb->get_var("SELECT ID FROM {$wpdb->prefix}posts WHERE post_title = '$forum_title' AND post_type = 'forum'");
$post_values['_bbp_forum_id'] = $forum_id;
}
}
$topic_status = isset($post_values['topic_status']) ? $post_values['topic_status'] : 'publish';
$forum_id = isset($post_values['_bbp_forum_id']) ? $post_values['_bbp_forum_id'] : '';
$author = isset($post_values['author']) ? $post_values['author'] : '';
if($topic_status == 'Open'){
$topic_status = 'publish';
}
if(!is_numeric($author)){
$author = $wpdb->get_var("SELECT ID FROM {$wpdb->prefix}users WHERE user_login = '$author'");
}
$topics = array(
'ID' => $post_id,
'post_parent' => $forum_id,
'post_status' => $topic_status,
'post_author' =>$author,
);
$topic[]=wp_update_post($topics);
}
if(isset($post_values['_bbp_author_ip'])){
$author_ip = isset($post_values['_bbp_author_ip']) ? $post_values['_bbp_author_ip'] : '';
update_post_meta($post_id, '_bbp_author_ip',$author_ip);
update_post_meta($post_id, '_bbp_forum_id',$forum_id);
}
if(isset($post_values['topic_type'])){
$type=$post_values['topic_type'];
switch ($type) {
case 'sticky':
update_post_meta($forum_id,'_bbp_sticky_topics',$topic);
break;
case 'super sticky':
$option_topic = get_option('_bbp_super_sticky_topics');
if(!empty($option_topic)){
foreach($topic as $topic_id){
if(!in_array($topic_id,$option_topic)){
array_push($option_topic,$topic_id);
}
}
update_option( '_bbp_super_sticky_topics',$option_topic);
}
else{
update_option( '_bbp_super_sticky_topics',$topic);
}
break;
}
}
}
if($type== 'reply'){
if(isset($post_values['forum_name']) ||isset($post_values['reply_status'])||isset($post_values['author'])){
if(isset($post_values['forum_name'])){
if(!is_numeric($post_values['forum_name'])){
$forum_title = $post_values['forum_name'];
$forum_id = $wpdb->get_var("SELECT ID FROM {$wpdb->prefix}posts WHERE post_title = '$forum_title' AND post_type = 'forum'");
$post_values['forum_name'] = $forum_id;
}
}
$topic_status = isset($post_values['reply_status']) ? $post_values['reply_status'] : '';
$forum_id = isset($post_values['_bbp_forum_id']) ? $post_values['_bbp_forum_id'] : '';
$author = isset($post_values['reply_author']) ? $post_values['reply_author'] : '';
if(!is_numeric($author)){
$author = $wpdb->get_var("SELECT ID FROM {$wpdb->prefix}users WHERE user_login = '$author'");
}
$topics = array(
'ID' => $post_id,
'post_parent' => $forum_id,
'post_status' => $topic_status,
'post_author' =>$author,
);
wp_update_post($topics);
}
if(isset($post_values['_bbp_author_ip'])||isset($post_values['topic_name'])){
if(isset($post_values['_bbp_topic_id'])){
if(!is_numeric($post_values['_bbp_topic_id'])){
$topic_title = $post_values['_bbp_topic_id'];
$topic_id = $wpdb->get_var("SELECT ID FROM {$wpdb->prefix}posts WHERE post_title = '$topic_title' AND post_type = 'topic'");
$post_values['_bbp_topic_id'] = $topic_id;
}
}
$topic_id = isset($post_values['_bbp_topic_id']) ? $post_values['_bbp_topic_id'] : '';
$author_ip = isset($post_values['_bbp_author_ip']) ? $post_values['_bbp_author_ip'] : '';
update_post_meta($post_id, '_bbp_author_ip',$author_ip);
update_post_meta($post_id, '_bbp_topic_id',$topic_id);
update_post_meta($post_id, '_bbp_forum_id',$forum_id);
}
}
}
}

View File

@@ -0,0 +1,262 @@
<?php
/**
* WP Ultimate CSV Importer plugin file.
*
* Copyright (C) 2010-2020, Smackcoders Inc - info@smackcoders.com
*/
namespace Smackcoders\FCSV;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class CFSImport {
private static $cfs_instance = null;
public static function getInstance() {
if (CFSImport::$cfs_instance == null) {
CFSImport::$cfs_instance = new CFSImport;
return CFSImport::$cfs_instance;
}
return CFSImport::$cfs_instance;
}
function set_cfs_values($line_number,$header_array ,$value_array , $map, $post_id , $type,$hash_key){
$post_values = [];
$helpers_instance = ImportHelpers::getInstance();
$post_values = $helpers_instance->get_header_values($map , $header_array , $value_array);
$this->cfs_import_function($line_number,$post_values, $post_id,$hash_key);
}
public function cfs_import_function ($line_number,$data_array, $pID,$hash_key) {
global $wpdb;
$helpers_instance = ImportHelpers::getInstance();
$media_instance = MediaHandling::getInstance();
$cfs_data = $this->CFSFields();
foreach ($data_array as $dkey => $dvalue) {
if(array_key_exists($dkey,$cfs_data['CFS'])){
if($cfs_data['CFS'][$dkey]['type'] == 'hyperlink'){
$linksfields = explode('|', $dvalue);
$linksarr['url'] = $linksfields[0];
$linksarr['text'] = $linksfields[1];
$linksarr['target'] = $linksfields[2];
$darray[$cfs_data['CFS'][$dkey]['name']] = $linksarr;
}
elseif($cfs_data['CFS'][$dkey]['type'] == 'file'){
$file_type = $this->get_remote_file_mime_type($dvalue);
if (strpos($file_type, 'image/') === 0) {
$media_instance->store_image_ids($i=1);
$darray[$cfs_data['CFS'][$dkey]['name']] = $media_instance->image_meta_table_entry($line_number, '', $pID, $cfs_data['CFS'][$dkey]['name'], $dvalue, $hash_key, 'cfs', '', '');
} else{
$darray[$cfs_data['CFS'][$dkey]['name']] = $media_instance->media_handling($dvalue, $pID);
}
}elseif($cfs_data['CFS'][$dkey]['type'] == 'select'){
if( strpos($dvalue, ',') !== false )
{
$multifields = explode(',', $dvalue);
foreach($multifields as $mk => $mv){
$meta_id = add_post_meta($pID, $cfs_data['CFS'][$dkey]['name'], $mv);
$this->insert_cfs_values($cfs_data,$pID,$meta_id,$cfs_data['CFS'][$dkey]['name']);
}
}else{
$darray[$cfs_data['CFS'][$dkey]['name']] = $dvalue;
}
}elseif($cfs_data['CFS'][$dkey]['type'] == 'relationship' && $cfs_data['CFS'][$dkey]['parent_id'] == 0){
$relations = explode(',', $dvalue);
foreach($relations as $rk => $rv){
$relationid = $wpdb->get_col($wpdb->prepare("select ID from {$wpdb->prefix}posts where post_title = %s and post_type != %s",$rv,'revision'));
$meta_id = add_post_meta($pID, $cfs_data['CFS'][$dkey]['name'], $relationid[0]);
$this->insert_cfs_values($cfs_data,$pID,$meta_id,$cfs_data['CFS'][$dkey]['name']);
}
}
elseif($cfs_data['CFS'][$dkey]['type'] == 'term'){
$relationterms = explode(',', $dvalue);
foreach($relationterms as $rtk => $rtv){
$term = get_term_by('name',$rtv,'category');
$termid = $term->term_id;
$meta_id = add_post_meta($pID, $cfs_data['CFS'][$dkey]['name'], $termid);
$this->insert_cfs_values($cfs_data,$pID,$meta_id,$cfs_data['CFS'][$dkey]['name']);
}
}elseif($cfs_data['CFS'][$dkey]['type'] == 'user'){
$users = explode(',', $dvalue);
foreach($users as $uk => $uv){
$userdata = $helpers_instance->get_from_user_details($uv);
$meta_id = add_post_meta($pID, $cfs_data['CFS'][$dkey]['name'], $userdata['user_id']);
$this->insert_cfs_values($cfs_data,$pID,$meta_id,$cfs_data['CFS'][$dkey]['name']);
}
}
else if($cfs_data['CFS'][$dkey]['type'] != 'loop' && $cfs_data['CFS'][$dkey]['parent_id'] == 0){
$darray[$dkey] = $dvalue;
}
global $wpdb;
$csfFields = $cfs_data['CFS'];
foreach($csfFields as $values){
if($values['type'] == 'loop'){
$parentLoopId = $values['fieldid'];
$parentLoopName = $values['name'];
}
if(!empty($parentLoopId)){
if($parentLoopId == $cfs_data['CFS'][$dkey]['parent_id'] && $values['parent_id'] != 0){
$childKeyName = $values['name'];
$childFieldname = $values['type'];
$childParentId = $values['parent_id'];
$childFieldId = $values['fieldid'];
if(!empty($childKeyName)){
if($cfs_data['CFS'][$dkey]['type'] == $childFieldname){
if($childFieldname =='relationship'){
$dataArray = explode('|', $dvalue);
$increment = 0;
foreach ($dataArray as $relationshipData) {
$relatedSingle = explode(',', $relationshipData);
foreach ($relatedSingle as $relate) {
$meta_id = add_post_meta($pID, $childKeyName, $relate);
$hierarchy = $parentLoopId . ':' . $increment . ':' . $childFieldId;
$this->insert_cfs_loop_values($childFieldId, $meta_id, $pID, $parentLoopId, $hierarchy);
}
$increment++; // Increment after each set of $relationshipData
}
}else if($childFieldname =='textarea'){
$dataArray = explode('|', $dvalue);
$increment = 0;
foreach($dataArray as $metaValue => $meta){
$meta_id = add_post_meta($pID, $childKeyName, $meta);
$hierarchy = $parentLoopId.':'.$increment.':'.$childFieldId;
$increment++;
$this->insert_cfs_loop_values($childFieldId, $meta_id, $pID, $parentLoopId, $hierarchy);
}
}
else if($childFieldname =='hyperlink'){
$dataArray = explode(',', $dvalue);
$increment = 0;
foreach($dataArray as $metaValue => $meta){
$urlArray = explode('|', $meta);
$linksarr['url'] = $urlArray[0];
$linksarr['text'] = $urlArray[1];
$linksarr['target'] = $urlArray[2];
$meta_id = add_post_meta($pID, $childKeyName, $linksarr);
$hierarchy = $parentLoopId.':'.$increment.':'.$childFieldId;
$increment++;
$this->insert_cfs_loop_values($childFieldId, $meta_id, $pID, $parentLoopId, $hierarchy);
}
}else if($childFieldname =='date'){
$dataArray = explode('|', $dvalue);
$increment = 0;
foreach($dataArray as $metaValue => $meta){
$convertedDate = date('Y-m-d', strtotime($meta));
$meta_id = add_post_meta($pID, $childKeyName, $convertedDate);
$hierarchy = $parentLoopId.':'.$increment.':'.$childFieldId;
$increment++;
$this->insert_cfs_loop_values($childFieldId, $meta_id, $pID, $parentLoopId, $hierarchy);
}
}else if($childFieldname =='color' || $childFieldname =='true_false' || $childFieldname =='select' || $childFieldname =='term' || $childFieldname =='user'){
$dataArray = explode('|', $dvalue);
$increment = 0;
foreach($dataArray as $metaValue => $meta){
$meta_id = add_post_meta($pID, $childKeyName, $meta);
$hierarchy = $parentLoopId.':'.$increment.':'.$childFieldId;
$increment++;
$this->insert_cfs_loop_values($childFieldId, $meta_id, $pID, $parentLoopId, $hierarchy);
}
}else if ($childFieldname == 'text'){
$dataArray = explode('|', $dvalue);
$increment = 0;
foreach($dataArray as $metaValue => $meta){
$meta_id = add_post_meta($pID, $childKeyName, $meta);
$hierarchy = $parentLoopId.':'.$increment.':'.$childFieldId;
$increment++;
$this->insert_cfs_loop_values($childFieldId, $meta_id, $pID, $parentLoopId, $hierarchy);
}
}
}
}
}
}
}
}
}
if($darray){
foreach($darray as $mkey => $mval){
$metaid = update_post_meta($pID, $mkey, $mval);
$this->insert_cfs_values($cfs_data,$pID,$metaid,$mkey);
}
}
}
public function get_remote_file_mime_type($url) {
$headers = get_headers($url, 1);
if ($headers !== false && isset($headers['Content-Type'])) {
if (is_array($headers['Content-Type'])) {
return $headers['Content-Type'][0]; // Sometimes headers might return an array
}
return $headers['Content-Type'];
}
return '';
}
public function insert_cfs_loop_values($childFieldId, $meta_id, $pID, $parentLoopId, $hierarchy){
global $wpdb;
$wpdb->insert($wpdb->prefix.'cfs_values',
array('field_id' => $childFieldId,
'meta_id' => $meta_id,
'post_id' => $pID,
'hierarchy' => $hierarchy,
'base_field_id' => $parentLoopId
),
array('%s','%s','%s')
);
}
public function insert_cfs_values($cfs_data,$pID,$metaid,$mkey) {
global $wpdb;
$wpdb->insert($wpdb->prefix.'cfs_values',
array('field_id' => $cfs_data['CFS'][$mkey]['fieldid'],
'meta_id' => $metaid,
'post_id' => $pID,
),
array('%s','%s','%s')
);
}
public function CFSFields(){
global $wpdb;
$customFields = $cfs_field = array();
$get_cfs_groups = $wpdb->get_results($wpdb->prepare("select ID from {$wpdb->prefix}posts where post_type = %s and post_status = %s", 'cfs', 'publish'),ARRAY_A);
$group_id_arr = '';
foreach ( $get_cfs_groups as $item => $group_rules ) {
$get_id[] = $group_rules['ID'];
}
$group_id_arr = !empty($get_id) ? implode(',',$get_id) : "";
if($group_id_arr != '') {
// Get available CFS fields based on the import type and group id
$get_cfs_fields = $wpdb->get_results("SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE post_id IN ($group_id_arr) and meta_key ='cfs_fields'", ARRAY_A);
}
// Available CFS fields
if (!empty($get_cfs_fields)) {
foreach ($get_cfs_fields as $key => $value) {
$get_cfs_field = @unserialize($value['meta_value']);
foreach($get_cfs_field as $fk => $fv){
$customFields["CFS"][$fv['name']]['label'] = $fv['label'];
$customFields["CFS"][$fv['name']]['name'] = $fv['name'];
$customFields["CFS"][$fv['name']]['type'] = $fv['type'];
$customFields["CFS"][$fv['name']]['fieldid'] = $fv['id'];
$customFields["CFS"][$fv['name']]['parent_id'] = $fv['parent_id'];
$cfs_field[] = $fv['name'];
}
}
}
return $customFields;
}
}

View File

@@ -0,0 +1,359 @@
<?php
/**
* WP Ultimate CSV Importer plugin file.
*
* Copyright (C) 2010-2020, Smackcoders Inc - info@smackcoders.com
*/
namespace Smackcoders\FCSV;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class CommentsImport {
private static $comments_instance = null;
public static function getInstance() {
if (CommentsImport::$comments_instance == null) {
CommentsImport::$comments_instance = new CommentsImport;
return CommentsImport::$comments_instance;
}
return CommentsImport::$comments_instance;
}
public function comments_import_function($data_array , $mode , $unikey_value,$unikey_name , $line_number, $type) {
global $wpdb;
$core_instance = CoreFieldsImport::getInstance();
global $core_instance;
$helpers_instance = ImportHelpers::getInstance();
$log_table_name = $wpdb->prefix ."import_detail_log";
$returnArr = [];
$updated_row_counts = $helpers_instance->update_count($unikey_value,$unikey_name);
$created_count = $updated_row_counts['created'];
$updated_count = $updated_row_counts['updated'];
$skipped_count = $updated_row_counts['skipped'];
//To avoid invalid statements and scripts
// if(isset($data_array['comment_content'])){
// $data_array['comment_content'] = esc_textarea($data_array['comment_content']);
// }
$allowed_html = ['div' => ['class' => true, 'id' => true, 'style' => true, ],
'a' => ['id' => true, 'href' => true, 'title' => true, 'target' => true, 'class' => true, 'style' => true, 'onclick' => true,],
'strong' => [],
'i' => ['id' => true, 'onclick' => true, 'style' => true, 'class' => true, 'aria-hidden' => true, 'title' => true ],
'p' => ['style' => true, 'name' => true, 'id' => true, ],
'img' => ['id' => true, 'style' => true, 'class' => true, 'src' => true, 'align' => true, 'src' => true, 'width' => true, 'height' => true, 'border' => true, ],
'table' => ['id' => true, 'class' => true, 'style' => true, 'height' => true, 'cellspacing' => true, 'cellpadding' => true, 'border' => true, 'width' => true, 'align' => true, 'background' => true, 'frame' => true, 'rules' => true, ],
'tbody' => [],
'br' => ['bogus' => true, ],
'tr' => ['id' => true, 'class' => true, 'style' => true, ],
'th' => ['id' => true, 'class' => true, 'style' => true, ],
'hr' => ['id' => true, 'class' => true, 'style' => true,],
'h3' => ['style' => true, ],
'td' => ['style' => true, 'id' => true, 'align' => true, 'width' => true, 'valign' => true, 'class' => true, 'colspan' => true, ],
'span' => ['style' => true, 'class' => true, ],
'h1' => ['style' => true, ],
'thead' => [],
'tfoot' => ['id' => true, 'style' => true, ],
'figcaption' => ['id' => true, 'style' => true, ],
'h4' => ['id' => true, 'align' => true, 'style' => true, ],
'h2' => ['id' => true, 'align' => true, 'style' => true, 'class' => true],
'select' => ['id' => true, 'name' => true, 'class' => true, 'data-size' =>true, 'data-live-search' =>true],
'option' => ['value' => true, 'selected' => true],
'label' =>['id' => true, 'class' =>true],
'input' => ['type' => true, 'value' => true, 'id' => true, 'name' => true, 'class' => true],
'form' => ['method' => true, 'name' => true, 'id' => true, 'action' => true]];
if(isset($data_array['comment_content'])){
$content = preg_replace('/<script>.+?<\/script>/i',"",$data_array['comment_content']);
$data_array['comment_content'] = wp_kses($content,$allowed_html);
}
$commentid = '';
$post_id = isset($data_array['comment_post_ID']) ? $data_array['comment_post_ID'] :'';
$post_exists = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}posts WHERE id = '" . $post_id . "' and post_status in ('publish','draft','future','private','pending')", ARRAY_A);
$valid_status = array('1', '0', 'spam');
if(empty($data_array['comment_approved'])) {
$data_array['comment_approved'] = 0;
}
if(!in_array($data_array['comment_approved'], $valid_status)) {
$data_array['comment_approved'] = 0;
}
$data_array['comment_approved'] = trim($data_array['comment_approved']);
if(!empty($data_array['user_id'])){
$user_login=$data_array['user_id'];
$u_id = $wpdb->get_results("SELECT ID FROM {$wpdb->prefix}users WHERE user_login = '$user_login'");
foreach($u_id as $user_id){
$users=$user_id->ID;
$data_array['user_id']=$users;
}
}
if($type == 'WooCommerce Reviews'){
$data_array['comment_type'] = 'review';
}
if ($post_exists) {
if($mode == 'Insert'){
if(empty( $data_array['comment_date'] )) {
$data_array['comment_date'] = current_time('mysql', 0);
}else{
$data_array['comment_date'] = date( 'Y-m-d H:i:s', strtotime( $data_array['comment_date'] ) );
}
$retID = wp_insert_comment($data_array);
$mode_of_affect = 'Inserted';
if(is_wp_error($retID) || $retID == '') {
$core_instance->detailed_log[$line_number]['Message'] = "Skipped, Due to unknown post ID.";
$fields = $wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey_value'");
$returnArr['MODE'] = $mode_of_affect;
return $returnArr;
}
$core_instance->detailed_log[$line_number]['Message'] = 'Inserted Comment ID: ' . $retID;
$core_instance->detailed_log[$line_number]['id'] = $retID;
$fields = $wpdb->get_results("UPDATE $log_table_name SET created = $created_count WHERE $unikey_name = '$unikey_value'");
}
if($mode == 'Update'){
$ID_result = $wpdb->get_results("SELECT comment_ID FROM {$wpdb->prefix}comments WHERE comment_post_ID = $post_id order by comment_ID DESC ");
if ( is_array( $ID_result ) && ! empty( $ID_result ) ) {
$retID = $ID_result[0]->comment_ID;
$data_array['comment_ID'] = $retID;
wp_update_comment( $data_array );
$mode_of_affect = 'Updated';
$core_instance->detailed_log[$line_number]['Message'] = 'Updated Comment ID: ' . $retID;
$fields = $wpdb->get_results("UPDATE $log_table_name SET updated = $updated_count WHERE $unikey_name = '$unikey_value'");
}else{
$retID = wp_insert_comment($data_array);
$mode_of_affect = 'Inserted';
if(is_wp_error($retID) || $retID == '') {
$core_instance->detailed_log[$line_number]['Message'] = "Skipped, Due to unknown post ID.";
$fields = $wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey_value'");
$returnArr['MODE'] = $mode_of_affect;
return $returnArr;
}
$core_instance->detailed_log[$line_number]['Message'] = 'Inserted Comment ID: ' . $retID;
$fields = $wpdb->get_results("UPDATE $log_table_name SET created = $created_count WHERE $unikey_name = '$unikey_value'");
}
}
if(isset($data_array['comment_rating'])){
$rating_range = range(1,5);
if(in_array($data_array['comment_rating'], $rating_range)){
update_comment_meta($retID ,'rating', $data_array['comment_rating']);
}
}
}else {
$retID = $commentid;
$core_instance->detailed_log[$line_number]['Message'] = "Skipped, Due to unknown post ID.";
$fields = $wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey_value'");
}
$returnArr['ID'] = $retID;
$returnArr['MODE'] = isset($mode_of_affect) ? $mode_of_affect :'';
return $returnArr;
}
public function menu_import_function($data_array , $mode , $unikey_value,$unikey_name , $line_number){
global $wpdb;
$menu_title = $data_array['menu_title'];
$check_term_exists = term_exists($menu_title, 'nav_menu');
if(is_array($check_term_exists)){
$insert_term_id = $check_term_exists['term_id'];
$insert_taxo_id = $check_term_exists['term_taxonomy_id'];
}
else{
$insert_term = wp_insert_term($menu_title, 'nav_menu');
$insert_term_id = $insert_term['term_id'];
$insert_taxo_id = $insert_term['term_taxonomy_id'];
}
$menu_item_types = explode(',', $data_array['_menu_item_type']);
$menu_item_objects = explode(',', $data_array['_menu_item_object']);
$menu_item_objects_ids = explode(',', $data_array['_menu_item_object_id']);
$menu_item_urls = explode(',', $data_array['_menu_item_url']);
$temp = 0;
foreach($menu_item_types as $menu_types){
$menu_object_titles = $menu_item_objects_ids[$temp];
$menu_objects = $menu_item_objects[$temp];
if($menu_types == 'custom'){
$post_title = $menu_object_titles;
}
else{
$post_title = '';
}
// posts table entry
$nav_post_arr = array(
'post_title' => $post_title,
'post_status' => 'publish',
'post_type' => 'nav_menu_item',
'menu_order' => $temp + 1
);
$inserted_post_id = wp_insert_post($nav_post_arr);
if($menu_types == 'post_type'){
$post_title_id = $wpdb->get_var("SELECT ID FROM {$wpdb->prefix}posts WHERE post_title = '$menu_object_titles' AND post_type = '$menu_objects' AND post_status = 'publish' ");
}
elseif($menu_types == 'taxonomy'){
$get_menu_term_id = get_term_by('name', $menu_object_titles, $menu_objects);
$post_title_id = $get_menu_term_id->term_id;
}
else{
$post_title_id = $inserted_post_id;
}
// postmeta table entry
update_post_meta($inserted_post_id, '_menu_item_type', $menu_types);
update_post_meta($inserted_post_id, '_menu_item_menu_item_parent', 0);
update_post_meta($inserted_post_id, '_menu_item_object_id', $post_title_id);
update_post_meta($inserted_post_id, '_menu_item_object', $menu_objects);
update_post_meta($inserted_post_id, '_menu_item_target', '');
update_post_meta($inserted_post_id, '_menu_item_classes', 'a:1:{i:0;s:0:"";}');
update_post_meta($inserted_post_id, '_menu_item_xfn', '');
update_post_meta($inserted_post_id, '_menu_item_url', $menu_item_urls[$temp]);
// terms relationship table entry
$wpdb->insert($wpdb->prefix.'term_relationships',
array('object_id' => $inserted_post_id,
'term_taxonomy_id' => $insert_taxo_id
),
array('%d','%d')
);
$temp++;
}
$menu_auto_add = $data_array['menu_auto_add'];
$get_auto_add = get_option("nav_menu_options");
foreach($get_auto_add as $auto_key => $auto_value){
if($auto_key == 'auto_add'){
if(empty($auto_value)){
if($menu_auto_add == 'yes'){
$get_auto_add['auto_add'] = array($insert_term_id);
update_option("nav_menu_options", $get_auto_add);
}
}
else{
if(!in_array($insert_term_id , $auto_value) && $menu_auto_add == 'yes'){
array_push($auto_value, $insert_term_id);
$get_auto_add['auto_add'] = $auto_value;
update_option("nav_menu_options", $get_auto_add);
}
}
}
}
$data_array_copy = $data_array;
$exclude_keys = array('menu_title', '_menu_item_type', '_menu_item_object', '_menu_item_object_id', '_menu_item_url', 'menu_auto_add');
foreach($exclude_keys as $exclude_key){
unset($data_array_copy[$exclude_key]);
}
foreach($data_array_copy as $data_key => $data_value){
if($data_value == 'yes'){
$locations = get_theme_mod( 'nav_menu_locations' );
$locations[$data_key] = $insert_term_id;
set_theme_mod ( 'nav_menu_locations', $locations );
}
}
}
public function widget_import_function($post_values , $mode ,$unikey_value,$unikey_name , $line_number){
foreach($post_values as $post_widget_key => $post_widget_value){
if(!empty($post_widget_value)){
$get_widget_id = explode('widget_', $post_widget_key);
$get_total_posts = explode('|', $post_widget_value);
foreach($get_total_posts as $per_post){
$get_post_footer = explode('->', $per_post);
$post_footer_number = $get_post_footer[1];
$sidebar = 'sidebar-'.$post_footer_number;
$get_post_details = explode(',', $get_post_footer[0]);
$widget_data = [];
if($post_widget_key == 'widget_recent-posts'){
$widget_data['title'] = $get_post_details[0];
$widget_data['number'] = $get_post_details[1];
$widget_data['show_date'] = $get_post_details[2];
}
elseif($post_widget_key == 'widget_pages'){
$widget_data['title'] = $get_post_details[0];
$widget_data['sortby'] = $get_post_details[1];
$exclude_ids = str_replace('/', ',', $get_post_details[2]);
$widget_data['exclude'] = $exclude_ids;
}
elseif($post_widget_key == 'widget_recent-comments'){
$widget_data['title'] = $get_post_details[0];
$widget_data['number'] = $get_post_details[1];
}
elseif($post_widget_key == 'widget_archives'){
$widget_data['title'] = $get_post_details[0];
$widget_data['count'] = $get_post_details[1];
$widget_data['dropdown'] = $get_post_details[2];
}
elseif($post_widget_key == 'widget_categories'){
$widget_data['title'] = $get_post_details[0];
$widget_data['count'] = $get_post_details[1];
$widget_data['hierarchical'] = $get_post_details[2];
$widget_data['dropdown'] = $get_post_details[3];
}
$this->insert_widget_in_sidebar( $get_widget_id[1], $widget_data, $sidebar );
}
}
}
}
public function insert_widget_in_sidebar( $widget_id, $widget_data, $sidebar ) {
// Retrieve sidebars, widgets and their instances
$sidebars_widgets = get_option( 'sidebars_widgets', array() );
$widget_instances = get_option( 'widget_' . $widget_id, array() );
// Retrieve the key of the next widget instance
$numeric_keys = array_filter( array_keys( $widget_instances ), 'is_int' );
//$next_key = $numeric_keys ? max( $numeric_keys ) + 1 : 2;
if((count($numeric_keys) == 1) && (empty($widget_instances[$numeric_keys[0]]['title']))){
$next_key = $numeric_keys[0];
}else{
$next_key = max( $numeric_keys ) + 1;
}
// Add this widget to the sidebar
if ( ! isset( $sidebars_widgets[ $sidebar ] ) ) {
$sidebars_widgets[ $sidebar ] = array();
}
$sidebar_key_id = $widget_id . '-' . $next_key;
if(!in_array($sidebar_key_id, $sidebars_widgets[ $sidebar ])){
$sidebars_widgets[ $sidebar ][] = $sidebar_key_id;
}
// Add the new widget instance
$widget_instances[ $next_key ] = $widget_data;
// Store updated sidebars, widgets and their instances
update_option( 'sidebars_widgets', $sidebars_widgets );
update_option( 'widget_' . $widget_id, $widget_instances );
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,285 @@
<?php
/**
* WP Ultimate CSV Importer plugin file.
*
* Copyright (C) 2010-2020, Smackcoders Inc - info@smackcoders.com
*/
namespace Smackcoders\FCSV;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class CustomerReviewsImport {
private static $customer_reviews_instance = null;
public static function getInstance() {
if (CustomerReviewsImport::$customer_reviews_instance == null) {
CustomerReviewsImport::$customer_reviews_instance = new CustomerReviewsImport;
return CustomerReviewsImport::$customer_reviews_instance;
}
return CustomerReviewsImport::$customer_reviews_instance;
}
public function customer_reviews_import($data_array, $mode , $unikey_value = null,$unikey_name = null , $line_number = null) {
global $wpdb;
$mapping_instance = MappingExtension::getInstance();
$helpers_instance = ImportHelpers::getInstance();
$core_instance = CoreFieldsImport::getInstance();
global $core_instance;
$log_table_name = $wpdb->prefix ."import_detail_log";
$reviewId = '';
$returnArray = array('MODE' => $mode);
$mode_of_affect = 'Inserted';
$update_review_info = false;
if(isset($data_array['review_format'])) {
if(!array_key_exists('review_format', $data_array) && !isset($data_array['review_format']) && !empty($data_array['review_format'])) {
$reviewFormat = 'business';
} else {
$reviewFormat = strtolower($data_array['review_format']);
}
}
$post_id = $data_array['review_post'];
$post_exists = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}posts WHERE id = '" . $post_id . "' and post_status in ('publish','draft','future','private','pending')", 'ARRAY_A');
$get_available_plugin_lists = $mapping_instance->get_active_plugins();
$updated_row_counts = $helpers_instance->update_count($unikey_value,$unikey_name);
$created_count = $updated_row_counts['created'];
$updated_count = $updated_row_counts['updated'];
$skipped_count = $updated_row_counts['skipped'];
if($mode == 'Insert') {
if ($post_exists) {
update_post_meta($post_id, 'wpcr3_enable', 1);
update_post_meta($post_id, 'wpcr3_format', $reviewFormat);
if(in_array('wp-customer-reviews/wp-customer-reviews-3.php', $get_available_plugin_lists)) {
$review_date = current_time('mysql', 0);
if(isset($data_array['date_time'])) {
$review_date = date( 'Y-m-d H:i:s', strtotime( $data_array['date_time'] ) );
}
$review_title = $data_array['review_name'];
$review_slug = preg_replace('/[^a-zA-Z0-9._\-\s]/', '', $review_title);
$review_slug = wp_unique_filename('', $review_slug);
if(isset($data_array['status'])) {
$data_array['status'] = strtolower( $data_array['status'] );
}
if ($data_array['status'] != 'publish' && $data_array['status'] != 'private' && $data_array['status'] != 'draft' && $data_array['status'] != 'pending' && $data_array['status'] != 'sticky') {
$data_array ['post_password'] = '';
$stripPSF = strpos($data_array['status'], '{');
if ($stripPSF === 0) {
$poststatus = substr($data_array['status'], 1);
$stripPSL = substr($poststatus, -1);
if ($stripPSL == '}') {
$postpwd = substr($poststatus, 0, -1);
$data_array['status'] = 'publish';
$data_array ['post_password'] = $postpwd;
} else {
$data_array['status'] = 'publish';
$data_array ['post_password'] = $poststatus;
}
} else {
$data_array['status'] = 'publish';
}
}
$review_array = array(
'post_author' => '1',
'post_date' => $review_date,
'post_content' => $data_array['review_text'],
'post_title' => $review_title,
'post_status' => $data_array['status'],
'comment_status' => 'closed',
'ping_status' => 'closed',
'post_password' => $data_array['post_password'],
'post_name' => $review_slug,
'post_parent' => 0,
'post_type' => 'wpcr3_review',
);
$reviewId = wp_insert_post($review_array);
if(is_wp_error($reviewId)) {
$core_instance->detailed_log[$line_number]['Message'] = "Can't insert this Review. " . $reviewId->get_error_message();
$fields = $wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey_value'");
return $returnArray;
}
$guId = site_url() . '/?post_type=wpcr3_review&#038;p=' . $reviewId;
wp_update_post(array('ID' => $reviewId, 'guid' => $guId));
// Review meta information
$review_meta_data = array(
'wpcr3_review_ip' => $data_array['review_ip'],
'wpcr3_review_post' => $data_array['review_post'],
'wpcr3_review_name' => $data_array['review_name'],
'wpcr3_review_email' => $data_array['review_email'],
'wpcr3_review_rating' => $data_array['review_rating'],
'wpcr3_review_title' => $data_array['review_title'],
'wpcr3_review_website' => $data_array['review_website'],
'wpcr3_review_admin_response' => $data_array['review_admin_response'],
'wpcr3_f1' => $data_array['custom_field1'],
'wpcr3_f2' => $data_array['custom_field2'],
'wpcr3_f3' => $data_array['custom_field3'],
);
foreach($review_meta_data as $metaKey => $metaValue) {
update_post_meta($reviewId, $metaKey, $metaValue);
}
} else {
$wpdb->insert($wpdb->wpcreviews, array('date_time' => $data_array['date_time'], 'review_name' => $data_array['review_name'], 'review_email' => $data_array['review_email'], 'review_ip' => $data_array['reviewer_ip'], 'review_title' => $data_array['review_title'], 'review_text' => $data_array['review_text'], 'review_admin_response' => $data_array['review_admin_response
'], 'status' => $data_array['status'], 'review_rating' => $data_array['review_rating'], 'review_website' => $data_array['review_website'], 'page_id' => $data_array['review_post']));
$reviewId = $wpdb->insert_id;
if(is_wp_error($reviewId)) {
$core_instance->detailed_log[$line_number]['Message'] = "Can't insert this Review. " . $reviewId->get_error_message();
$fields = $wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey_value'");
return $returnArray;
}
}
$mode_of_affect = 'Inserted';
$core_instance->detailed_log[$line_number]['Message'] = 'Inserted Review ID: ' . $reviewId;
$fields = $wpdb->get_results("UPDATE $log_table_name SET created = $created_count WHERE $unikey_name = '$unikey_value'");
}
} else {
if($post_exists) {
if($mode == 'Update') {
update_post_meta($post_id, 'wpcr3_enable', 1);
update_post_meta($post_id, 'wpcr3_format', $reviewFormat);
if(in_array('wp-customer-reviews/wp-customer-reviews-3.php', $get_available_plugin_lists)) {
$query = "select *from {$wpdb->prefix}posts where ID = '{$data_array['review_id']}' and post_type = 'wpcr3_review'";
$id_results = $wpdb->get_results($query);
$reviewId = $id_results[0]->ID;
$review_date = current_time('mysql', 0);
if(isset($data_array['date_time'])) {
$review_date = date( 'Y-m-d H:i:s', strtotime( $data_array['date_time'] ) );
}
$review_title = $data_array['review_name'];
$review_slug = preg_replace('/[^a-zA-Z0-9._\-\s]/', '', $review_title);
$review_slug = wp_unique_filename('', $review_slug);
if(isset($data_array['status'])) {
$data_array['status'] = strtolower( $data_array['status'] );
}
if ($data_array['status'] != 'publish' && $data_array['status'] != 'private' && $data_array['status'] != 'draft' && $data_array['status'] != 'pending' && $data_array['status'] != 'sticky') {
$stripPSF = strpos($data_array['status'], '{');
if ($stripPSF === 0) {
$poststatus = substr($data_array['status'], 1);
$stripPSL = substr($poststatus, -1);
if ($stripPSL == '}') {
$postpwd = substr($poststatus, 0, -1);
$data_array['status'] = 'publish';
$data_array ['post_password'] = $postpwd;
} else {
$data_array['status'] = 'publish';
$data_array ['post_password'] = $poststatus;
}
} else {
$data_array['status'] = 'publish';
}
}
$review_array = array(
'post_author' => '1',
'post_date' => $review_date,
'post_content' => $data_array['review_text'],
'post_title' => $review_title,
'post_status' => $data_array['status'],
'comment_status' => 'closed',
'ping_status' => 'closed',
'post_password' => $data_array['post_password'],
'post_name' => $review_slug,
'post_parent' => 0,
'post_type' => 'wpcr3_review',
);
if ( $reviewId == null ) {
$reviewId = wp_insert_post($review_array);
if(is_wp_error($reviewId)) {
$core_instance->detailed_log[$line_number]['Message'] = "Can't insert this Review. " . $reviewId->get_error_message();
$fields = $wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey_value'");
return $returnArray;
}
$mode_of_affect = 'Inserted';
$core_instance->detailed_log[$line_number]['Message'] = 'Inserted Review ID: ' . $reviewId;
$fields = $wpdb->get_results("UPDATE $log_table_name SET created = $created_count WHERE $unikey_name = '$unikey_value'");
} else {
$review_array['ID'] = $reviewId;
wp_update_post($review_array);
$mode_of_affect = 'Updated';
$core_instance->detailed_log[$line_number]['Message'] = 'Updated Review ID: ' . $reviewId;
$fields = $wpdb->get_results("UPDATE $log_table_name SET updated = $updated_count WHERE $unikey_name = '$unikey_value'");
}
$guId = site_url() . '/?post_type=wpcr3_review&#038;p=' . $reviewId;
wp_update_post(array('ID' => $reviewId, 'guid' => $guId));
// Review meta information
$review_meta_data = array(
'wpcr3_review_ip' => $data_array['review_ip'],
'wpcr3_review_post' => $data_array['review_post'],
'wpcr3_review_name' => $data_array['review_name'],
'wpcr3_review_email' => $data_array['review_email'],
'wpcr3_review_rating' => $data_array['review_rating'],
'wpcr3_review_title' => $data_array['review_title'],
'wpcr3_review_website' => $data_array['review_website'],
'wpcr3_review_admin_response' => $data_array['review_admin_response'],
'wpcr3_f1' => $data_array['custom_field1'],
'wpcr3_f2' => $data_array['custom_field2'],
'wpcr3_f3' => $data_array['custom_field3'],
);
foreach($review_meta_data as $metaKey => $metaValue) {
update_post_meta($reviewId, $metaKey, $metaValue);
}
} else {
$query = "select id from $wpdb->wpcreviews where (review_title = '{$data_array['review_title']}') and (page_id = '{$data_array['review_post']}') ";
$id_results = $wpdb->get_results( $query );
$reviewId = $id_results[0]->id;
if ( $reviewId == null ) {
$wpdb->insert( $wpdb->wpcreviews, array(
'date_time' => $data_array['date_time'],
'review_name' => $data_array['review_name'],
'review_email' => $data_array['review_email'],
'review_ip' => $data_array['review_ip'],
'review_title' => $data_array['review_title'],
'review_text' => $data_array['review_text'],
'review_admin_response' => $data_array['review_admin_response'],
'status' => $data_array['status'],
'review_rating' => $data_array['review_rating'],
'review_website' => $data_array['review_website'],
'page_id' => $data_array['review_post']
) );
$reviewId = $wpdb->insert_id;
$mode_of_affect = 'Inserted';
$core_instance->detailed_log[$line_number]['Message'] = 'Inserted Review ID: ' . $reviewId;
$fields = $wpdb->get_results("UPDATE $log_table_name SET created = $created_count WHERE $unikey_name = '$unikey_value'");
} else {
$wpdb->update( $wpdb->wpcreviews, array(
'date_time' => $data_array['date_time'],
'review_name' => $data_array['review_name'],
'id' => $reviewId,
'review_email' => $data_array['review_email'],
'review_ip' => $data_array['review_ip'],
'review_title' => $data_array['review_title'],
'review_text' => $data_array['review_text'],
'review_admin_response' => $data_array['review_admin_response'],
'status' => $data_array['status'],
'review_rating' => $data_array['review_rating'],
'review_website' => $data_array['review_website'],
'page_id' => $data_array['review_post']
) );
$mode_of_affect = 'Updated';
$core_instance->detailed_log[$line_number]['Message'] = 'Updated Review ID: ' . $reviewId;
$fields = $wpdb->get_results("UPDATE $log_table_name SET updated = $updated_count WHERE $unikey_name = '$unikey_value'");
}
}
}
}
}
return array('ID' => $reviewId, 'MODE' => $mode_of_affect);
}
}

View File

@@ -0,0 +1,108 @@
<?php
/******************************************************************************************
* Copyright (C) Smackcoders. - All Rights Reserved under Smackcoders Proprietary License
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* You can contact Smackcoders at email address info@smackcoders.com.
*******************************************************************************************/
namespace Smackcoders\FCSV;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class ElementorImport {
private static $elementor_instance = null,$media_instance;
public static function getInstance() {
if (ElementorImport::$elementor_instance == null) {
ElementorImport::$elementor_instance = new ElementorImport;
return ElementorImport::$elementor_instance;
}
return ElementorImport::$elementor_instance;
}
public function set_elementor_value($header_array ,$value_array , $map, $post_id , $type, $hash_key, $gmode, $templatekey){
$post_values = [];
$helpers_instance = ImportHelpers::getInstance();
$post_values = $helpers_instance->get_header_values($map , $header_array , $value_array);
foreach ($post_values as $custom_key => $custom_value) {
if(is_serialized($custom_value) && $custom_key != '_elementor_data'){
$custom_value = unserialize($custom_value);
}
elseif($custom_key =='_elementor_data'){
$custom_value = wp_slash(base64_decode($custom_value));
}
update_post_meta($post_id, $custom_key, $custom_value);
}
}
function set_elementor_values($header_array ,$value_array , $map, $post_id , $type, $mode, $line_number , $hash_key){
global $wpdb;
$smackcsv_instance = SmackCSV::getInstance();
$core_instance = CoreFieldsImport::getInstance();
$upload_dir = $smackcsv_instance->create_upload_dir();
$file_table_name = $wpdb->prefix . "smackcsv_file_events";
$file = $wpdb->get_results("SELECT file_name,total_rows FROM $file_table_name WHERE `hash_key` = '$hash_key'");
$file_name = $file[0]->file_name;
$total_rows = $file[0]->total_rows;
$addHeader =1;
$file_extension = pathinfo($file_name, PATHINFO_EXTENSION);
$csv_file = $upload_dir.$hash_key.'/'.$hash_key;
$file_handle = fopen($csv_file, 'r');
$first_row = true;
while (($data = fgetcsv($file_handle, 1000, ",")) !== FALSE) {
// Skip header row
if ($first_row) {
$first_row = false;
continue;
}
$content_data=$data[2];
$content=unserialize($content_data);
$styles =unserialize($data[3]);
$style_data =unserialize($styles);
$style_encode= json_encode($style_data);
$style_encode = wp_slash( $style_encode );
$template_data = [
'post_title' => $data[1],
'post_content' => $content['content'],
'post_type' => 'elementor_library',
'post_status' => $data[7],
'post_date' => $data[5],
'post_author' => 1,
];
$post_id = wp_insert_post($template_data);
$id[]= $post_id;
if ($id) {
foreach($id as $post_id){
if(isset($style_encode)){
add_post_meta($post_id, '_elementor_data', $style_encode);
add_post_meta($post_id, '_elementor_edit_mode', 'builder');
add_post_meta($post_id, '_elementor_version', '3.17.3');
add_post_meta($post_id, '_wp_page_template', 'default');
}
update_post_meta($post_id, '_elementor_template_type', $data[4]);
}
}
}
fclose($file_handle);
if ($id) {
foreach($id as $post_id){
$core_instance->detailed_log[$post_id]['Message'] = "Imported Successfully.Imported Template ID: $post_id <br/>";
$core_instance->detailed_log[$post_id]['VERIFY'] = "<b> Click here to verify</b> - <a href='" . get_permalink( $post_id ) . "' target='_blank' title='" . esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $template_title ) ) . "'rel='permalink'>Web View</a> | <a href='" . get_edit_post_link( $post_id, true ) . "'target='_blank' title='" . esc_attr( 'Edit this item' ) . "'>Admin View</a>";
}
$log_manager_instance = LogManager::getInstance();
$log_manager_instance->get_event_log($hash_key , $file_name , $file_extension , $mode , $total_rows , $type , $core_instance->detailed_log, $addHeader,$templatekey = null);
}
return $post_id;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,67 @@
<?php
/******************************************************************************************
* Copyright (C) Smackcoders. - All Rights Reserved under Smackcoders Proprietary License
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* You can contact Smackcoders at email address info@smackcoders.com.
*******************************************************************************************/
namespace Smackcoders\FCSV;
if (!defined('ABSPATH'))
exit; // Exit if accessed directly
class FIFUImport
{
private static $fifu_instance = null;
public static function getInstance()
{
if (FIFUImport::$fifu_instance == null) {
FIFUImport::$fifu_instance = new FIFUImport;
return FIFUImport::$fifu_instance;
}
return FIFUImport::$fifu_instance;
}
public function set_fifu_values($header_array, $value_array, $map, $post_id, $type, $mode){
$post_values = [];
$helpers_instance = ImportHelpers::getInstance();
$post_values = $helpers_instance->get_header_values($map, $header_array, $value_array);
$this->fifu_values_import($post_values, $post_id, $type, $mode);
}
public function fifu_values_import($post_values, $post_id, $type, $mode){
global $wpdb;
$fifu_array = [];
$author_id = get_option('fifu_author');
$attachment_id = wp_insert_attachment( array(
'post_mime_type' => 'image/jpeg',
'post_status' => 'inherit',
'post_title' => $post_values['fifu_image_alt'],
'post_type' => 'attachment',
'post_author' => $author_id,
'guid'=>$post_values['fifu_image_url'],
'post_parent'=>$post_id,
));
$fifu_array = [];
$fifu_array['fifu_image_url'] = isset($post_values['fifu_image_url']) ? $post_values['fifu_image_url'] : '';
$fifu_array['fifu_image_alt'] = isset($post_values['fifu_image_alt']) ? $post_values['fifu_image_alt'] : '';
$fifu_array['_thumbnail_id'] = isset($post_values['fifu_image_url']) ? $attachment_id : '';
foreach ($fifu_array as $fifu_key => $fifu_value) {
update_post_meta($post_id, $fifu_key, $fifu_value);
}
update_post_meta($attachment_id, '_wp_attached_file', $post_values['fifu_image_url']);
update_post_meta($attachment_id, '_wp_attachment_image_alt', $post_values['fifu_image_alt']);
}
}

View File

@@ -0,0 +1,625 @@
<?php
/**
* WP Ultimate CSV Importer plugin file.
*
* Copyright (C) 2010-2020, Smackcoders Inc - info@smackcoders.com
*/
namespace Smackcoders\FCSV;
use PhpParser\Error;
use PhpParser\ParserFactory;
use NXP\MathExecutor;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
require_once(__DIR__.'/../lib/autoload.php');
class ImportHelpers {
private static $helpers_instance = null;
public static function getInstance() {
if (ImportHelpers::$helpers_instance == null) {
ImportHelpers::$helpers_instance = new ImportHelpers;
self::$helpers_instance->doHooks();
return ImportHelpers::$helpers_instance;
}
return ImportHelpers::$helpers_instance;
}
public function doHooks(){
add_action('wp_ajax_check_import', array($this, 'checkImport'));
}
public function checkImport(){
check_ajax_referer('smack-ultimate-csv-importer', 'securekey');
if(\is_plugin_active('import-users/import-users/.php')){
$result['success'] =true;
}
else{
$result['success'] = false;
}
echo wp_json_encode($result);
wp_die();
}
public function get_requested_term_details ($post_id, $term,$taxonomy) {
if(is_array($term)){
foreach($term as $terms){
$termLen = strlen($terms);
$checktermid = intval($terms);
$verifiedTermLen = strlen($checktermid);
if($termLen == $verifiedTermLen && !is_string($terms)) {
return $terms;
}
}
$reg_term_id = wp_set_object_terms($post_id, $term, $taxonomy);
$terms = get_term_by('name',"$terms","$taxonomy");
if(isset($terms->term_id)){
$term_id = $terms->term_id;
//incase if term id and term taxonomy id are not same
// global $wpdb;
// $term_taxonomy_id = $reg_term_id[0];
// $term_id = $wpdb->get_var("SELECT term_id FROM {$wpdb->prefix}term_taxonomy WHERE term_taxonomy_id = $term_taxonomy_id");
}
return $term_id;
}
else{
$termLen = strlen($term);
$checktermid = intval($term);
$verifiedTermLen = strlen($checktermid);
if($termLen == $verifiedTermLen) {
return $term;
} else {
$reg_term_id = wp_set_object_terms($post_id, $term, 'category');
if(isset($reg_term_id[0])){
$term_id = $reg_term_id[0];
}
return $term_id;
}
}
}
public function get_from_user_details($request_user) {
global $wpdb;
$authorLen = strlen($request_user);
$checkpostuserid = intval($request_user);
$postAuthorLen = strlen($checkpostuserid);
if ($authorLen == $postAuthorLen) {
$postauthor = $wpdb->get_results($wpdb->prepare("select ID,user_login from $wpdb->users where ID = %s", $request_user));
if (empty($postauthor) || !$postauthor[0]->ID) { // If user name are numeric Ex: 1300001
$postauthor = $wpdb->get_results($wpdb->prepare("select ID,user_login from $wpdb->users where user_login = \"{%s}\"",$request_user));
}
} else {
$postauthor = $wpdb->get_results($wpdb->prepare("select ID,user_login from $wpdb->users where user_login = %s", $request_user));
}
if (empty($postauthor) || !$postauthor[0]->ID) {
$request_user = 1;
$admindet = $wpdb->get_results($wpdb->prepare("select ID,user_login from $wpdb->users where ID = %d", 1));
$message = " <b>Author :- </b> not found (assigned to <b>" . $admindet[0]->user_login . "</b>)";
} else {
$request_user = $postauthor[0]->ID;
$admindet = $wpdb->get_results($wpdb->prepare("select ID,user_login from $wpdb->users where ID = %s", $request_user));
$message = " <b>Author :- </b>" . $admindet[0]->user_login;
}
$userDetails['user_id'] = $request_user;
$userDetails['user_login'] = $admindet[0]->user_login;
$userDetails['message'] = $message;
return $userDetails;
}
public function assign_post_status($data_array) {
global $wpdb;
if (isset($data_array['is_post_status']) && $data_array['is_post_status'] != 'on') {
$data_array ['post_status'] = $data_array['is_post_status'];
unset($data_array['is_post_status']);
}
// if (isset($data_array ['post_type']) && $data_array ['post_type'] == 'page') {
// $data_array ['post_status'] = 'publish';
// }
if($data_array['post_status'] == 'trash'){
$title=$data_array['post_title'];
$trash = $wpdb->get_results(
"DELETE FROM {$wpdb->prefix}posts WHERE post_title = '$title' AND post_status='publish' "
);
}
elseif($data_array['post_status'] == 'delete'){
$post_title=$data_array['post_title'];
$id=$wpdb->query("select ID FROM {$wpdb->prefix}posts WHERE post_title= '$post_title' ");
$id = $wpdb->get_results("select ID FROM {$wpdb->prefix}posts WHERE post_title= '$post_title' ");
foreach ($id as $delete_id){
$del_id=$delete_id->ID;
wp_delete_post($del_id, true);
}
}
else {
if(isset($data_array['post_status']) || isset($data_array['coupon_status'])) {
if(isset($data_array['post_status'])) {
$data_array['post_status'] = strtolower( $data_array['post_status'] );
} else {
$data_array['post_status'] = strtolower( $data_array['coupon_status'] );
}
$data_array['post_status'] = trim($data_array['post_status']);
if ($data_array['post_status'] != 'publish' && $data_array['post_status'] != 'private' && $data_array['post_status'] != 'draft' && $data_array['post_status'] != 'pending' && $data_array['post_status'] != 'sticky'&& $data_array['post_status'] != 'scheduled' && $data_array['post_status'] != 'future') {
$stripPSF = strpos($data_array['post_status'], '{');
if ($stripPSF === 0) {
$poststatus = substr($data_array['post_status'], 1);
$stripPSL = substr($poststatus, -1);
if ($stripPSL == '}') {
$postpwd = substr($poststatus, 0, -1);
$data_array['post_status'] = 'publish';
$data_array ['post_password'] = $postpwd;
} else {
$data_array['post_status'] = 'publish';
$data_array ['post_password'] = $poststatus;
}
} else {
$data_array['post_status'] = 'publish';
}
}
else if($data_array['post_status'] == 'scheduled'){
$data_array['post_status'] = 'future';
}
if ($data_array['post_status'] == 'sticky') {
$data_array['post_status'] = 'publish';
$sticky = true;
}
} else {
$data_array['post_status'] = 'publish';
}
}
return $data_array;
}
public function import_post_types($import_type, $importAs = null) {
$import_type = trim($import_type);
$module = array('Posts' => 'post', 'Pages' => 'page', 'Users' => 'user', 'JetReviews' => 'jetreviews', 'Comments' => 'comments', 'Taxonomies' => $importAs, 'CustomerReviews' =>'wpcr3_review', 'Categories' => 'categories', 'Tags' => 'tags', 'WooCommerce' => 'product', 'WPeCommerce' => 'wpsc-product','WPeCommerceCoupons' => 'wpsc-product', 'WooCommerceOrders' => 'product', 'WooCommerceCoupons' => 'product', 'WooCommerceRefunds' => 'product', 'CustomPosts' => $importAs,'WooCommerceReviews' =>'reviews');
foreach (get_taxonomies() as $key => $taxonomy) {
$module[$taxonomy] = $taxonomy;
}
if(array_key_exists($import_type, $module)) {
return $module[$import_type];
}
else {
return $import_type;
}
}
public function UCI_WPML_Supported_Posts ($data_array, $pId) {
global $sitepress, $wpdb;
$get_trid = $wpdb->get_results("select trid from {$wpdb->prefix}icl_translations ORDER BY translation_id DESC limit 1");
$trid = $get_trid[0]->trid;
if(empty($data_array['translated_post_title']) && !empty($data_array['language_code'])){
$wpdb->insert( $wpdb->prefix.'icl_translations', array('element_type' => 'post_'.$data_array['post_type'],'language_code' => $data_array['language_code'],'element_id' => $pId , 'trid' => $trid + 1));
}
elseif(!empty($data_array['language_code']) && !empty($data_array['translated_post_title'])){
$update_query = $wpdb->prepare("select ID,post_type from {$wpdb->prefix}posts where post_title = %s and post_type=%s order by ID DESC",$data_array['translated_post_title'] , $data_array['post_type']);
$ID_result = $wpdb->get_results($update_query);
if(is_array($ID_result) && !empty($ID_result)) {
$element_id = $ID_result[0]->ID;
$post_type = $ID_result[0]->post_type;
}else{
return false;
}
/* Update Multi-language */
$update = $wpdb->prepare("select translation_id from {$wpdb->prefix}posts where element_id = %s order by ID DESC",$pId);
$result_ID = $wpdb->get_results($update);
if(is_array($result_ID) && !empty($result_ID)) {
$upelement_id = $result_ID[0]->ID;
}
$trid_id = $sitepress->get_element_trid($element_id,'post_'.$post_type);
$translate_lcode = $sitepress->get_language_for_element($element_id,'post_'.$post_type);
if(!empty($result_ID)){
$wpdb->update($wpdb->prefix.'icl_translations', array(
'element_type' => 'post_'.$data_array['post_type'],
'trid' => $trid_id,
'language_code' => $data_array['language_code'],
'source_language_code' => $translate_lcode
), array('element_id' => $pId ), array( '%s', '%s', '%s', '%s' ), array( '%d' ) );
} else{
$wpdb->insert( $wpdb->prefix.'icl_translations', array( 'element_type' => 'post_'.$data_array['post_type'],'trid' => $trid_id, 'language_code' => $data_array['language_code'], 'source_language_code' => $translate_lcode ,'element_id' => $pId));
}
}
}
public function get_header_values($map , $header_array , $value_array){
$current_user = wp_get_current_user();
$current_user_role = $current_user->roles[0];
if($current_user_role == 'administrator'){
$post_values = [];
$trim_content = array(
'->static' => '',
'->math' => '',
'->cus1' => '',
'->openAI' => '',
);
if(is_array($map)){
foreach($map as $header_keys => $value){
if( strpos($header_keys, '->cus2') !== false) {
if(!empty($value)){
$this->write_to_customfile($value, $header_array, $value_array);
unset($map[$header_keys]);
}
}
else{
$header_trim = strtr($header_keys, $trim_content);
if($header_trim != $header_keys){
unset($map[$header_keys]);
}
$map[$header_trim] = $value;
}
}
foreach($map as $key => $value){
$csv_value= trim($map[$key]);
$value_assoc = array_combine($header_array, $value_array);
if(!empty($csv_value)){
//$pattern = "/({([a-z A-Z 0-9 | , _ -]+)(.*?)(}))/";
$pattern1 = '/{([^}]*)}/';
$pattern2 = '/\[([^\]]*)\]/';
if(preg_match_all($pattern1, $csv_value, $matches, PREG_PATTERN_ORDER)){
//check for inbuilt or custom function call -> enclosed in []
if(preg_match_all($pattern2, $csv_value, $matches2)){
$matched_element = $matches2[1][0];
foreach($matches[1] as $value){
$get_value = $this->replace_header_with_values($value, $header_array, $value_array);
$values = '{'.$value.'}';
$get_value = '"'.$get_value.'"';
$matched_element = str_replace($values, $get_value, $matched_element);
}
$csv_element = $this->evalPhp($matched_element);
}
else{
$csv_element = $csv_value;
//foreach($matches[2] as $value){
foreach($matches[1] as $value){
$get_key = array_search($value , $header_array);
if(isset($value_array[$get_key])){
$csv_value_element = $value_array[$get_key];
//}
$value = '{'.$value.'}';
$csv_element = str_replace($value, $csv_value_element, $csv_element);
}
}
$math = 'MATH';
if (strpos($csv_element, $math) !== false) {
$equation = str_replace('MATH', '', $csv_element);
$csv_element = $this->evalMath($equation);
}
}
$wp_element= trim($key);
if(!empty($csv_element) && !empty($wp_element)){
$post_values[$wp_element] = $csv_element;
}
}
elseif (preg_match_all($pattern2, $csv_value, $matches2)) {
$matched_element = $matches2[1][0];
$wp_element = trim($key);
$csv_element1 = '';
if ($matched_element === 'fields' && strpos($wp_element, '_wpbdp[fields][') === 0) {
if (isset($value_assoc[$wp_element])) {
$csv_element1 = $value_assoc[$wp_element];
}
if (!empty($csv_element1)) {
if (strpos($csv_element1, '|') !== false) {
$csv_element1 = explode('|', $csv_element1);
} else {
$csv_element1 = trim($csv_element1);
}
}
} else {
$csv_element1 = $this->evalPhp($matched_element);
}
if (!empty($csv_element1) && !empty($wp_element)) {
$post_values[$wp_element] = $csv_element1;
}
}
elseif(!in_array($csv_value , $header_array)){
$wp_element= trim($key);
$post_values[$wp_element] = $csv_value;
}
else{
$get_key = array_search($csv_value , $header_array);
if(isset($value_array[$get_key])){
$csv_element = $value_array[$get_key];
//}
$wp_element = trim($key);
if(isset($csv_element) && !empty($wp_element)){
$post_values[$wp_element] = $csv_element;
}
}
}
}
}
}
}
return $post_values;
}
/**
* Function to evaluate Math equations
*/
public function evalMath($equation) {
// Sanitize input
$equation = preg_replace("/[^0-9+\-.*\/()%]/", "", $equation);
// Convert percentages to decimal
$equation = preg_replace("/([+-])([0-9]{1})(%)/", "*(1$1.0$2)", $equation);
$equation = preg_replace("/([+-])([0-9]+)(%)/", "*(1$1.$2)", $equation);
try {
$executor = new MathExecutor();
return $executor->execute($equation);
} catch (Exception $e) {
$return("Unable to calculate equation");
}
}
/**
* Function to evaluate PHP expressions
*/
public function evalPhp($expression) {
$parser = (new ParserFactory)->createForNewestSupportedVersion();
try {
$parser->parse($expression);
$value=$parser->parse($expression);
if(!empty($value)){
$expression=sanitize_text_field($expression);
return eval('return '.$expression.';');
}
} catch (Error $error) {
return 'Parse Error: '. $error->getMessage();
}
}
public function get_post_ids($post_id , $eventKey,$templatekey = null){
$smack_instance = SmackCSV::getInstance();
$recordId = array($post_id);
if($templatekey != null) {
$upload_dir = $smack_instance->create_upload_dir('CLI');
$eventInfoFile = $upload_dir.$eventKey.'/'.$templatekey.'/'.$templatekey.'.txt';
}
else{
$upload_dir = $smack_instance->create_upload_dir();
$eventInfoFile = $upload_dir.$eventKey.'/'.$eventKey.'.txt';
}
if(file_exists($eventInfoFile)) {
$handle = fopen( $eventInfoFile, 'r' );
$contents = json_decode( fread( $handle, filesize( $eventInfoFile ) ) );
fclose( $handle );
}
$fp = fopen($eventInfoFile, 'w+');
if(!empty($contents) && $contents != null) {
$contents = array_merge( $contents, $recordId );
$contents = json_encode( $contents );
} else {
$contents = json_encode( $recordId );
}
fwrite($fp, $contents);
fclose($fp);
}
public function update_log($message , $status , $verify , $post_id , $hash_key){
global $wpdb;
$importlog_table_name = $wpdb->prefix ."import_log_detail";
$wpdb->insert($importlog_table_name, array(
'hash_key' => $hash_key,
'message' => "{$message}",
'status' => "{$status}",
'verify' => "{$verify}",
'post_id' => $post_id,
),
array('%s', '%s', '%s', '%s', '%d')
);
}
public function update_error_log($message , $hash_key , $post_id){
global $wpdb;
$importlog_table_name = $wpdb->prefix ."import_log_detail";
$wpdb->insert($importlog_table_name, array(
'hash_key' => $hash_key,
'message' => "{$message}",
'post_id' => $post_id
),
array('%s', '%s', '%d')
);
}
public function update_category_log($category , $post_id){
global $wpdb;
$wpdb->update($wpdb->prefix.'import_log_detail', array(
'categories' => "{$category}"
),
array('post_id' => $post_id)
);
}
public function update_tag_log($tag , $post_id){
global $wpdb;
$wpdb->update($wpdb->prefix.'import_log_detail', array(
'tags' => "{$tag}"
),
array('post_id' => $post_id)
);
}
public function update_status_log($status , $verify , $post_id){
global $wpdb;
$wpdb->update($wpdb->prefix.'import_log_detail', array(
'status' => "{$status}",
'verify' => "{$verify}"
),
array('post_id' => $post_id)
);
}
public function formatSizeUnits($bytes)
{
if ($bytes >= 1073741824)
{
$bytes = number_format($bytes / 1073741824, 2) . ' GB';
}
elseif ($bytes >= 1048576)
{
$bytes = number_format($bytes / 1048576, 2) . ' MB';
}
elseif ($bytes >= 1024)
{
$bytes = number_format($bytes / 1024, 2) . ' KB';
}
elseif ($bytes > 1)
{
$bytes = $bytes . ' bytes';
}
elseif ($bytes == 1)
{
$bytes = $bytes . ' byte';
}
else
{
$bytes = '0 bytes';
}
return $bytes;
}
public function update_count($unikey_value,$unikey_name){
$response = [];
global $wpdb;
$log_table_name = $wpdb->prefix ."import_detail_log";
$get_data = $wpdb->get_results("SELECT skipped , created , updated FROM $log_table_name WHERE $unikey_name = '$unikey_value' ");
$skipped = $get_data[0]->skipped;
$response['skipped'] = $skipped + 1;
$created = $get_data[0]->created;
$response['created'] = $created + 1;
$updated = $get_data[0]->updated;
$response['updated'] = $updated + 1;
return $response;
}
public function validate_datefield($date,$field,$dateformat,$line_number){
if(empty($date)){
return $date;
}
$core_instance = CoreFieldsImport::getInstance();
$index = "</br><b>Info about " . $field . "</b>";
//Validate the date
if(strtotime( $date )) {
$date = date( $dateformat, strtotime( $date ) );
}
else {
//check the date format as mm-dd-yyyy (valid)
$date = str_replace(array('.','-'), '/', $date);
if(!strtotime($date)){
//Invalid date
//check the date format as 18/05/2022 (valid)
$date = str_replace('/','-',$date);
if(strtotime($date)){
//valid
$date = date( $dateformat, strtotime( $date ) );
}
else {
//Invalid
$core_instance->detailed_log[$line_number][$index] = "Date format provided is wrong. Correct date format is Y-m-d" ;
$date = '';
}
}
else {
//Valid date
$date = date( $dateformat, strtotime( $date ) );
}
}
return $date;
}
public function write_to_customfile($csv_value, $header_array = null, $value_array = null) {
// Only allow admin users (or users with 'manage_options') to write
if (!current_user_can('manage_options')) {
wp_die(__('You do not have sufficient permissions to access this page.'));
}
// Prepare upload directory
$upload = wp_upload_dir();
$upload_base_dir = $upload['basedir'] . '/smack_uci_uploads';
if (!file_exists($upload_base_dir)) {
wp_mkdir_p($upload_base_dir); // creates directory safely
}
$custom_file_path = $upload_base_dir . '/custom_data.json';
// Initialize file if it doesn't exist
if (!file_exists($custom_file_path)) {
file_put_contents($custom_file_path, json_encode([]));
chmod($custom_file_path, 0644);
}
// Safely replace placeholders with values
if ($header_array && $value_array && preg_match_all('/{+(.*?)}/', $csv_value, $matches)) {
foreach ($matches[1] as $key) {
$replacement = isset($value_array[$key]) ? $value_array[$key] : '';
$csv_value = str_replace('{'.$key.'}', $replacement, $csv_value);
}
}
// Load existing data safely
$existing_data = json_decode(file_get_contents($custom_file_path), true);
if (!is_array($existing_data)) {
$existing_data = [];
}
// Avoid duplicates
if (!in_array($csv_value, $existing_data)) {
$existing_data[] = $csv_value;
file_put_contents($custom_file_path, json_encode($existing_data, JSON_PRETTY_PRINT));
chmod($custom_file_path, 0644);
}
// Return the stored data for further use
return $existing_data;
}
public function replace_header_with_values($csv_header, $header_array, $value_array){
$csv_value = $csv_header;
$get_key = array_search($csv_header , $header_array);
if(isset($value_array[$get_key])){
$csv_value = $value_array[$get_key];
}
return $csv_value;
}
}

View File

@@ -0,0 +1,298 @@
<?php
/******************************************************************************************
* Copyright (C) Smackcoders. - All Rights Reserved under Smackcoders Proprietary License
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* You can contact Smackcoders at email address info@smackcoders.com.
*******************************************************************************************/
namespace Smackcoders\FCSV;
if (!defined('ABSPATH'))
exit; // Exit if accessed directly
class JetBookingImport
{
private static $instance = null, $media_instance;
public static function getInstance()
{
if (JetBookingImport::$instance == null) {
JetBookingImport::$instance = new JetBookingImport;
JetBookingImport::$instance = new JetBookingImport;
JetBookingImport::$media_instance = MediaHandling::getInstance();
}
return JetBookingImport::$instance;
}
function set_jet_booking_values($header_array, $value_array, $map, $post_id, $type, $mode, $hash_key, $line_number, $gmode, $templatekey)
{
$post_values = [];
$helpers_instance = ImportHelpers::getInstance();
$post_values = $helpers_instance->get_header_values($map, $header_array, $value_array);
$this->jet_booking_fields_import_function($post_values, $type, $post_id, $mode, $hash_key, $line_number, $header_array, $value_array, $gmode, $templatekey);
}
public function jet_booking_fields_import_function($data_array, $type, $post_id, $mode, $hash_key, $line_number, $header_array, $value_array, $gmode, $templatekey)
{
global $wpdb;
$helpers_instance = ImportHelpers::getInstance();
$plugin = 'jetengine-booking';
$media_instance = MediaHandling::getInstance();
$darray = array();
$listTaxonomy = get_taxonomies();
if (in_array($type, $listTaxonomy)) {
$get_import_type = 'term';
} elseif ($type == 'Users' || $type == 'user') {
$get_import_type = 'user';
} elseif ($type == 'Comments') {
$get_import_type = 'comment';
} else {
$get_import_type = 'post';
}
foreach ($data_array as $dkey => $dvalue) {
$dvalue = trim($dvalue);
if (!empty($dvalue) && ($dkey == 'jet_abaf_price' || $dkey == 'jet_abaf_custom_schedule' || $dkey == 'jet_abaf_configuration')) {
// Unserialize the string, if possible
$data = maybe_unserialize($dvalue);
if (is_string($data)) {
$data = unserialize($dvalue);
}
// Update post meta with properly serialized data
update_post_meta($post_id, $dkey, $data);
}
}
if (!empty($data_array['unit_title'])) {
$unit_titles = explode('|', $data_array['unit_title']);
$numbers = explode('|', $data_array['unit_number']);
// Ensure both arrays have the same length
if (count($unit_titles) === count($numbers)) {
foreach ($unit_titles as $index => $unit_title) {
$number = !empty($numbers[$index]) ? absint($numbers[$index]) : 1;
$apartment = $post_id;
$result = jet_abaf()->db->get_apartment_units($apartment);
$current_count = count($result);
for ($i = 1; $i <= $number; $i++) {
$unit_num = $current_count + $i;
// Insert each unit with its title and calculated unit number
jet_abaf()->db::wpdb()->insert(jet_abaf()->db->units->table(), [
'apartment_id' => $apartment,
'unit_title' => $unit_title . ' ' . $unit_num,
]);
}
$current_count += $number;
}
}
}
}
function jet_booking_import($item, $type, $mode, $unikey, $unikey_name, $line_number, $update_based_on, $check, $hash_key)
{
global $wpdb;
$helpers_instance = ImportHelpers::getInstance();
$core_instance = CoreFieldsImport::getInstance();
global $core_instance;
$log_table_name = $wpdb->prefix . "import_detail_log";
$updated_row_counts = $helpers_instance->update_count($unikey, $unikey_name);
$created_count = $updated_row_counts['created'];
$updated_count = $updated_row_counts['updated'];
$skipped_count = $updated_row_counts['skipped'];
$item['status'] = strtolower($item['status']);
if ($item['status'] == 'on hold' || $item['status'] == 'onhold') {
$item['status'] = 'on-hold';
}
if ($mode == 'Insert' && !empty($item)) {
$result = $this->insert_booking($item, $wpdb, $core_instance, $helpers_instance, $created_count, $updated_count, $skipped_count, $log_table_name, $type, $mode, $unikey, $unikey_name, $line_number, $update_based_on, $check, $hash_key);
} else if ($mode == 'Update' && !empty($item)) {
$result = $this->update_booking($item, $wpdb, $core_instance, $helpers_instance, $created_count, $updated_count, $skipped_count, $log_table_name, $type, $mode, $unikey, $unikey_name, $line_number, $update_based_on, $check, $hash_key);
}
return $result;
}
public function update_booking($item, $wpdb, $core_instance, $helpers_instance, $created_count, $updated_count, $skipped_count, $log_table_name, $type, $mode, $unikey, $unikey_name, $line_number, $update_based_on, $check, $hash_key)
{
$item_id = $item['booking_id'];
if (! empty($item['attributes'])) {
wp_cache_set('booking_attributes_' . $item_id, $item['attributes']);
}
if (! empty($item['guests'])) {
wp_cache_set('booking_guests_' . $item_id, $item['guests']);
}
$not_allowed = [
'booking_id',
'order_id',
'user_id',
'attributes',
'guests',
];
if (empty($item) || empty($item['check_in_date']) || empty($item['check_out_date'])) {
$core_instance->detailed_log[$line_number]['Message'] = "No data to update. Incorrect item data in Jet-Booking.";
$core_instance->detailed_log[$line_number]['state'] = 'Skipped';
$wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey'");
return array('MODE' => $mode, 'ERROR_MSG' => 'No data to update');
}
foreach ($not_allowed as $key) {
if (isset($item[$key])) {
unset($item[$key]);
}
}
$item['check_in_date'] = strtotime($item['check_in_date']);
$item['check_out_date'] = strtotime($item['check_out_date']);
$apartment_units = jet_abaf()->db->get_apartment_units($item['apartment_id']);
if (! empty($apartment_units)) {
$apartment_unit = jet_abaf()->db->get_apartment_unit($item['apartment_id'], $item['apartment_unit']);
if (empty($apartment_unit)) {
$item['apartment_unit'] = jet_abaf()->db->get_available_unit($item);
}
}
$is_available = jet_abaf()->db->booking_availability($item, $item_id);
$is_dates_available = jet_abaf()->db->is_booking_dates_available($item, $item_id);
$is_days_available = jet_abaf()->tools->is_booking_period_available($item);
if (! $is_available && ! $is_dates_available || ! $is_days_available) {
$error_message = "Unable to add this record ";
if (! $is_available) {
$error_message .= "Booking unit is not open or available.";
} elseif (! $is_dates_available) {
$error_message .= "Requested booking dates are unavailable.";
} elseif (! $is_days_available) {
$error_message .= "Requested booking days are unavailable.";
} else {
$error_message .= "Something went wrong";
}
// Log the message and update the detailed log
$core_instance->detailed_log[$line_number]['Message'] = $error_message;
$core_instance->detailed_log[$line_number]['state'] = 'Skipped';
$wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey'");
return array('MODE' => $mode, 'ERROR_MSG' => $error_message);
}
jet_abaf()->db->update_booking($item_id, $item);
$mode_of_affect = 'Updated';
$core_instance->detailed_log[$line_number]['state'] = 'Updated';
$wpdb->get_results("UPDATE $log_table_name SET updated = $updated_count WHERE $unikey_name = '$unikey'");
$returnArr['ID'] = $item_id;
$returnArr['MODE'] = $mode_of_affect;
return $returnArr;
}
public function insert_booking($item, $wpdb, $core_instance, $helpers_instance, $created_count, $updated_count, $skipped_count, $log_table_name, $type, $mode, $unikey, $unikey_name, $line_number, $update_based_on, $check, $hash_key)
{
$order_status = $item['orderStatus'];
$import_id = $item['import_id'];
$user_id = $item['user_id'];
unset($item['orderStatus']);
if (empty($item['check_in_date']) || empty($item['check_out_date'])) {
$core_instance->detailed_log[$line_number]['Message'] = "Booking date is empty";
$core_instance->detailed_log[$line_number]['state'] = 'Skipped';
$wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey'");
return array('MODE' => $mode, 'ERROR_MSG' => 'Invalid');
}
$item['check_in_date'] = strtotime($item['check_in_date']);
$item['check_out_date'] = strtotime($item['check_out_date']);
if ($item['check_in_date'] >= $item['check_out_date']) {
$item['check_out_date'] = $item['check_in_date'] + 12 * HOUR_IN_SECONDS;
}
if (empty($item['apartment_unit'])) {
$item['apartment_unit'] = jet_abaf()->db->get_available_unit($item);
}
$is_available = jet_abaf()->db->booking_availability($item);
$is_dates_available = jet_abaf()->db->is_booking_dates_available($item);
$is_days_available = jet_abaf()->tools->is_booking_period_available($item);
$bookings_cpt = jet_abaf()->settings->get('apartment_post_type');
$posts = jet_abaf()->tools->get_booking_posts();
$post_ids = wp_list_pluck($posts, 'ID');
$apartment_id = !empty($item['apartment_id']) ? $item['apartment_id'] : false;
$apartment_id_check = in_array($apartment_id, $post_ids) ? true : false;
if (! $apartment_id || ! $apartment_id_check || ! $is_available && ! $is_dates_available || ! $is_days_available) {
$error_message = "Unable to add this record ";
if (! $apartment_id) {
$error_message .= "Apartment ID is missing.";
} else if (! $apartment_id_check) {
$error_message .= "Apartment ID is not available in your " . $bookings_cpt;
} else if (! $is_available) {
$error_message .= "Booking unit is not open or available.";
} elseif (! $is_dates_available) {
$error_message .= "Requested booking dates are unavailable.";
} elseif (! $is_days_available) {
$error_message .= "Requested booking days are unavailable.";
} else {
$error_message .= "Something went wrong.";
}
// Log the message and update the detailed log
$core_instance->detailed_log[$line_number]['Message'] = $error_message;
$core_instance->detailed_log[$line_number]['state'] = 'Skipped';
$wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey'");
return array('MODE' => $mode, 'ERROR_MSG' => $error_message);
}
$booking_id = jet_abaf()->db->insert_booking($item);
if ($booking_id !== '0' && ! empty($order_status)) {
$this->set_related_order_data($order_status, $booking_id, $item);
} else {
$core_instance->detailed_log[$line_number]['Message'] = "Cat't add this apartment_id is invalid";
$core_instance->detailed_log[$line_number]['state'] = 'Skipped';
$wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey'");
return array('MODE' => $mode, 'ERROR_MSG' => 'apartment_id invalid');
}
$mode_of_affect = 'Inserted';
$core_instance->detailed_log[$line_number]['state'] = 'Inserted';
$wpdb->get_results("UPDATE $log_table_name SET created = $created_count WHERE $unikey_name = '$unikey'");
$returnArr['ID'] = $booking_id;
$returnArr['MODE'] = $mode_of_affect;
return $returnArr;
}
public function set_related_order_data($order_status, $booking_id, $booking)
{
if ('plain' === jet_abaf()->settings->get('booking_mode') && ! jet_abaf()->settings->get('wc_integration')) {
$post_type = jet_abaf()->settings->get('related_post_type');
$post_type_object = get_post_type_object($post_type);
$args = [
'post_type' => $post_type,
'post_status' => ! empty($order_status) ? $order_status : 'draft',
];
if (post_type_supports($post_type, 'excerpt')) {
$args['post_excerpt'] = sprintf(__('This is %s post.', 'jet-booking'), $post_type_object->labels->singular_name);
}
$post_id = wp_insert_post($args);
if (! $post_id || is_wp_error($post_id)) {
return;
}
wp_update_post([
'ID' => $post_id,
'post_title' => $post_type_object->labels->singular_name . ' #' . $post_id,
'post_name' => $post_type_object->labels->singular_name . '-' . $post_id,
]);
jet_abaf()->db->update_booking($booking_id, ['order_id' => $post_id]);
} else {
do_action('jet-booking/rest-api/add-booking/set-related-order-data', $order_status, $booking_id, $booking);
}
}
}

View File

@@ -0,0 +1,453 @@
<?php
/******************************************************************************************
* Copyright (C) Smackcoders. - All Rights Reserved under Smackcoders Proprietary License
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* You can contact Smackcoders at email address info@smackcoders.com.
*******************************************************************************************/
namespace Smackcoders\FCSV;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class JetEngineCCTImport {
private static $instance = null;
public static function getInstance() {
if (JetEngineCCTImport::$instance == null) {
JetEngineCCTImport::$instance = new JetEngineCCTImport;
}
return JetEngineCCTImport::$instance;
}
function set_jet_engine_cct_values($header_array ,$value_array , $map, $post_id , $type , $mode, $hash_key,$line_number){
$post_values = [];
$helpers_instance = ImportHelpers::getInstance();
$post_values = $helpers_instance->get_header_values($map , $header_array , $value_array);
$this->jet_engine_cct_import_function($post_values,$type, $post_id, $mode, $hash_key,$line_number,$header_array,$value_array);
}
public function jet_engine_cct_import_function($data_array, $type, $pID ,$mode, $hash_key,$line_number,$header_array,$value_array)
{
global $wpdb;
$helpers_instance = ImportHelpers::getInstance();
$media_instance = MediaHandling::getInstance();
$table_names = 'jet_cct_'.$type;
$single_post_id = $data_array['cct_single_post_id'];
$get_results = $wpdb->get_results("SELECT cct_status FROM {$wpdb->prefix}$table_names WHERE _ID = $pID ");
$listTaxonomy = get_taxonomies();
if (in_array($type, $listTaxonomy)) {
$get_import_type = 'termcct';
}elseif ($type == 'Users' || $type == 'user') {
$get_import_type = 'usercct';
}elseif ($type == 'Comments') {
$get_import_type = 'commentcct';
} else {
$get_import_type = 'postcct';
}
if(empty($get_results)){
return;
}
$jet_data = $this->JetEngineCCTFields($type);
$get_gallery_id = $gallery_ids = '';
foreach ($data_array as $dkey => $dvalue) {
if(array_key_exists($dkey,$jet_data['JECCT'])){
if($jet_data['JECCT'][$dkey]['type'] == 'text' ||$jet_data['JECCT'][$dkey]['type'] == 'textarea'
|| $jet_data['JECCT'][$dkey]['type'] == 'colorpicker' || $jet_data['JECCT'][$dkey]['type'] == 'iconpicker'
|| $jet_data['JECCT'][$dkey]['type'] == 'radio' || $jet_data['JECCT'][$dkey]['type'] == 'number'
|| $jet_data['JECCT'][$dkey]['type'] == 'wysiwyg' || $jet_data['JECCT'][$dkey]['type'] == 'switcher'){
$dvalue = preg_replace('/\s+/', ' ', $dvalue);
// Minify the HTML content
$dvalue = trim($dvalue);
$darray[$jet_data['JECCT'][$dkey]['name']] = $dvalue;
}
elseif($jet_data['JECCT'][$dkey]['type'] == 'date'){
$dateformat = 'Y-m-d';
if(!empty($dvalue)){
$var = trim($dvalue);
$date = str_replace('/', '-', "$var");
if($jet_data['JECCT'][$dkey]['is_timestamp']){
if(is_numeric($date)){
$date_of = $date;
}
else{
$date_of = strtotime($date);
}
}else{
$date_of = $helpers_instance->validate_datefield($var,$dkey,$dateformat,$line_number);
}
$darray[$jet_data['JECCT'][$dkey]['name']] = $date_of;
}
else{
$darray[$jet_data['JECCT'][$dkey]['name']] = '';
}
}
elseif($jet_data['JECCT'][$dkey]['type'] == 'gallery' || $jet_data['JECCT'][$dkey]['type'] == 'media'){
$gallery_ids ='';
$media_ids = '';
$media_id='';
$dselect='';
$exploded_gallery_items = explode( ',', $dvalue );
$galleryvalue=array();
$shortcode_table = $wpdb->prefix . "ultimate_csv_importer_shortcode_manager";
$indexs = 0;
foreach ( $exploded_gallery_items as $gallery ) {
$gallery = trim( $gallery );
if ( preg_match_all( '/\b(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)[-A-Z0-9+&@#\/%=~_|$?!:,.]*[A-Z0-9+&@#\/%=~_|$]/i', $gallery ) ) {
$field_name = $jet_data['JECCT'][$dkey]['name'];
$field_type = $jet_data['JECCT'][$dkey]['type'];
$plugin = 'jetengine_'.$field_type;
$imgformat = $jet_data['JECCT'][$dkey]['value_format'];
$media_instance->store_image_ids($i=1);
$get_gallery_id = $media_instance->image_meta_table_entry($line_number,$data_array, $pID, $field_name,$gallery, $hash_key, $plugin,'','','',$header_array, $value_array,$imgformat,'',$indexs);
if ( $get_gallery_id != '' ) {
if($jet_data['JECCT'][$dkey]['type'] == 'media'){
$media_ids .= $get_gallery_id. ',';
}
elseif($jet_data['JECCT'][$dkey]['value_format'] == 'url'){
$get_gallery_fields = $wpdb->get_results("select meta_value from {$wpdb->prefix}postmeta where post_id=$get_gallery_id and meta_key ='_wp_attached_file'");
$dir = wp_upload_dir();
$gallery_ids .= $dir ['baseurl'] . '/' .$get_gallery_fields[0]->meta_value. ',';
}
elseif($jet_data['JECCT'][$dkey]['value_format'] == 'both'){
$gallery_id1 ['id']= $get_gallery_id;
$get_gallery_fields = $wpdb->get_results("select meta_value from {$wpdb->prefix}postmeta where post_id=$get_gallery_id and meta_key ='_wp_attached_file'");
$dir = wp_upload_dir();
$gallery_id2['url']= $dir ['baseurl'] . '/' .$get_gallery_fields[0]->meta_value;
$galleryvalue[] = array_merge($gallery_id1,$gallery_id2);
$gallery_ids=$galleryvalue;
}
else{
$gallery_ids .= $get_gallery_id.',';
}
}
} else {
$galleryLen = strlen( $gallery );
$checkgalleryid = intval( $gallery );
$verifiedGalleryLen = strlen( $checkgalleryid );
if ( $galleryLen == $verifiedGalleryLen ) {
if($jet_data['JECCT'][$dkey]['type'] == 'media'){
$media_ids .= $gallery. ',';
}
else{
$gallery_ids .= $gallery. ',';
}
}
}
$indexs++;
}
if(is_array($gallery_ids)){
$gallery_id = $gallery_ids;
}
if (!is_array($gallery_ids)) {
$gallery_id = rtrim($gallery_ids,',');
}
if(isset($media_ids)){
$media_id = rtrim($media_ids,',');
}
if($jet_data['JECCT'][$dkey]['value_format'] == 'url'){
$get_media_fields = $wpdb->get_results("select meta_value from {$wpdb->prefix}postmeta where post_id=$media_id and meta_key ='_wp_attached_file'");
$dir = wp_upload_dir();
if(!empty($get_media_fields[0]->meta_value)){
$media_id = $dir ['baseurl'] . '/' .$get_media_fields[0]->meta_value;
}
else{
$media_id='';
}
}
elseif($jet_data['JECCT'][$dkey]['value_format'] == 'both'){
if ( $media_id != '' ) {
$media_ids1['id']=$media_id;
$get_media_fields = $wpdb->get_results("select meta_value from {$wpdb->prefix}postmeta where post_id=$media_id and meta_key ='_wp_attached_file'");
$dir = wp_upload_dir();
if(!empty($get_media_fields[0]->meta_value)){
$media_ids2['url'] = $dir ['baseurl'] . '/' .$get_media_fields[0]->meta_value;
}
else{
$media_ids2['url']='';
}
$mediavalue= array_merge($media_ids1,$media_ids2);
$media_id=array($mediavalue);
}
}
else{
$media_id=$media_id;
}
if($jet_data['JECCT'][$dkey]['type'] == 'media'){
$darray[$jet_data['JECCT'][$dkey]['name']] = $media_id;
}
else{
$darray[$jet_data['JECCT'][$dkey]['name']] = $gallery_id;
}
}
elseif($jet_data['JECCT'][$dkey]['type'] == 'datetime-local'){
$dateformat = 'Y-m-d\TH:m';
if(!empty($dvalue)) {
$dt_var = trim($dvalue);
$datetime = str_replace('/', '-', "$dt_var");
if($jet_data['JECCT'][$dkey]['is_timestamp']){
if(is_numeric($datetime)){
$date_time_of = $datetime;
}
else{
$date_time_of = strtotime($datetime);
}
}else{
$date_time_of = $helpers_instance->validate_datefield($dt_var,$dkey,$dateformat,$line_number);
}
$darray[$jet_data['JECCT'][$dkey]['name']] = $date_time_of;
}
else {
$darray[$jet_data['JECCT'][$dkey]['name']] = '';
}
}
elseif($jet_data['JECCT'][$dkey]['type'] == 'time'){
$var = trim($dvalue);
$time = date('H:i', strtotime($var));
$darray[$jet_data['JECCT'][$dkey]['name']] = $time;
}
elseif($jet_data['JECCT'][$dkey]['type'] == 'checkbox'){
if($jet_data['JECCT'][$dkey]['is_array'] == 1){
$dvalexp = explode(',' , $dvalue);
$darray[$jet_data['JECCT'][$dkey]['name']] = $dvalexp;
}
else{
$options = $jet_data['JECCT'][$dkey]['options'];
$arr = [];
$opt = [];
$dvalexp = explode(',' , $dvalue);
foreach($options as $option_key => $option_val){
//$opt[$option_key] = $option_val['key'];
$arr[$option_val['key']] = 'false';
}
foreach($dvalexp as $dvalkey => $dvalueval){
$dvalueval = trim($dvalueval);
$keys = array_keys($arr);
foreach($keys as $keys1){
if($dvalueval == $keys1){
$arr[$keys1] = 'true';
}
}
//added new checkbox values
if(!in_array($dvalueval, $keys)){
$get_meta_fields = $wpdb->get_results("SELECT id, meta_fields from {$wpdb->prefix}jet_post_types where slug = '$type' and status = 'content-type'");
if(isset($get_meta_fields[0])){
$unserialized_meta = maybe_unserialize($get_meta_fields[0]->meta_fields);
$jet_engine_id = $get_meta_fields[0]->id;
if(!empty($unserialized_meta)){
foreach($unserialized_meta as $jet_keys => $jet_values){
$count_jetvalues = 0;
if($jet_values['type'] == 'checkbox' && $jet_values['name'] == $dkey){
$count_jetvalues = count($jet_values['options']);
$unserialized_meta[$jet_keys]['options'][$count_jetvalues]['key'] = $dvalueval;
$unserialized_meta[$jet_keys]['options'][$count_jetvalues]['value'] = $dvalueval;
$unserialized_meta[$jet_keys]['options'][$count_jetvalues]['id'] = $jet_values['options'][$count_jetvalues - 1]['id'] + 1;
}
}
$serialized_meta = serialize($unserialized_meta);
$wpdb->update( $wpdb->prefix . 'jet_post_types' ,
array(
'meta_fields' => $serialized_meta,
) ,
array(
'id' => $jet_engine_id
)
);
$arr[$dvalueval] = 'true';
}
}
}
}
$check_val=serialize($arr);
$darray[$jet_data['JECCT'][$dkey]['name']] = $check_val;
}
}
elseif($jet_data['JECCT'][$dkey]['type'] == 'select'){
$dselect = [];
if($jet_data['JECCT'][$dkey]['is_multiple'] == 0 || empty($jet_data['JECCT'][$dkey]['is_multiple'])){
$darray[$jet_data['JECCT'][$dkey]['name']] = $dvalue;
}
else{
$exp = explode(',',$dvalue);
foreach($exp as $exp_values){
$dselect[] = trim($exp_values);
}
//$dselect = $exp;
$darray[$jet_data['JECCT'][$dkey]['name']] = $dselect;
}
}
elseif($jet_data['JECCT'][$dkey]['type'] == 'posts'){
if($jet_data['JECCT'][$dkey]['is_multiple'] == 0){
//$jet_posts = $wpdb->_real_escape($jet_posts);
if(is_numeric($dvalue)) {
$jet_post_values=$dvalue;
$darray[$jet_data['JECCT'][$dkey]['name']] = $jet_post_values;
}
else{
$jet_posts = trim($dvalue);
$query = "SELECT id FROM {$wpdb->prefix}posts WHERE post_title ='{$jet_posts}' AND post_status='publish'";
$name = $wpdb->get_results($query);
if (!empty($name)) {
$jet_posts_values=$name[0]->id;
}
$darray[$jet_data['JECCT'][$dkey]['name']] = $jet_posts_values;
}
}
else{
$jet_posts_exp = explode(',',trim($dvalue));
$jet_posts_value = array();
$jet_posts_field_value = array();
foreach($jet_posts_exp as $jet_posts_value){
$jet_posts_value = trim($jet_posts_value);
if(is_numeric($jet_posts_value)){
$jet_posts_field_value[]=$jet_posts_value;
}
else{
if(!empty($jet_posts_value)){
$query = "SELECT id FROM {$wpdb->prefix}posts WHERE post_title ='{$jet_posts_value}' AND post_status='publish' ORDER BY ID DESC";
$multiple_id = $wpdb->get_results($query);
$multiple_id[0] = isset($multiple_id[0]) ? $multiple_id[0] : '';
$multiple_ids =$multiple_id[0];
if(!$multiple_id){
$jet_posts_field_value[]=$jet_posts_value;
}
else{
$jet_posts_field_value[]=trim($multiple_ids->id);
}
}
}
}
$jet_posts_value=serialize($jet_posts_field_value);
$darray[$jet_data['JECCT'][$dkey]['name']] = $jet_posts_value;
}
}
else{
if($jet_data['JECCT'][$dkey]['type'] != 'repeater'){
$darray[$jet_data['JECCT'][$dkey]['name']] = $dvalue;
}
}
// html
}
}
$darray['cct_modified']= date("Y-m-d\TH:i");
$table_name = 'jet_cct_'.$type;
if($darray){
$dataArray = [];
$key_name = '';
$data_values = '';
foreach($darray as $mkey => $mval){
if(is_array($mval)){
$darray[$mkey] = serialize($mval);
}
}
$wpdb->update($wpdb->prefix.'jet_cct_'.$type,
$darray,
array( '_ID' => $pID)
);
}
$getarg = $wpdb->get_results("SELECT args from {$wpdb->prefix}jet_post_types where slug = '$type' and status = 'content-type'",ARRAY_A);
foreach($getarg as $key => $value){
$arg_data = $value['args'];
break;
}
$arg_data = unserialize($arg_data);
if(!empty($arg_data) && array_key_exists('has_single',$arg_data) && $arg_data['has_single']){
$this->set_has_single($arg_data,$darray,$type,$pID,$mode,$single_post_id);
}
}
public function JetEngineCCTFields($type){
global $wpdb;
$jet_field = array();
$get_meta_fields = $wpdb->get_results($wpdb->prepare("select id, meta_fields from {$wpdb->prefix}jet_post_types where slug = %s and status = %s", $type, 'content-type'));
$unserialized_meta = maybe_unserialize($get_meta_fields[0]->meta_fields);
foreach($unserialized_meta as $jet_key => $jet_value){
$customFields["JECCT"][ $jet_value['name']]['label'] = $jet_value['title'];
$customFields["JECCT"][ $jet_value['name']]['name'] = $jet_value['name'];
$customFields["JECCT"][ $jet_value['name']]['type'] = $jet_value['type'];
$customFields["JECCT"][ $jet_value['name']]['options'] = isset($jet_value['options']) ? $jet_value['options'] : '';
$customFields["JECCT"][ $jet_value['name']]['is_multiple'] = isset($jet_value['is_multiple']) ? $jet_value['is_multiple'] : '';
$customFields["JECCT"][ $jet_value['name']]['is_array'] = isset($jet_value['is_array']) ? $jet_value['is_array'] : '';
$customFields["JECCT"][ $jet_value['name']]['value_format'] = isset($jet_value['value_format']) ? $jet_value['value_format'] : '';
if($jet_value['type'] == 'date' || $jet_value['type'] == 'datetime-local'){
$customFields["JECCT"][ $jet_value['name']]['is_timestamp'] = isset($jet_value['is_timestamp']) ? $jet_value['is_timestamp'] : '';
}
$jet_field[] = $jet_value['name'];
}
return $customFields;
}
function set_has_single($data,$field_data,$type,$pID,$mode,$single_post_id){
$title_field = $content_field = "";
$relation_title = $relation_content = "";
if(array_key_exists('related_post_type',$data)){
$relation_type = $data['related_post_type'];
if(array_key_exists('related_post_type_title',$data)){
$title_field = $data['related_post_type_title'];
}
if(array_key_exists('related_post_type_content',$data)){
$content_field = $data['related_post_type_content'];
}
}
if(array_key_exists($title_field,$field_data)){
$relation_title = $field_data[$title_field];
}
if(array_key_exists($content_field,$field_data)){
$relation_content = $field_data[$content_field];
}
$this->create_interrelation($relation_title,$relation_content,$type,$relation_type,$pID,$mode,$single_post_id);
}
function create_interrelation($title,$content,$type,$relation_type,$pID,$mode,$single_post_id){
global $wpdb;
$data_array['post_title'] = $title;
$data_array['post_content'] = $content;
$data_array['post_status'] = 'publish';
$data_array['post_name'] = str_replace(" ","-",$title);
$data_array['post_date'] = current_time('Y-m-d H:i:s');
$data_array['post_type'] = $relation_type;
if($mode == 'Insert'){
$post_id = wp_insert_post($data_array);
}
if(!empty($post_id)){
$wpdb->update( $wpdb->prefix . 'jet_cct_'.$type ,
array(
'cct_single_post_id' => $post_id,
) ,
array(
'_ID' => $pID
)
);
}
}
}

View File

@@ -0,0 +1,284 @@
<?php
/******************************************************************************************
* Copyright (C) Smackcoders. - All Rights Reserved under Smackcoders Proprietary License
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* You can contact Smackcoders at email address info@smackcoders.com.
*******************************************************************************************/
namespace Smackcoders\FCSV;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class JetEngineCPTImport {
private static $instance = null;
public static function getInstance() {
if (JetEngineCPTImport::$instance == null) {
JetEngineCPTImport::$instance = new JetEngineCPTImport;
}
return JetEngineCPTImport::$instance;
}
function set_jet_engine_cpt_values($header_array ,$value_array , $map, $post_id , $type , $mode, $hash_key,$line_number){
$post_values = [];
$helpers_instance = ImportHelpers::getInstance();
$post_values = $helpers_instance->get_header_values($map , $header_array , $value_array);
$extension_object = new ExtensionHandler;
$import_as = $extension_object->import_post_types($type );
$this->jet_engine_cpt_import_function($post_values,$import_as, $post_id, $mode, $hash_key,$line_number,$header_array,$value_array);
}
public function jet_engine_cpt_import_function($data_array, $type, $pID ,$mode, $hash_key,$line_number,$header_array,$value_array)
{
global $wpdb;
$helpers_instance = ImportHelpers::getInstance();
$media_instance = MediaHandling::getInstance();
if($type == 'WooCommerce Product'){
$type = 'product';
}
$jet_data = $this->JetEngineCPTFields($type);
foreach ($data_array as $dkey => $dvalue) {
if(array_key_exists($dkey,$jet_data['JECPT'])){
if ($jet_data['JECPT'][$dkey]['type'] === 'advanced-date') {
$meta_value = [];
$date_test = trim($dvalue) ?? '';
if (!empty($date_test)) {
$date_parts = explode(',', $date_test);
// Assign date parts to core fields
$meta_value = [
'date' => $date_parts[0] ?? '',
'time' => $date_parts[1] ?? '',
'is_end_date' => $date_parts[2] ?? '',
'end_date' => $date_parts[3] ?? '',
'end_time' => $date_parts[4] ?? '',
'is_recurring' => $date_parts[5] ?? '',
'recurring' => $date_parts[6] ?? '',
'recurring_period' => $date_parts[7] ?? ''
];
// Add recurring details based on recurrence type
$recurring = $meta_value['recurring'];
switch ($recurring) {
case 'daily':
$meta_value['end'] = $date_parts[8] ?? '';
$meta_value['end_after_date'] = $date_parts[9] ?? '';
break;
case 'weekly':
$meta_value['week_days'] = explode('|', $date_parts[8] ?? '');
$meta_value['end'] = $date_parts[9] ?? '';
$meta_value['end_after_date'] = $date_parts[10] ?? '';
break;
case 'monthly':
$meta_value['monthly_type'] = $date_parts[8] ?? '';
$meta_value['month_day'] = $date_parts[9] ?? '';
$meta_value['month_day_type'] = $date_parts[10] ?? '';
$meta_value['month_day_type_value'] = $date_parts[11] ?? '';
$meta_value['end'] = $date_parts[12] ?? '';
$meta_value['end_after_date'] = $date_parts[13] ?? '';
break;
case 'yearly':
$meta_value['monthly_type'] = $date_parts[8] ?? '';
$meta_value['month'] = $date_parts[9] ?? '';
$meta_value['month_day'] = $date_parts[10] ?? '';
$meta_value['month_day_type'] = $date_parts[11] ?? '';
$meta_value['month_day_type_value'] = $date_parts[12] ?? '';
$meta_value['end'] = $date_parts[13] ?? '';
$meta_value['end_after_date'] = $date_parts[14] ?? '';
break;
}
//update meta
$meta_key = sanitize_key($dkey . '__config');
$meta_value_json = json_encode($meta_value);
update_post_meta($pID, $meta_key, $meta_value_json);
}
}
if($jet_data['JECPT'][$dkey]['type'] == 'datetime-local'){
$dateformat = 'Y-m-d\TH:m';
if(!empty($dvalue)){
$dt_var = trim($dvalue);
$datetime = str_replace('/', '-', "$dt_var");
if($jet_data['JECPT'][$dkey]['is_timestamp']){
if(is_numeric($datetime)){
$date_time_of = $datetime;
}
else{
$date_time_of = strtotime($datetime);
}
}else{
$date_time_of = $helpers_instance->validate_datefield($dt_var,$dkey,$dateformat,$line_number);
}
$darray[$jet_data['JECPT'][$dkey]['name']] = $date_time_of;
}
else{
$darray[$jet_data['JECPT'][$dkey]['name']] = '';
}
}
elseif($jet_data['JECPT'][$dkey]['type'] == 'date'){
$dateformat = 'Y-m-d';
if(!empty($dvalue)){
$var = trim($dvalue);
$date = str_replace('/', '-', "$var");
if($jet_data['JECPT'][$dkey]['is_timestamp']){
if(is_numeric($date)){
$date_of = $date;
}
else{
$date_of = strtotime($date);
}
}else{
$date_of = $helpers_instance->validate_datefield($var,$dkey,$dateformat,$line_number);
}
$darray[$jet_data['JECPT'][$dkey]['name']] = $date_of;
}
else{
$darray[$jet_data['JECPT'][$dkey]['name']] = '';
}
}
elseif($jet_data['JECPT'][$dkey]['type'] == 'time'){
$var = trim($dvalue);
$time = date('H:i', strtotime($var));
$darray[$jet_data['JECPT'][$dkey]['name']] = $time;
}
elseif($jet_data['JECPT'][$dkey]['type'] == 'checkbox'){
$dvalue = trim($dvalue);
if($jet_data['JECPT'][$dkey]['is_array'] == 1){
$dvalexp = explode(',' , $dvalue);
$darray[$jet_data['JECPT'][$dkey]['name']] = $dvalexp;
}
else{
$options = $jet_data['JECPT'][$dkey]['options'];
$arr = [];
$opt = [];
$dvalexp = explode(',' , $dvalue);
foreach($options as $option_key => $option_val){
$arr[$option_val['key']] = 'false';
}
foreach($dvalexp as $dvalkey => $dvalueval){
$dvalueval = trim($dvalueval);
$keys = array_keys($arr);
foreach($keys as $keys1){
if($dvalueval == $keys1){
$arr[$keys1] = 'true';
}
}
//added new checkbox values
if(!in_array($dvalueval, $keys)){
$get_meta_fields = $wpdb->get_results("SELECT id, meta_fields FROM {$wpdb->prefix}jet_post_types WHERE slug = '$type' AND status IN ('publish','built-in')");
if(isset($get_meta_fields[0])){
$unserialized_meta = maybe_unserialize($get_meta_fields[0]->meta_fields);
$jet_engine_id = $get_meta_fields[0]->id;
if(!empty($unserialized_meta)){
foreach($unserialized_meta as $jet_keys => $jet_values){
$count_jetvalues = 0;
if($jet_values['type'] == 'checkbox' && $jet_values['name'] == $dkey){
$count_jetvalues = count($jet_values['options']);
$unserialized_meta[$jet_keys]['options'][$count_jetvalues]['key'] = $dvalueval;
$unserialized_meta[$jet_keys]['options'][$count_jetvalues]['value'] = $dvalueval;
$unserialized_meta[$jet_keys]['options'][$count_jetvalues]['id'] = $jet_values['options'][$count_jetvalues - 1]['id'] + 1;
}
}
$serialized_meta = serialize($unserialized_meta);
$wpdb->update( $wpdb->prefix . 'jet_post_types' ,
array(
'meta_fields' => $serialized_meta,
) ,
array(
'id' => $jet_engine_id
)
);
$arr[$dvalueval] = 'true';
}
}
}
}
$darray[$jet_data['JECPT'][$dkey]['name']] = $arr;
}
}
elseif($jet_data['JECPT'][$dkey]['type'] == 'select'){
$dselect = [];
if($jet_data['JECPT'][$dkey]['is_multiple'] == 0){
$darray[$jet_data['JECPT'][$dkey]['name']] = $dvalue;
}
else{
$exp = explode(',',$dvalue);
foreach($exp as $exp_values){
$dselect[] = trim($exp_values);
}
// $dselect = $exp;
$darray[$jet_data['JECPT'][$dkey]['name']] = $dselect;
}
}
else{
if($jet_data['JECPT'][$dkey]['type'] != 'repeater'){
$darray[$jet_data['JECPT'][$dkey]['name']] = $dvalue;
}
}
}
}
if($darray){
foreach($darray as $mkey => $mval){
update_post_meta($pID, $mkey, $mval);
}
}
}
public function JetEngineCPTFields($type){
global $wpdb;
$jet_field = array();
$get_meta_fields = $wpdb->get_results("SELECT id, meta_fields FROM {$wpdb->prefix}jet_post_types WHERE slug = '$type' AND status IN ('publish','built-in')");
if(isset($get_meta_fields[0])){
$unserialized_meta = maybe_unserialize($get_meta_fields[0]->meta_fields);
}
else{
$unserialized_meta = '';
}
$customFields = [];
if(is_array($unserialized_meta)){
foreach($unserialized_meta as $jet_key => $jet_value){
$customFields["JECPT"][ $jet_value['name']]['label'] = $jet_value['title'];
$customFields["JECPT"][ $jet_value['name']]['name'] = $jet_value['name'];
$customFields["JECPT"][ $jet_value['name']]['type'] = $jet_value['type'];
$customFields["JECPT"][ $jet_value['name']]['options'] = isset($jet_value['options']) ? $jet_value['options'] : '';
$customFields["JECPT"][ $jet_value['name']]['is_multiple'] = isset($jet_value['is_multiple']) ? $jet_value['is_multiple'] : '';
$customFields["JECPT"][ $jet_value['name']]['is_array'] = isset($jet_value['is_array']) ? $jet_value['is_array'] : '';
$customFields["JECPT"][ $jet_value['name']]['value_format'] = isset($jet_value['value_format']) ? $jet_value['value_format'] : '';
if($jet_value['type'] == 'date' || $jet_value['type'] == 'datetime-local'){
$customFields["JECPT"][ $jet_value['name']]['is_timestamp'] = isset($jet_value['is_timestamp']) ? $jet_value['is_timestamp'] : '';
}
$jet_field[] = $jet_value['name'];
}
}
return $customFields;
}
}

View File

@@ -0,0 +1,427 @@
<?php
/******************************************************************************************
* Copyright (C) Smackcoders. - All Rights Reserved under Smackcoders Proprietary License
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* You can contact Smackcoders at email address info@smackcoders.com.
*******************************************************************************************/
namespace Smackcoders\FCSV;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class JetEngineImport {
private static $instance = null;
public static function getInstance() {
if (JetEngineImport::$instance == null) {
JetEngineImport::$instance = new JetEngineImport;
}
return JetEngineImport::$instance;
}
function set_jet_engine_values($header_array ,$value_array , $map, $post_id , $type , $mode, $hash_key,$line_number){
$post_values = [];
$helpers_instance = ImportHelpers::getInstance();
$post_values = $helpers_instance->get_header_values($map , $header_array , $value_array);
$this->jet_engine_import_function($post_values,$type, $post_id, $mode, $hash_key,$line_number,$header_array,$value_array);
}
public function jet_engine_import_function($data_array, $type, $pID ,$mode, $hash_key,$line_number,$header_array,$value_array)
{
global $wpdb;
$helpers_instance = ImportHelpers::getInstance();
$media_instance = MediaHandling::getInstance();
$jet_data = $this->JetEngineFields($type);
foreach ($data_array as $dkey => $dvalue) {
if(array_key_exists($dkey,$jet_data['JE'])){
if($jet_data['JE'][$dkey]['type'] == 'advanced-date'){
$meta_value = [];
$date_test = trim($dvalue) ?? '';
if (!empty($date_test)) {
$date_parts = explode(',', $date_test);
// Assign date parts to core fields
$meta_value = [
'date' => $date_parts[0] ?? '',
'time' => $date_parts[1] ?? '',
'is_end_date' => $date_parts[2] ?? '',
'end_date' => $date_parts[3] ?? '',
'end_time' => $date_parts[4] ?? '',
'is_recurring' => $date_parts[5] ?? '',
'recurring' => $date_parts[6] ?? '',
'recurring_period' => $date_parts[7] ?? ''
];
// Add recurring details based on recurrence type
$recurring = $meta_value['recurring'];
switch ($recurring) {
case 'daily':
$meta_value['end'] = $date_parts[8] ?? '';
$meta_value['end_after_date'] = $date_parts[9] ?? '';
break;
case 'weekly':
$meta_value['week_days'] = explode('|', $date_parts[8] ?? '');
$meta_value['end'] = $date_parts[9] ?? '';
$meta_value['end_after_date'] = $date_parts[10] ?? '';
break;
case 'monthly':
$meta_value['monthly_type'] = $date_parts[8] ?? '';
$meta_value['month_day'] = $date_parts[9] ?? '';
$meta_value['month_day_type'] = $date_parts[10] ?? '';
$meta_value['month_day_type_value'] = $date_parts[11] ?? '';
$meta_value['end'] = $date_parts[12] ?? '';
$meta_value['end_after_date'] = $date_parts[13] ?? '';
break;
case 'yearly':
$meta_value['monthly_type'] = $date_parts[8] ?? '';
$meta_value['month'] = $date_parts[9] ?? '';
$meta_value['month_day'] = $date_parts[10] ?? '';
$meta_value['month_day_type'] = $date_parts[11] ?? '';
$meta_value['month_day_type_value'] = $date_parts[12] ?? '';
$meta_value['end'] = $date_parts[13] ?? '';
$meta_value['end_after_date'] = $date_parts[14] ?? '';
break;
}
//update meta
$meta_key = sanitize_key($dkey . '__config');
$meta_value_json = json_encode($meta_value);
update_post_meta($pID, $meta_key, $meta_value_json);
}
}
else if($jet_data['JE'][$dkey]['type'] == 'gallery' || $jet_data['JE'][$dkey]['type'] == 'media'){
$gallery_ids = $media_ids = '';
$exploded_gallery_items = explode( ',', $dvalue );
$galleryvalue=array();
$shortcode_table = $wpdb->prefix . "ultimate_csv_importer_shortcode_manager";
$indexs = 0;
foreach ( $exploded_gallery_items as $gallery ) {
$gallery = trim( $gallery );
if ( preg_match_all( '/\b(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)[-A-Z0-9+&@#\/%=~_|$?!:,.]*[A-Z0-9+&@#\/%=~_|$]/i', $gallery ) ) {
$field_name = $jet_data['JE'][$dkey]['name'];
$field_type = $jet_data['JE'][$dkey]['type'];
$plugin = 'jetengine_'.$field_type;
$imgformat = $jet_data['JE'][$dkey]['value_format'];
$media_instance->store_image_ids($i=1);
$get_gallery_id = $media_instance->image_meta_table_entry($line_number,$data_array, $pID, $field_name,$gallery, $hash_key, $plugin,'','','',$header_array, $value_array,$imgformat,'',$indexs);
if ( $get_gallery_id != '' ) {
if($jet_data['JE'][$dkey]['type'] == 'media'){
$media_ids .= $get_gallery_id. ',';
}
elseif($jet_data['JE'][$dkey]['value_format'] == 'url'){
global $wpdb;
$get_gallery_fields = $wpdb->get_results("select meta_value from {$wpdb->prefix}postmeta where post_id=$get_gallery_id and meta_key ='_wp_attached_file'");
$dir = wp_upload_dir();
$gallery_ids .= $dir ['baseurl'] . '/' .$get_gallery_fields[0]->meta_value. ',';
}
elseif($jet_data['JE'][$dkey]['value_format'] == 'both'){
global $wpdb;
$gallery_id1 ['id']= $get_gallery_id;
$get_gallery_fields = $wpdb->get_results("select meta_value from {$wpdb->prefix}postmeta where post_id=$get_gallery_id and meta_key ='_wp_attached_file'");
$dir = wp_upload_dir();
$gallery_id2['url']= $dir ['baseurl'] . '/' .$get_gallery_fields[0]->meta_value;
$galleryvalue[] = array_merge($gallery_id1,$gallery_id2);
$gallery_ids=$galleryvalue;
}
else{
$gallery_ids .= $get_gallery_id.',';
}
}
} else {
$galleryLen = strlen( $gallery );
$checkgalleryid = intval( $gallery );
$verifiedGalleryLen = strlen( $checkgalleryid );
if ( $galleryLen == $verifiedGalleryLen ) {
if($jet_data['JE'][$dkey]['type'] == 'media'){
$media_ids .= $gallery. ',';
}
else{
$gallery_ids .= $gallery. ',';
}
}
}
$indexs++;
}
if(is_array($gallery_ids)){
$gallery_id = $gallery_ids;
}
if (!is_array($gallery_ids)) {
$gallery_id = rtrim($gallery_ids,',');
}
if($jet_data['JE'][$dkey]['value_format'] == 'url'){
global $wpdb;
$media_id = $media_instance->media_handling( $dvalue, $pID);
$get_media_fields = $wpdb->get_results("select meta_value from {$wpdb->prefix}postmeta where post_id=$media_id and meta_key ='_wp_attached_file'");
$dir = wp_upload_dir();
//$media_id = $dir ['baseurl'] . '/' .$get_media_fields[0]->meta_value;
if(!empty($get_media_fields[0]->meta_value)){
$media_id = $dir ['baseurl'] . '/' .$get_media_fields[0]->meta_value;
}
else{
$media_id='';
}
}
elseif($jet_data['JE'][$dkey]['value_format'] == 'both'){
global $wpdb;
$media_id = $media_instance->media_handling( $dvalue, $pID);
$media_ids1['id']=$media_id;
$get_media_fields = $wpdb->get_results("select meta_value from {$wpdb->prefix}postmeta where post_id=$media_id and meta_key ='_wp_attached_file'");
$dir = wp_upload_dir();
if(!empty($get_media_fields[0]->meta_value)){
$media_ids2['url'] = $dir ['baseurl'] . '/' .$get_media_fields[0]->meta_value;
}
else{
$media_ids2['url']='';
}
$mediavalue= array_merge($media_ids1,$media_ids2);
$media_id=array($mediavalue);
}
else{
if(is_string($dvalue)) //Find image url or id
$media_id = $media_instance->media_handling( $dvalue, $pID);
else
$media_id = $dvalue;
}
if($jet_data['JE'][$dkey]['type'] == 'media'){
$darray[$jet_data['JE'][$dkey]['name']] = $media_id;
}
else{
$darray[$jet_data['JE'][$dkey]['name']] = $gallery_id;
}
}
elseif($jet_data['JE'][$dkey]['type'] == 'datetime-local'){
$dateformat = 'Y-m-d\TH:m';
if(!empty($dvalue)){
$dt_var = trim($dvalue);
$datetime = str_replace('/', '-', "$dt_var");
if($jet_data['JE'][$dkey]['is_timestamp']){
if(is_numeric($datetime)){
$date_time_of = $datetime;
}
else{
$date_time_of = strtotime($datetime);
}
}else{
$date_time_of = $helpers_instance->validate_datefield($dt_var,$dkey,$dateformat,$line_number);
}
$darray[$jet_data['JE'][$dkey]['name']] = $date_time_of;
}
else{
$darray[$jet_data['JE'][$dkey]['name']] = '';
}
}
elseif($jet_data['JE'][$dkey]['type'] == 'date'){
$dateformat = 'Y-m-d';
if(!empty($dvalue)){
$var = trim($dvalue);
$date = str_replace('/', '-', "$var");
if($jet_data['JE'][$dkey]['is_timestamp']){
if(is_numeric($date)){
$date_of = $date;
}
else{
$date_of = strtotime($date);
}
}else{
$date_of = $helpers_instance->validate_datefield($var,$dkey,$dateformat,$line_number);
}
$darray[$jet_data['JE'][$dkey]['name']] = $date_of;
}
else{
$darray[$jet_data['JE'][$dkey]['name']] = '';
}
}
elseif ($jet_data['JE'][$dkey]['type'] == 'time') {
$var = trim($dvalue);
$time = date('H:i', strtotime($var));
if ($time == '00:00') {
$darray[$jet_data['JE'][$dkey]['name']] = ''; // Set empty value
} else {
$darray[$jet_data['JE'][$dkey]['name']] = $time;
}
}
elseif($jet_data['JE'][$dkey]['type'] == 'checkbox'){
if($jet_data['JE'][$dkey]['is_array'] == 1){
$arr = explode(',' , $dvalue);
$darray[$jet_data['JE'][$dkey]['name']] = $arr;
}
else{
$options = $jet_data['JE'][$dkey]['options'];
$arr = [];
$opt = [];
$dvalexp = explode(',' , $dvalue);
foreach($options as $option_key => $option_val){
$arr[$option_val['key']] = 'false';
}
foreach($dvalexp as $dvalkey => $dvalueval){
$dvalueval = trim($dvalueval);
$keys = array_keys($arr);
foreach($keys as $keys1){
if($dvalueval == $keys1){
$arr[$keys1] = 'true';
}
}
//added new checkbox values
if(!in_array($dvalueval, $keys)){
//$get_meta_fields = $wpdb->get_results("SELECT id, meta_fields FROM {$wpdb->prefix}jet_post_types WHERE slug = '$type' AND status IN ('publish','built-in')");
$get_meta_fields = $wpdb->get_results( $wpdb->prepare("SELECT option_value FROM {$wpdb->prefix}options WHERE option_name=%s",'jet_engine_meta_boxes'));
if(isset($get_meta_fields[0])){
$unserialized_meta = maybe_unserialize($get_meta_fields[0]->option_value);
if(!empty($unserialized_meta)){
foreach($unserialized_meta as $jet_keys => $jet_values){
foreach($jet_values['meta_fields'] as $meta_keys => $meta_values){
$count_jetvalues = 0;
if($meta_values['type'] == 'checkbox' && $meta_values['name'] == $dkey){
$count_jetvalues = count($meta_values['options']);
$unserialized_meta[$jet_keys]['meta_fields'][$meta_keys]['options'][$count_jetvalues]['key'] = $dvalueval;
$unserialized_meta[$jet_keys]['meta_fields'][$meta_keys]['options'][$count_jetvalues]['value'] = $dvalueval;
$unserialized_meta[$jet_keys]['meta_fields'][$meta_keys]['options'][$count_jetvalues]['id'] = $meta_values['options'][$count_jetvalues - 1]['id'] + 1;
}
}
}
update_option('jet_engine_meta_boxes', $unserialized_meta);
$arr[$dvalueval] = 'true';
}
}
}
}
$darray[$jet_data['JE'][$dkey]['name']] = $arr;
}
}
elseif($jet_data['JE'][$dkey]['type'] == 'select'){
$dselect = [];
if($jet_data['JE'][$dkey]['is_multiple'] == 0 || empty($jet_data['JE'][$dkey]['is_multiple'])){
$darray[$jet_data['JE'][$dkey]['name']] = $dvalue;
}
else{
$exp = explode(',',$dvalue);
foreach($exp as $exp_values){
$dselect[] = trim($exp_values);
}
//$dselect = $exp;
$darray[$jet_data['JE'][$dkey]['name']] = $dselect;
}
}
elseif($jet_data['JE'][$dkey]['type'] == 'posts'){
global $wpdb;
if($jet_data['JE'][$dkey]['is_multiple'] == 0){
$jet_posts = trim($dvalue);
//$jet_posts = $wpdb->_real_escape($jet_posts);
if(is_numeric($jet_posts)){
$jet_posts_field_value = $jet_posts;
}
else{
$query = "SELECT id FROM {$wpdb->prefix}posts WHERE post_title ='{$jet_posts}' AND post_status='publish'";
$name = $wpdb->get_results($query);
if (!empty($name)) {
$jet_posts_field_value = $name[0]->id;
}
}
}
else{
$jet_posts_exp = explode(',',trim($dvalue));
$jet_posts_value = array();
foreach($jet_posts_exp as $jet_posts_value){
$jet_posts_value = trim($jet_posts_value);
$query = "SELECT id FROM {$wpdb->prefix}posts WHERE post_title ='{$jet_posts_value}' AND post_status = 'publish' ORDER BY ID DESC";
$multiple_id = $wpdb->get_results($query);
$multiple_ids =$multiple_id[0];
if(!$multiple_id){
$jet_posts_field_value[]=$jet_posts_value;
}
else{
$jet_posts_field_value[]=trim($multiple_ids->id);
}
}
}
$darray[$jet_data['JE'][$dkey]['name']] = $jet_posts_field_value;
}
else{
if($jet_data['JE'][$dkey]['type'] != 'repeater'){
$darray[$jet_data['JE'][$dkey]['name']] = $dvalue;
}
}
$listTaxonomy = get_taxonomies();
if($darray){
if($type == 'Users'){
foreach($darray as $mkey => $mval){
update_user_meta($pID, $mkey, $mval);
}
}
elseif(in_array($type, $listTaxonomy)){
foreach($darray as $mkey => $mval){
update_term_meta($pID, $mkey, $mval);
}
}
else{
foreach($darray as $mkey => $mval){
update_post_meta($pID, $mkey, $mval);
}
}
}
}
}
}
public function JetEngineFields($type){
global $wpdb;
$jet_field = array();
$get_meta_box_fields = $wpdb->get_results( $wpdb->prepare("SELECT option_value FROM {$wpdb->prefix}options WHERE option_name=%s",'jet_engine_meta_boxes'));
$unserialized_meta = maybe_unserialize($get_meta_box_fields[0]->option_value);
$arraykeys = array_keys($unserialized_meta);
foreach($arraykeys as $val){
$values = explode('-',$val);
$v = $values[1];
}
for($i=1 ; $i<=$v ; $i++){
$meta['meta_fields'] = isset($unserialized_meta['meta-'.$i]['meta_fields']) ? $unserialized_meta['meta-'.$i]['meta_fields'] : '';
$fields = $meta['meta_fields'];
if(!empty($fields)){
foreach($fields as $jet_key => $jet_value){
$customFields["JE"][ $jet_value['name']]['label'] = $jet_value['title'];
$customFields["JE"][ $jet_value['name']]['name'] = $jet_value['name'];
$customFields["JE"][ $jet_value['name']]['type'] = $jet_value['type'];
$customFields["JE"][ $jet_value['name']]['options'] = isset($jet_value['options']) ? $jet_value['options'] : '';
$customFields["JE"][ $jet_value['name']]['is_multiple'] = isset($jet_value['is_multiple']) ? $jet_value['is_multiple'] : ' ' ;
$customFields["JE"][ $jet_value['name']]['value_format'] = isset($jet_value['value_format']) ? $jet_value['value_format'] : '';
$customFields["JE"][ $jet_value['name']]['is_array'] = isset($jet_value['is_array']) ? $jet_value['is_array'] : '';
if($jet_value['type'] == 'date' || $jet_value['type'] == 'datetime-local'){
$customFields["JE"][ $jet_value['name']]['is_timestamp'] = isset($jet_value['is_timestamp']) ? $jet_value['is_timestamp'] : '';
}
}
}
}
return $customFields;
}
}

View File

@@ -0,0 +1,469 @@
<?php
/******************************************************************************************
* Copyright (C) Smackcoders. - All Rights Reserved under Smackcoders Proprietary License
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* You can contact Smackcoders at email address info@smackcoders.com.
*******************************************************************************************/
namespace Smackcoders\FCSV;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class JetEngineRELImport {
private static $instance = null;
public static function getInstance() {
if (JetEngineRELImport::$instance == null) {
JetEngineRELImport::$instance = new JetEngineRELImport;
}
return JetEngineRELImport::$instance;
}
function set_jet_engine_rel_values($header_array ,$value_array , $map, $post_id , $type , $mode, $hash_key, $line_number,$gmode,$templatekey = null){
$post_values = [];
$helpers_instance = ImportHelpers::getInstance();
$post_values = $helpers_instance->get_header_values($map , $header_array , $value_array);
$get_plugins_list = get_plugins();
$get_jetengine_plugin_version = $get_plugins_list['jet-engine/jet-engine.php']['Version'];
if($get_jetengine_plugin_version >= '2.11.4'){
$this->jet_engine_rel_import_function_new($post_values,$type, $post_id, $mode, $hash_key, $line_number,$gmode,$templatekey);
}
else{
$this->jet_engine_rel_import_function($post_values,$type, $post_id, $mode, $hash_key,$gmode,$templatekey);
}
}
public function jet_engine_rel_import_function($data_array, $type, $pID ,$mode, $hash_key,$gmode,$templatekey)
{
// $media_instance = MediaHandling::getInstance();
// $jet_data = $this->JetEngineFields($type);
global $wpdb;
$meta_key_exp = explode('|',$data_array['jet_relation_metakey']);
$meta_values_exp = explode('|',$data_array['jet_related_post']);
$count = count($meta_key_exp);
if(!empty($meta_key_exp[0])){
foreach($meta_key_exp as $metkey){
if($mode != 'Insert'){
$query = "SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE meta_key ='{$metkey}' and post_id = '{$pID}' ";
$get_metavalue = $wpdb->get_results($query);
foreach($get_metavalue as $metval){
$metaid = $metval->meta_value;
delete_post_meta($metaid,$metkey);
}
delete_post_meta($pID,$metkey);
}
}
for($i=0 ;$i<$count ; $i++){
$meta_keys = $meta_key_exp[$i];
$meta_values = $meta_values_exp[$i];
$metaval = explode(',',$meta_values);
$val_count = count($metaval);
foreach($metaval as $metakeyval => $metavalues){
$rmeta_keys = rtrim($meta_keys,' ');
$metavalues = trim($metavalues);
if(is_numeric($metavalues)){
if($count > 1){
add_post_meta($pID,$rmeta_keys,$metavalues);
add_post_meta($metavalues,$meta_keys,$pID);
}
else{
update_post_meta($pID,$rmeta_keys,$metavalues);
update_post_meta($metavalues,$meta_keys,$pID);
}
}
else{
$query = "SELECT id FROM {$wpdb->prefix}posts WHERE post_title ='{$metavalues}' and post_status = 'publish' ORDER BY ID DESC";
$get_id = $wpdb->get_results($query);
$getids = $get_id[0];
$meta_valueid = $getids->id;
add_post_meta($pID,$rmeta_keys,$meta_valueid);
add_post_meta($meta_valueid,$meta_keys,$pID);
}
}
}
}
}
public function jet_engine_rel_import_function_new($data_array, $type, $pID ,$mode, $hash_key, $line_number,$gmode,$templatekey) {
global $wpdb;
$helpers_instance = ImportHelpers::getInstance();
$extension_object = new ExtensionHandler;
$import_type = $extension_object->import_post_types($type );
if($import_type == 'WooCommerce Product'){
$import_type = 'product';
}
$relation_fields = [];
$relation_meta = [];
foreach($data_array as $data_key => $data_value){
if(strpos($data_key, 'jet_related_post') !== false){
if(!empty($data_value)){
$get_relation_id = explode(' :: ', $data_key);
$relation_id = $get_relation_id[1];
$get_related_objects = $this->get_relation_objects($relation_id, $import_type, $pID, 'args',$mode);
$parent_object_id = $get_related_objects['parent_object'];
$child_object_id = $get_related_objects['child_object'];
$relation_type = $get_related_objects['relation_type'];
$connection_type = $get_related_objects['connected_type'];
$connection_object = $get_related_objects['connected_object'];
$get_relate_db_table = $get_related_objects['get_relation_db_table'];
$relation_post_meta = [];
$get_related_posts_data = explode('|', $data_value);
$get_related_posts = array_map('trim', $get_related_posts_data);
$get_related_posts = array_unique($get_related_posts);
if($relation_type == 'one'){
foreach($get_related_posts as $related_posts){
$related_posts = trim($related_posts);
if(is_numeric($related_posts)){
if($connection_type == 'posts'){
$get_related_post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->prefix}posts WHERE ID = $related_posts AND post_status = 'publish' AND post_type = '$connection_object'");
}
elseif($connection_type == 'users'){
$get_related_post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->prefix}users WHERE ID = $related_posts");
}
elseif($connection_type == 'terms'){
$get_related_post_id = $wpdb->get_var("SELECT term_id FROM {$wpdb->prefix}terms WHERE name = $related_posts");
}
}
else{
if($connection_type == 'posts'){
$get_related_post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->prefix}posts WHERE post_title = \"$related_posts\" AND post_status = 'publish' AND post_type = '$connection_object' ORDER BY ID DESC");
}
elseif($connection_type == 'users'){
$get_related_post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->prefix}users WHERE user_login = '$related_posts'");
}
elseif($connection_type == 'terms'){
$get_related_post_id = $wpdb->get_var("SELECT term_id FROM {$wpdb->prefix}terms WHERE name = '$related_posts'");
}
}
if(!empty($get_related_post_id)){
if(!empty($parent_object_id)){
if($relation_type == 'one') {
$this->delete_rel($get_related_post_id,'child',$relation_id,$get_relate_db_table);
}
$child_object_id1 = $get_related_post_id;
$parent_object_id1 = $parent_object_id;
}
else{
if($relation_type == 'one') {
$this->delete_rel($get_related_post_id,'parent',$relation_id,$get_relate_db_table);
}
$parent_object_id1 = $get_related_post_id;
$child_object_id1 = $child_object_id;
}
$current_time = current_time('Y-m-d H:i:s');
$jet_rel_default_table = $wpdb->prefix . 'jet_rel_default';
$table_exists = $wpdb->query("SHOW TABLES LIKE '$jet_rel_default_table'");
if ($table_exists) {
$wpdb->insert($jet_rel_default_table, array('created' => $current_time, 'rel_id' => $relation_id, 'parent_rel' => 0, 'parent_object_id' => $parent_object_id1, 'child_object_id' => $child_object_id1));
}
$jet_rel_default_db_table = $wpdb->prefix . 'jet_rel_'.$relation_id;
if($get_relate_db_table == 1){
$get_id = $wpdb->get_results("SELECT _ID FROM $jet_rel_default_db_table WHERE rel_id = '$relation_id' AND parent_object_id = '$parent_object_id1' AND child_object_id = '$child_object_id1'");
$get_default_id = !empty($get_id) ? $get_id[0]->_ID : "";
if(empty($get_default_id)){
$wpdb->insert($jet_rel_default_db_table, array('created' => $current_time, 'rel_id' => $relation_id, 'parent_rel' => 0, 'parent_object_id' => $parent_object_id1, 'child_object_id' => $child_object_id1));
}
}
$last_id = $wpdb->insert_id;
$relation_post_meta[] = $last_id;
if($relation_type == 'one'){
break;
}
}
}
$relation_meta[$relation_id] = $relation_post_meta;
}}
}
else{
$relation_fields[$data_key] = $data_value;
}
}
$current_time = current_time('Y-m-d H:i:s');
if(!empty($relation_fields)){
foreach($relation_fields as $relation_field_key => $relation_field_value){
$get_relation_name = explode(' :: ', $relation_field_key);
$get_relation_field_values = explode('|', $relation_field_value);
$field_name = $get_relation_name[0];
$get_field_relation_id = $get_relation_name[1];
$get_related_metafields_objects = $this->get_relation_objects($get_field_relation_id, $import_type, $pID, 'metafields',$mode);
$relation_meta_fields = $get_related_metafields_objects['meta_fields'];
$get_relation_db_table = $get_related_metafields_objects['get_relation_db_table'];
if($get_relation_db_table == 1){
$jet_rel_table = $wpdb->prefix . 'jet_rel_' . $get_field_relation_id;
$jet_rel_default_meta_table = $wpdb->prefix . 'jet_rel_' . $get_field_relation_id . '_meta';
}
else{
$jet_rel_table = $wpdb->prefix . 'jet_rel_default';
$jet_rel_default_meta_table = $wpdb->prefix . 'jet_rel_default_meta';
}
if(array_key_exists('type',$get_related_metafields_objects))
$relation_type = $get_related_metafields_objects['type'];
if(!empty($relation_meta)) {
$get_inserted_rel_details = array_key_exists($get_field_relation_id,$relation_meta) ? $relation_meta[$get_field_relation_id] : [];
foreach($get_inserted_rel_details as $inserted_key => $inserted_values){
$relation_field_values = isset($get_relation_field_values[$inserted_key]) ? $get_relation_field_values[$inserted_key] : '';
if(!empty($relation_field_values)){
$inserted_parent_id = $wpdb->get_var("SELECT parent_object_id FROM $jet_rel_table WHERE _ID = $inserted_values");
$inserted_child_id = $wpdb->get_var("SELECT child_object_id FROM $jet_rel_table WHERE _ID = $inserted_values");
if( strpos($relation_field_values, ',') !== false) {
$relation_field_values_exp = explode(',', $relation_field_values);
$result_relation_field_values = array_map('trim', $relation_field_values_exp);
$serialize_relation_field_values = serialize($result_relation_field_values);
$wpdb->insert($jet_rel_default_meta_table, array('created' => $current_time, 'rel_id' => $get_field_relation_id, 'parent_object_id' => $inserted_parent_id, 'child_object_id' => $inserted_child_id, 'meta_key' => $field_name, 'meta_value' => $serialize_relation_field_values));
}
else{
if($relation_meta_fields[$field_name] == 'date'){
$dateformat = 'Y-m-d';
$relation_field_metavalues = $helpers_instance->validate_datefield($relation_field_values, $field_name, $dateformat, $line_number);
}
elseif($relation_meta_fields[$field_name] == 'datetime-local'){
$dateformat = 'Y-m-dTH:i';
$relation_field_metavalues = $helpers_instance->validate_datefield($relation_field_values, $field_name, $dateformat, $line_number);
}
elseif(strpos($relation_meta_fields[$field_name][0], 'select') !== false){
if(is_array($relation_type) && $relation_type[$field_name.'type'][0] == 1){
$relation_field_values_exp = explode(',', $relation_field_values);
$result_relation_field_values = array_map('trim', $relation_field_values_exp);
$relation_field_metavalues = serialize($result_relation_field_values);
}
else{
$relation_field_metavalues = $relation_field_values;
}
}
// elseif(strpos($relation_meta_fields[$field_name][0], 'media') !== false){
// $exp_image = explode(',', $relation_meta_fields[$field_name][0]);
// if(array_key_exists(1,$exp_image))
// $image_format = $exp_image[1];
// else
// $image_format = "id";
// $relation_field_metavalues = $this->get_related_image_id($relation_field_values, $image_format, $pID);
// if(is_array($relation_field_metavalues) && array_key_exists('0',$relation_field_metavalues)){
// $relation_field_metavalues = serialize($relation_field_metavalues[0]);//Media type is in both
// }
// }
else{
$relation_field_metavalues = $relation_field_values;
}
$wpdb->insert($jet_rel_default_meta_table, array('created' => $current_time, 'rel_id' => $get_field_relation_id, 'parent_object_id' => $inserted_parent_id, 'child_object_id' => $inserted_child_id, 'meta_key' => $field_name, 'meta_value' => $relation_field_metavalues));
}
}
}
}
}
}
}
public function get_relation_objects($relation_id, $import_type, $pID, $fetch,$mode){
global $wpdb;
if($fetch == 'args'){
//to get parent and child object for the given relation
$get_relation_objects = $wpdb->get_var("SELECT args FROM {$wpdb->prefix}jet_post_types WHERE id = $relation_id");
$get_relation_objects = maybe_unserialize($get_relation_objects);
$get_rel_parent_value = $get_relation_objects['parent_object'];
$get_rel_child_value = $get_relation_objects['child_object'];
$get_relation_types = $get_relation_objects['type'];
$get_relation_db_table_name = $get_relation_objects['db_table'];
$get_rel_parent = explode('::', $get_rel_parent_value);
$relation_parent_object = $get_rel_parent[1];
$get_rel_child = explode('::', $get_rel_child_value);
$relation_child_object = $get_rel_child[1];
$exp_relation_types = explode('_to_', $get_relation_types);
if($import_type == 'user'){
$import_type = 'users';
}
if($import_type == $relation_parent_object){
$parent_object_id = $pID;
$child_object_id = '';
$get_relation_type = $exp_relation_types[1];
$connected_type = $get_rel_child[0];
$connected_object = $relation_child_object;
if($mode != 'Insert'){
$this->delete_rel($pID,'parent',$relation_id,$get_relation_db_table_name);
}
}
elseif($import_type == $relation_child_object){
$parent_object_id = '';
$child_object_id = $pID;
$get_relation_type = $exp_relation_types[1];
$connected_type = $get_rel_parent[0];
$connected_object = $relation_parent_object;
if($get_relation_type == 'one') {
$this->delete_rel($pID,'parent',$relation_id,$get_relation_db_table_name);
}
if($mode != 'Insert'){
$this->delete_rel($pID,'child',$relation_id,$get_relation_db_table_name);
}
}
elseif($relation_child_object == 'product'){
$parent_object_id = '';
$child_object_id = $pID;
$get_relation_type = $exp_relation_types[1];
$connected_type = $get_rel_parent[0];
$connected_object = $relation_parent_object;
if($get_relation_type == 'one') {
$this->delete_rel($pID,'parent',$relation_id,$get_relation_db_table_name);
}
if($mode != 'Insert'){
$this->delete_rel($pID,'child',$relation_id,$get_relation_db_table_name);
}
}
if($connected_type == 'mix'){
$connected_type = 'users';
}
$response['parent_object'] = $parent_object_id;
$response['child_object'] = $child_object_id;
$response['relation_type'] = $get_relation_type;
$response['connected_type'] = $connected_type;
$response['connected_object'] = $connected_object;
$response['get_relation_db_table'] = $get_relation_db_table_name;
return $response;
}
elseif($fetch == 'metafields'){
//get meta fields for the given relation
$get_relation_metafields = $wpdb->get_var("SELECT meta_fields FROM {$wpdb->prefix}jet_post_types WHERE id = $relation_id");
$get_relation_metafields = maybe_unserialize($get_relation_metafields);
$jetengine_relation_metafields_array = [];
$jetengine_relation_type_array = [];
foreach($get_relation_metafields as $get_relation_metafield_values){
if($get_relation_metafield_values['type'] == 'media' && isset($get_relation_metafield_values['value_format'])){
$jetengine_relation_metafields_array[$get_relation_metafield_values['name']][] = $get_relation_metafield_values['type'] .','. $get_relation_metafield_values['value_format'];
}
elseif($get_relation_metafield_values['type'] == 'select'){
$jetengine_relation_metafields_array[$get_relation_metafield_values['name']][] = $get_relation_metafield_values['type'];
if(array_key_exists('is_multiple',$get_relation_metafield_values)){
$jetengine_relation_type_array[$get_relation_metafield_values['name'].'type'] []= $get_relation_metafield_values['is_multiple'];
$response['type'] = $jetengine_relation_type_array;
}
}
else{
$jetengine_relation_metafields_array[$get_relation_metafield_values['name']][] = $get_relation_metafield_values['type'];
}
}
$response['meta_fields'] = $jetengine_relation_metafields_array;
//get db structure
$get_relation_objects = $wpdb->get_var("SELECT args FROM {$wpdb->prefix}jet_post_types WHERE id = $relation_id");
$get_relation_objects = maybe_unserialize($get_relation_objects);
$response['get_relation_db_table'] = $get_relation_objects['db_table'];
return $response;
}
}
// public function get_related_image_id($image, $image_format, $pID){
// global $wpdb;
// $media_instance = MediaHandling::getInstance();
// $media_id = $media_instance->media_handling( $image, $pID);
// if($image_format == 'url'){
// $get_media_fields = $wpdb->get_results("select meta_value from {$wpdb->prefix}postmeta where post_id = $media_id and meta_key ='_wp_attached_file'");
// $dir = wp_upload_dir();
// if(!empty($get_media_fields[0]->meta_value)){
// $media_id = $dir ['baseurl'] . '/' .$get_media_fields[0]->meta_value;
// }
// else{
// $media_id='';
// }
// }
// elseif($image_format == 'both'){
// $media_ids1['id'] = $media_id;
// $get_media_fields = $wpdb->get_results("select meta_value from {$wpdb->prefix}postmeta where post_id = $media_id and meta_key ='_wp_attached_file'");
// $dir = wp_upload_dir();
// if(!empty($get_media_fields[0]->meta_value)){
// $media_ids2['url'] = $dir ['baseurl'] . '/' .$get_media_fields[0]->meta_value;
// }
// else{
// $media_ids2['url']='';
// }
// $mediavalue= array_merge($media_ids1,$media_ids2);
// $media_id = array($mediavalue);
// }
// else{
// $media_id = $media_id;
// }
// return $media_id;
// }
public function delete_rel($id,$type,$relation_id,$table){
global $wpdb;
if($table == 1){
$jet_rel_table = $wpdb->prefix . 'jet_rel_'.$relation_id;
$jet_rel_meta_table = $wpdb->prefix . 'jet_rel_'.$relation_id. '_meta';
}
else{
$jet_rel_table = $wpdb->prefix . 'jet_rel_default';
$jet_rel_meta_table = $wpdb->prefix . 'jet_rel_default_meta';
}
if($type == 'parent'){
$obj = "parent_object_id";
}
else {
$obj = "child_object_id";
}
$get_id = $wpdb->get_results("SELECT _ID FROM $jet_rel_table WHERE rel_id = '$relation_id' AND $obj = '$id'",ARRAY_A);
if(!empty($get_id)){
foreach($get_id as $rid){
$wpdb->delete($jet_rel_table, array('_ID' => $rid["_ID"]));
}
}
$get_meta_id = $wpdb->get_results("SELECT _ID FROM $jet_rel_meta_table WHERE rel_id = '$relation_id' AND $obj = '$id'",ARRAY_A);
if(!empty($get_meta_id)){
foreach($get_meta_id as $rmetaid){
$wpdb->delete($jet_rel_meta_table,array('_ID' => $rmetaid["_ID"]));
}
}
}
}

View File

@@ -0,0 +1,111 @@
<?php
/**
* WP Ultimate CSV Importer plugin file.
*
* Copyright (C) 2010-2020, Smackcoders Inc - info@smackcoders.com
*/
namespace Smackcoders\FCSV;
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly
}
class JetReviewsImport
{
private static $instance = null, $media_instance;
public static function getInstance()
{
if (JetReviewsImport::$instance == null) {
JetReviewsImport::$instance = new JetReviewsImport;
JetReviewsImport::$media_instance = MediaHandling::getInstance();
}
return JetReviewsImport::$instance;
}
function set_jet_reviews_values($post_values , $mode ,$unikey , $unikey_name, $line_number,$update_based_on,$check)
{
global $wpdb,$core_instance;
$helpers_instance = ImportHelpers::getInstance();
$core_instance = CoreFieldsImport::getInstance();
$log_table_name = $wpdb->prefix . "import_detail_log";
$updated_row_counts = $helpers_instance->update_count($unikey, $unikey_name);
$created_count = $updated_row_counts['created'];
$updated_count = $updated_row_counts['updated'];
$skipped_count = $updated_row_counts['skipped'];
if ($mode == 'Insert' && !empty($post_values)) {
$result = $this->insert_jet_reviews_data($post_values, $wpdb, $core_instance, $helpers_instance, $created_count, $updated_count, $skipped_count, $log_table_name, $mode, $unikey, $unikey_name, $line_number, $update_based_on, $check);
} else if ($mode == 'Update' && !empty($post_values)) {
$result = $this->update_jet_reviews_data($post_values, $wpdb, $core_instance, $helpers_instance, $created_count, $updated_count, $skipped_count, $log_table_name, $mode, $unikey, $unikey_name, $line_number, $update_based_on, $check);
}
return $result;
}
public function insert_jet_reviews_data($data_array, $wpdb, $core_instance, $helpers_instance, $created_count, $updated_count, $skipped_count, $log_table_name, $mode, $unikey, $unikey_name, $line_number, $update_based_on, $check)
{
if (isset($data_array['ID'])) {
unset($data_array['ID']);
}
$table_name = jet_reviews()->db->tables( 'reviews', 'name' );
$query = jet_reviews()->db->wpdb()->insert( $table_name, $data_array );
if ( ! $query ) {
$wpdb = jet_reviews()->db->wpdb();
$error_message = $wpdb->last_error;
$core_instance->detailed_log[$line_number]['Message'] = ' Skipped ' .$error_message;
$core_instance->detailed_log[$line_number]['state'] = 'Skipped';
$wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey'");
return array('MODE' => $mode, 'ERROR_MSG' => 'No data to update');
}
$review_id = jet_reviews()->db->wpdb()->insert_id; //Inserted
$mode_of_affect = 'Inserted';
$core_instance->detailed_log[$line_number]['state'] = 'Inserted';
$wpdb->get_results("UPDATE $log_table_name SET created = $created_count WHERE $unikey_name = '$unikey'");
$returnArr['ID'] = $review_id;
$returnArr['MODE'] = $mode_of_affect;
return $returnArr;
}
public function update_jet_reviews_data($data_array, $wpdb, $core_instance, $helpers_instance, $created_count, $updated_count, $skipped_count, $log_table_name, $mode, $unikey, $unikey_name, $line_number, $update_based_on, $check)
{
$review_id = $data_array['ID'];
if (isset($data_array['ID'])) {
unset($data_array['ID']);
}
$table_name = jet_reviews()->db->tables( 'reviews', 'name' );
$existing_entry = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$table_name} WHERE id = %d",$review_id));
/**Update */
if(!empty( $review_id ) && $existing_entry > 0){
$table_name = jet_reviews()->db->tables( 'reviews', 'name' );
$query = jet_reviews()->db->wpdb()->update(
$table_name,
$data_array,
array(
'id' => $review_id,
)
);
$mode_of_affect = 'Updated';
$core_instance->detailed_log[$line_number]['state'] = 'Updated';
$wpdb->get_results("UPDATE $log_table_name SET updated = $updated_count WHERE $unikey_name = '$unikey'");
$returnArr['ID'] = $review_id;
$returnArr['MODE'] = $mode_of_affect;
return $returnArr;
}
/**Insert */
else{
$query = jet_reviews()->db->wpdb()->insert( $table_name, $data_array );
$review_id = jet_reviews()->db->wpdb()->insert_id;
$mode_of_affect = 'Inserted';
$core_instance->detailed_log[$line_number]['state'] = 'Inserted';
$wpdb->get_results("UPDATE $log_table_name SET created = $created_count WHERE $unikey_name = '$unikey'");
$returnArr['ID'] = $review_id;
$returnArr['MODE'] = $mode_of_affect;
return $returnArr;
}
}
}

View File

@@ -0,0 +1,42 @@
<?php
/**
* WP Ultimate CSV Importer plugin file.
*
* Copyright (C) 2010-2020, Smackcoders Inc - info@smackcoders.com
*/
namespace Smackcoders\FCSV;
if (!defined('ABSPATH')) exit; // Exit if accessed directly
class JobListingImport
{
private static $job_listing_instance = null;
public static function getInstance()
{
if (JobListingImport::$job_listing_instance == null)
{
JobListingImport::$job_listing_instance = new JobListingImport;
return JobListingImport::$job_listing_instance;
}
return JobListingImport::$job_listing_instance;
}
public function set_job_listing_values($header_array, $value_array, $map, $post_id, $type)
{
$post_values = [];
$helpers_instance = ImportHelpers::getInstance();
$post_values = $helpers_instance->get_header_values($map, $header_array, $value_array);
$this->job_listing_import_function($post_values, $type, $post_id);
}
public function job_listing_import_function($data_array, $importas, $pID)
{
global $wpdb;
foreach($data_array as $data_key => $data_value){
update_post_meta($pID, '_'.$data_key, $data_value);
}
}
}

View File

@@ -0,0 +1,527 @@
<?php
/**
* WP Ultimate CSV Importer plugin file.
*
* Copyright (C) 2010-2020, Smackcoders Inc - info@smackcoders.com
*/
namespace Smackcoders\FCSV;
if (!defined('ABSPATH'))
exit; // Exit if accessed directly
class LearnPressImport
{
private static $learnpress_instance = null;
public static function getInstance()
{
if (LearnPressImport::$learnpress_instance == null) {
LearnPressImport::$learnpress_instance = new LearnPressImport;
return LearnPressImport::$learnpress_instance;
}
return LearnPressImport::$learnpress_instance;
}
public function set_learnpress_values($header_array, $value_array, $map, $post_id, $type){
$post_values = [];
$helpers_instance = ImportHelpers::getInstance();
$post_values = $helpers_instance->get_header_values($map, $header_array, $value_array);
$this->learnpress_values_import($post_values, $post_id, $type, $header_array ,$value_array);
}
public function learnpress_values_import($post_values, $post_id, $type, $header_array ,$value_array){
global $wpdb;
if($type == 'lp_course'){
if(isset($post_values['curriculum_name'])){
$get_curriculum_names = explode('|', $post_values['curriculum_name']);
if(isset($post_values['curriculum_description'])){
$get_curriculum_description = explode('|', $post_values['curriculum_description']);
}
if(isset($post_values['lesson_name'])){
$get_lesson_names = explode('|', $post_values['lesson_name']);
}
if(isset($post_values['lesson_description'])){
$get_lesson_description = explode('|', $post_values['lesson_description']);
}
if(isset($post_values['quiz_name'])){
$get_quiz_names = explode('|', $post_values['quiz_name']);
}
if(isset($post_values['quiz_description'])){
$get_quiz_description = explode('|', $post_values['quiz_description']);
}
$temp = 0;
foreach($get_curriculum_names as $curriculum_name){
$curriculums_description = isset($get_curriculum_description[$temp]) ? $get_curriculum_description[$temp] : '';
$wpdb->insert(
"{$wpdb->prefix}learnpress_sections",
array("section_name" => $curriculum_name, "section_course_id" => $post_id, "section_description" => $curriculums_description),
array('%s', '%d', '%s')
);
$inserted_section_id = $wpdb->insert_id;
if(isset($post_values['lesson_name'])){
$individual_lesson_names = explode(',', $get_lesson_names[$temp]);
if(isset($post_values['lesson_description'])){
$indivdual_lesson_description = explode(',', $get_lesson_description[$temp]);
}
$get_all_lesson_names = $wpdb->get_results("SELECT post_title FROM {$wpdb->prefix}posts WHERE post_type = 'lp_lesson' AND post_status = 'publish' ", ARRAY_A);
$all_lesson_names = array_column($get_all_lesson_names, 'post_title');
$i = 0;
foreach($individual_lesson_names as $lesson_name){
$lesson_names = trim($lesson_name);
if(in_array($lesson_names, $all_lesson_names)){
$lesson_post_id = $wpdb->get_var("SELECT ID from {$wpdb->prefix}posts WHERE post_title = '$lesson_names' and post_type = 'lp_lesson' ");
$check_assigned_to_course = $wpdb->get_var("SELECT section_id FROM {$wpdb->prefix}learnpress_section_items WHERE item_id = $lesson_post_id AND item_type = 'lp_lesson' ");
if(empty($check_assigned_to_course)){
LearnPressImport::$learnpress_instance->insert_lesson_details($inserted_section_id, $lesson_post_id, $post_values);
}
}else{
$lessons_description = isset($indivdual_lesson_description[$i]) ? $indivdual_lesson_description[$i] : '';
$lesson_array['post_title'] = $lesson_names;
$lesson_array['post_content'] = $lessons_description;
$lesson_array['post_type'] = 'lp_lesson';
$lesson_array['post_status'] = 'publish';
$lesson_post_id = wp_insert_post($lesson_array);
LearnPressImport::$learnpress_instance->insert_lesson_details($inserted_section_id, $lesson_post_id, $post_values);
}
$i++;
}
}
if(isset($post_values['quiz_name'])){
$individual_quiz_names = explode(',', $get_quiz_names[$temp]);
if(isset($post_values['quiz_description'])){
$individual_quiz_description = explode(',', $get_quiz_description[$temp]);
}
else{
$individual_quiz_description = [];
}
$get_all_quiz_names = $wpdb->get_results("SELECT post_title FROM {$wpdb->prefix}posts WHERE post_type = 'lp_quiz' AND post_status = 'publish' ", ARRAY_A);
$all_quiz_names = array_column($get_all_quiz_names, 'post_title');
$j = 0;
foreach($individual_quiz_names as $quiz_names){
if(in_array($quiz_names, $all_quiz_names)){
$quiz_post_id = $wpdb->get_var("SELECT ID from {$wpdb->prefix}posts WHERE post_title = '$quiz_names' and post_type = 'lp_quiz' ");
$check_assigned_to_course = $wpdb->get_var("SELECT section_id FROM {$wpdb->prefix}learnpress_section_items WHERE item_id = $quiz_post_id AND item_type = 'lp_quiz' ");
if(empty($check_assigned_to_course)){
LearnPressImport::$learnpress_instance->insert_quiz_details($type,$inserted_section_id, $quiz_post_id, $post_values);
}
}else{
$quizs_description = isset($individual_quiz_description[$j]) ? $individual_quiz_description[$j] : '';
$quiz_array['post_title'] = $quiz_names;
$quiz_array['post_content'] = $quizs_description;
$quiz_array['post_type'] = 'lp_quiz';
$quiz_array['post_status'] = 'publish';
$quiz_post_id = wp_insert_post($quiz_array);
LearnPressImport::$learnpress_instance->insert_quiz_details($type,$inserted_section_id, $quiz_post_id, $post_values);
}
$j++;
}
}
$temp++;
}
}
if(isset($post_values['_lp_requirements'])){
$lp_requi = $post_values['_lp_requirements'];
$lp_require = explode('|',$lp_requi);
$lp_requirements = $lp_require;
}
if(isset($post_values['_lp_target_audiences'])){
$lp_target = $post_values['_lp_target_audiences'];
$lp_target = explode('|',$lp_target);
$lp_target_audiences = $lp_target;
}
if(isset($post_values['_lp_key_features'])){
$lp_key_feature = $post_values['_lp_key_features'];
$lp_key = explode('|',$lp_key_feature);
$lp_key_features = $lp_key;
}
if(isset($post_values['_lp_faqs'])){
$lp_faqs = $post_values['_lp_faqs'];
$lp_faq = explode('|',$lp_faqs);
$lp_faq_value = array();
foreach($lp_faq as $lp_faq_values){
$lp_faq_value[] = explode(',',$lp_faq_values);
}
}
$course_setting_array = [];
$course_setting_array['_lp_duration'] = isset($post_values['_lp_duration']) ? $post_values['_lp_duration'] : '10 week';
$course_setting_array['_lp_max_students'] = isset($post_values['_lp_max_students']) ? $post_values['_lp_max_students'] : 1000;
$course_setting_array['_lp_students'] = isset($post_values['_lp_students']) ? $post_values['_lp_students'] : 0;
$course_setting_array['_lp_retake_count'] = isset($post_values['_lp_retake_count']) ? $post_values['_lp_retake_count'] : 0;
$course_setting_array['_lp_featured'] = isset($post_values['_lp_featured']) ? $post_values['_lp_featured'] : 'no';
$course_setting_array['_lp_block_lesson_content'] = isset($post_values['_lp_block_lesson_content']) ? $post_values['_lp_block_lesson_content'] : 'no';
$course_setting_array['_lp_external_link_buy_course'] = isset($post_values['_lp_external_link_buy_course']) ? $post_values['_lp_external_link_buy_course'] : '';
$course_setting_array['_lp_submission'] = isset($post_values['_lp_submission']) ? $post_values['_lp_submission'] : 'yes';
$course_setting_array['_lp_course_result'] = isset($post_values['_lp_course_result']) ? $post_values['_lp_course_result'] : 'evaluate_lesson';
$course_setting_array['_lp_passing_condition'] = isset($post_values['_lp_passing_condition']) ? $post_values['_lp_passing_condition'] : 80;
$course_setting_array['_lp_price'] = isset($post_values['_lp_price']) ? $post_values['_lp_price'] : 0;
$course_setting_array['_lp_sale_price'] = isset($post_values['_lp_sale_price']) ? $post_values['_lp_sale_price'] : 0;
$course_setting_array['_lp_required_enroll'] = isset($post_values['_lp_required_enroll']) ? $post_values['_lp_required_enroll'] : 'yes';
$course_setting_array['_lp_course_author'] = isset($post_values['_lp_course_author']) ? $post_values['_lp_course_author'] : 1;
$course_setting_array['_lp_block_expire_duration'] = isset($post_values['_lp_block_expire_duration']) ? $post_values['_lp_block_expire_duration'] : '';
$course_setting_array['_lp_allow_course_repurchase'] = isset($post_values['_lp_allow_course_repurchase']) ? $post_values['_lp_allow_course_repurchase'] : '';
$course_setting_array['_lp_block_finished'] = isset($post_values['_lp_block_finished']) ? $post_values['_lp_block_finished'] : '';
$course_setting_array['_lp_course_repurchase_option'] = isset($post_values['_lp_course_repurchase_option']) ? $post_values['_lp_course_repurchase_option'] : '';
$course_setting_array['_lp_level'] = isset($post_values['_lp_level']) ? $post_values['_lp_level'] : '';
$course_setting_array['_lp_has_finish'] = isset($post_values['_lp_has_finish']) ? $post_values['_lp_has_finish'] : '';
$course_setting_array['_lp_featured_review'] = isset($post_values['_lp_featured_review']) ? $post_values['_lp_featured_review'] : '';
$course_setting_array['_lp_no_required_enroll'] = isset($post_values['_lp_no_required_enroll']) ? $post_values['_lp_no_required_enroll'] : '';
$course_setting_array['_lp_requirements'] = isset($lp_requirements) ? $lp_requirements : '';
$course_setting_array['_lp_target_audiences'] = isset($lp_target_audiences) ? $lp_target_audiences : '';
$course_setting_array['_lp_key_features'] = isset($lp_key_features) ? $lp_key_features : '';
$course_setting_array['_lp_faqs'] = isset($lp_faq_value) ? $lp_faq_value : '';
$course_setting_array['_lp_course_status'] = 'publish';
foreach ($course_setting_array as $course_key => $course_value) {
update_post_meta($post_id, $course_key, $course_value);
}
}
if($type == 'lp_lesson' || $type == 'lp_quiz' || $type == 'lp_question'){
if(isset($post_values['course_id']) && $post_values['curriculum_name']){
$course_id = $post_values['course_id'];
$curriculum_name = $post_values['curriculum_name'];
$get_section_id = $wpdb->get_var("SELECT section_id FROM {$wpdb->prefix}learnpress_sections WHERE section_course_id = $course_id AND section_name = '$curriculum_name' ");
}
else{
$get_section_id = '';
}
if($type == 'lp_lesson'){
LearnPressImport::$learnpress_instance->insert_lesson_details($get_section_id, $post_id, $post_values);
}
if($type == 'lp_quiz'){
LearnPressImport::$learnpress_instance->insert_quiz_details($type,$get_section_id, $post_id, $post_values);
}
if($type == 'lp_question'){
LearnPressImport::$learnpress_instance->insert_question_details($type,$get_section_id, $post_id, $post_values, 0);
}
}
if($type == 'lp_order'){
LearnPressImport::$learnpress_instance->insert_order_details($post_id, $post_values);
}
}
public function insert_lesson_details($inserted_section_id, $lesson_post_id, $post_values){
global $wpdb;
if(isset($inserted_section_id)){
$wpdb->insert(
"{$wpdb->prefix}learnpress_section_items",
array("section_id" => $inserted_section_id, "item_id" => $lesson_post_id, "item_type" => 'lp_lesson'),
array('%d', '%d', '%s')
);
}
if(isset($post_values['_lp_lesson_duration'])){
update_post_meta($lesson_post_id, '_lp_duration', $post_values['_lp_lesson_duration']);
}
if(isset($post_values['_lp_preview'])){
update_post_meta($lesson_post_id, '_lp_preview', $post_values['_lp_preview']);
}
}
public function insert_quiz_details($type,$inserted_section_id, $quiz_post_id, $post_values){
global $wpdb;
if(!empty($inserted_section_id)){
$wpdb->insert(
"{$wpdb->prefix}learnpress_section_items",
array("section_id" => $inserted_section_id, "item_id" => $quiz_post_id, "item_type" => 'lp_quiz'),
array('%d', '%d', '%s')
);
}
$quiz_meta_array['_lp_duration'] = isset($post_values['_lp_duration']) ? $post_values['_lp_duration'] : '10 minute';
$quiz_meta_array['_lp_minus_points'] = isset($post_values['_lp_minus_points']) ? $post_values['_lp_minus_points'] : 0;
$quiz_meta_array['_lp_minus_skip_questions'] = isset($post_values['_lp_minus_skip_questions']) ? $post_values['_lp_minus_skip_questions'] : 'no';
$quiz_meta_array['_lp_passing_grade'] = isset($post_values['_lp_passing_grade']) ? $post_values['_lp_passing_grade'] : 80;
$quiz_meta_array['_lp_retake_count'] = isset($post_values['_lp_quiz_retake_count']) ? $post_values['_lp_quiz_retake_count'] : 0;
$quiz_meta_array['_lp_instant_check'] = isset($post_values['_lp_instant_check']) ? $post_values['_lp_instant_check'] : 'no';
$quiz_meta_array['_lp_negative_marking'] = isset($post_values['_lp_negative_marking']) ? $post_values['_lp_negative_marking'] : 'no';
$quiz_meta_array['_lp_pagination'] = isset($post_values['_lp_pagination']) ? $post_values['_lp_pagination'] : 1;
$quiz_meta_array['_lp_show_correct_review'] = isset($post_values['_lp_show_correct_review']) ? $post_values['_lp_show_correct_review'] : 'yes';
$quiz_meta_array['_lp_review'] = isset($post_values['_lp_review']) ? $post_values['_lp_review'] : 'yes';
foreach ($quiz_meta_array as $quiz_key => $quiz_value) {
update_post_meta($quiz_post_id, $quiz_key, $quiz_value);
}
if(isset($post_values['question_title'])){
$get_question_titles = explode(',', $post_values['question_title']);
$get_all_question_titles = $wpdb->get_results("SELECT post_title FROM {$wpdb->prefix}posts WHERE post_type = 'lp_question' AND post_status = 'publish' ", ARRAY_A);
$all_questions_title = array_column($get_all_question_titles, 'post_title');
$temp = 0;
foreach($get_question_titles as $question_titles){
if(in_array($question_titles, $all_questions_title)){
$question_post_id = $wpdb->get_var("SELECT ID from {$wpdb->prefix}posts WHERE post_title = '$question_titles' AND post_type = 'lp_question' AND post_status != 'trash' ");
$post_values['quiz_id'] = $quiz_post_id;
$check_assigned_to_quiz = $wpdb->get_var("SELECT quiz_question_id FROM {$wpdb->prefix}learnpress_quiz_questions WHERE question_id = $question_post_id ");
if(!empty($check_assigned_to_quiz)){
LearnPressImport::$learnpress_instance->insert_question_details($type,$inserted_section_id, $question_post_id, $post_values, $temp);
}
}else{
$get_question_description = explode(',', $post_values['question_description']);
foreach($get_question_description as $question_description){
$question_array['post_content'] = $question_description;
}
$question_array['post_title'] = $question_titles;
$question_array['post_type'] = 'lp_question';
$question_array['post_status'] = 'publish';
$question_post_id = wp_insert_post($question_array);
$post_values['quiz_id'] = $quiz_post_id;
LearnPressImport::$learnpress_instance->insert_question_details($type,$inserted_section_id, $question_post_id, $post_values, $temp);
}
$temp++;
}
}
}
public function insert_question_details($type,$inserted_section_id, $question_post_id, $post_values, $temp){
global $wpdb;
if(isset($post_values['_lp_mark'])){
$lp_question_mark = explode(',',$post_values['_lp_mark']);
}
if(isset($post_values['_lp_explanation'])){
$lp_question_explanation = explode(',',$post_values['_lp_explanation']);
}
if(isset($post_values['_lp_hint'])){
$lp_question_hint = explode(',',$post_values['_lp_hint']);
}
if(isset($post_values['_lp_type'])){
$lp_question_type = explode(',',$post_values['_lp_type']);
}
$question_meta_array['_lp_mark'] = isset($lp_question_mark[$temp]) ? $lp_question_mark[$temp] : 1;
$question_meta_array['_lp_explanation'] = isset($lp_question_explanation[$temp]) ? $lp_question_explanation[$temp] : NULL;
$question_meta_array['_lp_hint'] = isset($lp_question_hint[$temp]) ? $lp_question_hint[$temp] : NULL;
$question_meta_array['_lp_type'] = isset($lp_question_type[$temp]) ? $lp_question_type[$temp] : 'true_or_false';
foreach ($question_meta_array as $question_key => $question_value) {
update_post_meta($question_post_id, $question_key, $question_value);
}
if(isset($post_values['quiz_id'])){
$quiz_id = $post_values['quiz_id'];
$question_order = 1;
$get_question_order = $wpdb->get_var("SELECT question_order FROM {$wpdb->prefix}learnpress_quiz_questions WHERE quiz_id = $quiz_id ORDER BY quiz_question_id DESC LIMIT 1");
if(!empty($get_question_order)){
$question_order = $get_question_order + 1;
}
$wpdb->insert(
"{$wpdb->prefix}learnpress_quiz_questions",
array("quiz_id" => $quiz_id, "question_id" => $question_post_id, "question_order" => $question_order),
array('%d', '%d', '%d')
);
if(!empty($inserted_section_id)){
$check_assigned_to_course = $wpdb->get_var("SELECT section_item_id FROM {$wpdb->prefix}learnpress_section_items WHERE section_id = $inserted_section_id AND item_id = $quiz_id AND item_type = 'lp_quiz' ");
$check_assigned_to_another_course = $wpdb->get_var("SELECT section_id FROM {$wpdb->prefix}learnpress_section_items WHERE item_id = $quiz_id AND item_type = 'lp_quiz' ");
if(empty($check_assigned_to_course) && empty($check_assigned_to_another_course)){
$wpdb->insert(
"{$wpdb->prefix}learnpress_section_items",
array("section_id" => $inserted_section_id, "item_id" => $quiz_id, "item_type" => 'lp_quiz'),
array('%d', '%d', '%s')
);
}
}
}
if($type == 'lp_quiz'){
if(isset($post_values['question_options'])){
$get_separate_question_options = explode(',', $post_values['question_options']);
$get_question_titles = explode(',', $post_values['question_title']);
$i=0;
$get_separate_options =array();
foreach($get_separate_question_options as $get_separate_question_option){
$key=$get_question_titles[$i];
$get_separate_options[$key] = explode('->', $get_separate_question_option);
$i++;
}
foreach($get_separate_options as $option_key=> $option_values){
foreach($option_values as $option_value){
$post_type_values = $wpdb->get_results("SELECT post_title FROM {$wpdb->prefix}posts WHERE id = $question_post_id ", ARRAY_A);
$get_title_options_value = explode('|', $option_value);
if($option_key == $post_type_values[0]['post_title']){
$wpdb->insert(
"{$wpdb->prefix}learnpress_question_answers",
array("question_id" => $question_post_id, "title" => $get_title_options_value[0], "is_true"=>$get_title_options_value[1]),
array('%d', '%s','%s')
);
}
}
}
}
}
else{
if(isset($post_values['question_options'])){
$get_separate_options = explode('->', $post_values['question_options']);
foreach($get_separate_options as $option_values){
$get_title_options = explode('|', $option_values);
$wpdb->insert(
"{$wpdb->prefix}learnpress_question_answers",
array("question_id" => $question_post_id, "title" => $get_title_options[0], "is_true"=>$get_title_options[1]),
array('%d', '%s','%s')
);
}
}
}
}
public function insert_order_details($order_id, $post_values){
global $wpdb;
$order_key = strtoupper( uniqid( 'ORDER' ) );
$order_currency = get_option("_order_currency");
$order_meta_array = [];
if(isset($post_values['user_id'])){
$order_meta_array['_user_id'] = $post_values['user_id'];
}
else{
$order_meta_array['_user_id'] = get_current_user_id();
}
$order_meta_array['_order_currency'] = $order_currency;
$order_meta_array['_order_subtotal'] = isset($post_values['_order_subtotal']) ? $post_values['_order_subtotal'] : '';
$order_meta_array['_order_total'] = isset($post_values['_order_total']) ? $post_values['_order_total'] : '';
$order_meta_array['_prices_include_tax'] = 'no';
$order_meta_array['_payment_method'] = '';
$order_meta_array['_payment_method_title'] = '';
$order_meta_array['_order_key'] = $order_key;
$order_meta_array['_order_version'] = '3.0.0';
foreach($order_meta_array as $order_key => $order_value){
update_post_meta($order_id, $order_key, $order_value);
}
if(isset($post_values['item_id'])){
$order_item_ids = explode(',', $post_values['item_id']);
$order_item_quantity = explode(',', $post_values['item_quantity']);
$order_item_subtotal = explode(',', $post_values['_item_subtotal']);
$order_item_total = explode(',', $post_values['_item_total']);
$temp = 0;
foreach($order_item_ids as $order_item_id){
$order_name = $wpdb->get_var("SELECT post_title FROM {$wpdb->prefix}posts WHERE ID = $order_item_id ");
$wpdb->insert(
"{$wpdb->prefix}learnpress_order_items",
array("order_item_name" => $order_name, "order_id" => $order_id),
array('%s', '%d')
);
$lp_order_item_id = $wpdb->insert_id;
$order_item_meta_array = [];
$order_item_meta_array['_course_id'] = $order_item_id;
$order_item_meta_array['_quantity'] = $order_item_quantity[$temp];
$order_item_meta_array['_subtotal'] = $order_item_subtotal[$temp];
$order_item_meta_array['_total'] = $order_item_total[$temp];
foreach($order_item_meta_array as $order_item_meta_key => $order_item_meta_value){
if(empty($order_item_meta_value)){
$order_item_meta_value = 'NULL';
}
$wpdb->insert(
"{$wpdb->prefix}learnpress_order_itemmeta",
array("learnpress_order_item_id" => $lp_order_item_id, "meta_key" => $order_item_meta_key, "meta_value" => $order_item_meta_value),
array('%d', '%s', '%s')
);
}
$temp++;
}
}
}
public function learnpress_orders_import($data_array , $mode , $unikey_value,$unikey_name , $line_number){
$returnArr = array();
global $wpdb;
$helpers_instance = ImportHelpers::getInstance();
$core_instance = CoreFieldsImport::getInstance();
global $core_instance;
$log_table_name = $wpdb->prefix ."import_detail_log";
$updated_row_counts = $helpers_instance->update_count($unikey_value,$unikey_name);
$created_count = $updated_row_counts['created'];
$skipped_count = $updated_row_counts['skipped'];
$data_array['post_type'] = 'lp_order';
if(isset($data_array['order_status'])) {
$data_array['post_status'] = $data_array['order_status'];
}
/* Assign order date */
if(!isset( $data_array['order_date'] )) {
$data_array['post_date'] = current_time('Y-m-d H:i:s');
} else {
if(strtotime( $data_array['order_date'] )) {
$data_array['post_date'] = date( 'Y-m-d H:i:s', strtotime( $data_array['order_date'] ) );
} else {
$data_array['post_date'] = current_time('Y-m-d H:i:s');
}
}
if ($mode == 'Insert') {
$retID = wp_insert_post( $data_array );
$mode_of_affect = 'Inserted';
if(is_wp_error($retID) || $retID == '') {
$core_instance->detailed_log[$line_number]['Message'] = "Can't insert this LP Order. " . $retID->get_error_message();
$wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey_value'");
return array('MODE' => $mode, 'ERROR_MSG' => $retID->get_error_message());
}
$core_instance->detailed_log[$line_number]['Message'] = 'Inserted LP Order ID: ' . $retID;
$wpdb->get_results("UPDATE $log_table_name SET created = $created_count WHERE $unikey_name = '$unikey_value'");
}
$returnArr['ID'] = $retID;
$returnArr['MODE'] = $mode_of_affect;
return $returnArr;
}
}

View File

@@ -0,0 +1,392 @@
<?php
/******************************************************************************************
* Copyright (C) Smackcoders. - All Rights Reserved under Smackcoders Proprietary License
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* You can contact Smackcoders at email address info@smackcoders.com.
*******************************************************************************************/
namespace Smackcoders\FCSV;
if (!defined('ABSPATH'))
exit; // Exit if accessed directly
class LifterLmsImport
{
private static $lifterlms_instance = null;
public static function getInstance()
{
if (LifterLmsImport::$lifterlms_instance == null) {
LifterLmsImport::$lifterlms_instance = new LifterLmsImport;
return LifterLmsImport::$lifterlms_instance;
}
return LifterLmsImport::$lifterlms_instance;
}
public function set_lifterlms_values($header_array, $value_array, $map, $post_id, $type, $mode){
$post_values = [];
$helpers_instance = ImportHelpers::getInstance();
$post_values = $helpers_instance->get_header_values($map, $header_array, $value_array);
$this->lifterlms_values_import($post_values, $post_id, $type, $mode);
}
public function lifterlms_values_import($post_values, $post_id, $type, $mode){
global $wpdb;
$lifter_course_setting_array = [];
$lifter_course_setting_array['_llms_instructors'] = isset($post_values['_llms_instructors']) ? $post_values['_llms_instructors'] :'';
$lifter_course_setting_array['_llms_sales_page_content_type'] = isset($post_values['_llms_sales_page_content_type']) ? $post_values['_llms_sales_page_content_type'] : '' ;
$lifter_course_setting_array['_llms_sales_page_content_page_id'] = isset($post_values['_llms_sales_page_content_page_id']) ? $post_values['_llms_sales_page_content_page_id'] : '' ;
$lifter_course_setting_array['_llms_sales_page_content_url'] = isset($post_values['_llms_sales_page_content_url']) ? $post_values['_llms_sales_page_content_url'] : '' ;
$lifter_course_setting_array['_llms_length'] = isset($post_values['_llms_length']) ? $post_values['_llms_length'] : '';
$lifter_course_setting_array['_llms_post_course_difficulty'] = isset($post_values['_llms_post_course_difficulty']) ? $post_values['_llms_post_course_difficulty'] : '';
$lifter_course_setting_array['_llms_video_embed'] = isset($post_values['_llms_video_embed']) ? $post_values['_llms_video_embed'] : '';
$lifter_course_setting_array['_llms_tile_featured_video'] = isset($post_values['_llms_tile_featured_video']) ? $post_values['_llms_tile_featured_video'] : '';
$lifter_course_setting_array['_llms_audio_embed'] = isset($post_values['_llms_audio_embed']) ? $post_values['_llms_audio_embed'] : '' ;
$lifter_course_setting_array['_llms_content_restricted_message'] = isset($post_values['_llms_content_restricted_message']) ? $post_values['_llms_content_restricted_message'] : '' ;
$lifter_course_setting_array['_llms_enrollment_period'] = isset($post_values['_llms_enrollment_period']) ? $post_values['_llms_enrollment_period'] : '' ;
$lifter_course_setting_array['_llms_enrollment_start_date'] = isset($post_values['_llms_enrollment_start_date']) ? $post_values['_llms_enrollment_start_date'] : '';
$lifter_course_setting_array['_llms_enrollment_end_date'] = isset($post_values['_llms_enrollment_end_date']) ? $post_values['_llms_enrollment_end_date'] : '' ;
$lifter_course_setting_array['_llms_enrollment_opens_message'] = isset($post_values['_llms_enrollment_opens_message']) ? $post_values['_llms_enrollment_opens_message'] : '';
$lifter_course_setting_array['_llms_enrollment_closed_message'] = isset($post_values['_llms_enrollment_closed_message']) ? $post_values['_llms_enrollment_closed_message'] : '';
$lifter_course_setting_array['_llms_time_period'] = isset($post_values['_llms_time_period']) ? $post_values['_llms_time_period'] : '';
$lifter_course_setting_array['_llms_start_date'] = isset($post_values['_llms_start_date']) ? $post_values['_llms_start_date'] : '';
$lifter_course_setting_array['_llms_end_date'] = isset($post_values['_llms_end_date']) ? $post_values['_llms_end_date'] : '';
$lifter_course_setting_array['_llms_course_opens_message'] = isset($post_values['_llms_course_opens_message']) ? $post_values['_llms_course_opens_message'] : '';
$lifter_course_setting_array['_llms_course_closed_message'] = isset($post_values['_llms_course_closed_message']) ? $post_values['_llms_course_closed_message'] : '';
$lifter_course_setting_array['_llms_has_prerequisite'] = isset($post_values['_llms_has_prerequisite']) ? $post_values['_llms_has_prerequisite'] : '';
$lifter_course_setting_array['_llms_prerequisite'] = isset($post_values['_llms_prerequisite']) ? $post_values['_llms_prerequisite'] : '';
$lifter_course_setting_array['_llms_prerequisite_track'] = isset($post_values['_llms_prerequisite_track']) ? $post_values['_llms_prerequisite_track'] : '';
$lifter_course_setting_array['_llms_enable_capacity'] = isset($post_values['_llms_enable_capacity']) ? $post_values['_llms_enable_capacity'] : '';
$lifter_course_setting_array['_llms_capacity'] = isset($post_values['_llms_capacity']) ? $post_values['_llms_capacity'] : '';
$lifter_course_setting_array['_llms_capacity_message'] = isset($post_values['_llms_capacity_message']) ? $post_values['_llms_capacity_message'] : '';
$lifter_course_setting_array['_llms_reviews_enabled'] = isset($post_values['_llms_reviews_enabled']) ? $post_values['_llms_reviews_enabled'] : '';
$lifter_course_setting_array['_llms_display_reviews'] = isset($post_values['_llms_display_reviews']) ? $post_values['_llms_display_reviews'] : '';
$lifter_course_setting_array['_llms_num_reviews'] = isset($post_values['_llms_num_reviews']) ? $post_values['_llms_num_reviews'] : '';
$lifter_course_setting_array['_llms_multiple_reviews_disabled'] = isset($post_values['_llms_multiple_reviews_disabled']) ? $post_values['_llms_multiple_reviews_disabled'] : '';
foreach ($lifter_course_setting_array as $course_key => $course_value) {
if($course_key == '_llms_instructors'){
$data =array();
$inst_value = explode('|',$course_value);
foreach($inst_value as $ins){
$arr =array();
$instructor = explode(',',$ins);
$arr['label'] = 'Author';
$arr['visibility'] = $instructor[0];
$user_name =$instructor[1];
$user_id = $wpdb->get_var("SELECT ID FROM {$wpdb->prefix}users WHERE display_name='$user_name'");
$arr['id'] = $user_id;
$arr['name'] = $user_name;
array_push($data,$arr);
}
update_post_meta($post_id, $course_key, $data);
}
else{
update_post_meta($post_id, $course_key, $course_value);
}
}
if($type == 'lesson' || $type == 'llms_quiz' || $type == 'llms_coupon'){
if($type == 'lesson'){
LifterLmsImport::$lifterlms_instance->insert_lesson_details($get_section_id, $post_id, $post_values, $mode);
}
if($type == 'llms_quiz'){
LifterLmsImport::$lifterlms_instance->insert_quiz_details($type,$get_section_id, $post_id, $post_values, $mode);
}
if($type == 'llms_coupon'){
LifterLmsImport::$lifterlms_instance->insert_coupon_details($type,$get_section_id, $post_id, $post_values, 0, $mode, 'new');
}
}
if($type == 'llms_review'){
LifterLmsImport::$lifterlms_instance->insert_review_details($post_id, $post_values, $mode);
}
}
public function insert_lesson_details($inserted_section_id, $lesson_post_id, $post_values, $mode){
global $wpdb;
if($mode == 'Insert'){
if(isset($inserted_section_id)){
LifterLmsImport::$lifterlms_instance->insert_to_lifterlms_section_items($inserted_section_id, $lesson_post_id, 'lesson');
}
}
if($mode == 'Update'){
if(isset($inserted_section_id)){
LifterLmsImport::$lifterlms_instance->insert_to_lifterlms_section_items($inserted_section_id, $lesson_post_id, 'lesson');
}
}
$lesson_meta_array['_llms_reviews_enabled'] = isset($post_values['_llms_reviews_enabled']) ? $post_values['_llms_reviews_enabled'] : '';
$lesson_meta_array['_llms_display_reviews'] = isset($post_values['_llms_display_reviews']) ? $post_values['_llms_display_reviews'] : '';
$lesson_meta_array['_llms_num_reviews'] = isset($post_values['_llms_num_reviews']) ? $post_values['_llms_num_reviews'] : '';
$lesson_meta_array['_llms_multiple_reviews_disabled'] = isset($post_values['_llms_multiple_reviews_disabled']) ? $post_values['_llms_multiple_reviews_disabled'] : '';
$lesson_meta_array['_llms_video_embed'] = isset($post_values['_llms_video_embed']) ? $post_values['_llms_video_embed'] : '';
$lesson_meta_array['_llms_audio_embed'] = isset($post_values['_llms_audio_embed']) ? $post_values['_llms_audio_embed'] : '';
$lesson_meta_array['_llms_free_lesson'] = isset($post_values['_llms_free_lesson']) ? $post_values['_llms_free_lesson'] : '';
$lesson_meta_array['_llms_has_prerequisite'] = isset($post_values['_llms_has_prerequisite']) ? $post_values['_llms_has_prerequisite'] : '';
$lesson_meta_array['_llms_prerequisite'] = isset($post_values['_llms_prerequisite']) ? $post_values['_llms_prerequisite'] : '';
$lesson_meta_array['_llms_drip_method'] = isset($post_values['_llms_drip_method']) ? $post_values['_llms_drip_method'] : '';
$lesson_meta_array['_llms_days_before_available'] = isset($post_values['_llms_days_before_available']) ? $post_values['_llms_days_before_available'] : '';
$lesson_meta_array['_llms_date_available'] = isset($post_values['_llms_date_available']) ? $post_values['_llms_date_available'] : '';
$lesson_meta_array['_llms_time_available'] = isset($post_values['_llms_time_available']) ? $post_values['_llms_time_available'] : '';
$lesson_meta_array['_llms_require_passing_grade'] = isset($post_values['_llms_require_passing_grade']) ? $post_values['_llms_require_passing_grade'] : '';
$lesson_meta_array['_thumbnail_id'] = isset($post_values['_thumbnail_id']) ? $post_values['_thumbnail_id'] : '';
$lesson_meta_array['_llms_order'] = isset($post_values['_llms_order']) ? $post_values['_llms_order'] : '';
$lesson_meta_array['_llms_parent_course'] = isset($post_values['_llms_parent_course']) ? $post_values['_llms_parent_course'] : '';
$lesson_meta_array['_llms_parent_section'] = isset($post_values['_llms_parent_section']) ? $post_values['_llms_parent_section'] : '';
$lesson_meta_array['_llms_require_assignment_passing_grade'] = isset($post_values['_llms_require_assignment_passing_grade']) ? $post_values['_llms_require_assignment_passing_grade'] : '';
$lesson_meta_array['_llms_points'] = isset($post_values['_llms_points']) ? $post_values['_llms_points'] : '';
$lesson_meta_array['_llms_quiz_enabled'] = isset($post_values['_llms_quiz_enabled']) ? $post_values['_llms_quiz_enabled'] : '';
$lesson_meta_array['_llms_lesson_id'] = isset($post_values['_llms_lesson_id']) ? $post_values['_llms_lesson_id'] : '';
$lesson_meta_array['_llms_allowed_attempts'] = isset($post_values['_llms_allowed_attempts']) ? $post_values['_llms_allowed_attempts'] : '';
$lesson_meta_array['_llms_limit_attempts'] = isset($post_values['_llms_limit_attempts']) ? $post_values['_llms_limit_attempts'] : '';
$lesson_meta_array['_llms_limit_time'] = isset($post_values['_llms_limit_time']) ? $post_values['_llms_limit_time'] : '';
$lesson_meta_array['_llms_passing_percent'] = isset($post_values['_llms_passing_percent']) ? $post_values['_llms_passing_percent'] : '';
$lesson_meta_array['_llms_show_correct_answer'] = isset($post_values['_llms_show_correct_answer']) ? $post_values['_llms_show_correct_answer'] : '';
$lesson_meta_array['_llms_time_limit'] = isset($post_values['_llms_time_limit']) ? $post_values['_llms_time_limit'] : '';
$lesson_meta_array['_llms_quiz'] = isset($post_values['_llms_quiz']) ? $post_values['_llms_quiz'] : '';
$lesson_meta_array['_llms_free_lesson'] = isset($post_values['_llms_free_lesson']) ? $post_values['_llms_free_lesson'] : '';
foreach ($lesson_meta_array as $lesson_key => $lesson_value) {
update_post_meta($lesson_post_id, $lesson_key, $lesson_value);
}
}
public function insert_quiz_details($type,$inserted_section_id, $quiz_post_id, $post_values, $mode){
global $wpdb;
if($mode == 'Update'){
$check_for_same_section_id = $wpdb->get_var("SELECT section_id FROM {$wpdb->prefix}lifterlms_section_items WHERE item_id = $quiz_post_id AND item_type = 'llms_quiz' ");
if(!empty($check_for_same_section_id) && $inserted_section_id == $check_for_same_section_id){
$get_section_item_id = $wpdb->get_var("SELECT section_item_id FROM {$wpdb->prefix}lifterlms_section_items WHERE section_id = $check_for_same_section_id AND item_id = $quiz_post_id AND item_type = 'llmsquiz' ");
LifterLmsImport::$lifterlms_instance->update_to_lifterlms_section_items($inserted_section_id, $quiz_post_id, 'llms_quiz', $get_section_item_id );
}
}
if($mode == 'Insert'){
if(!empty($inserted_section_id)){
LifterLmsImport::$lifterlms_instance->insert_to_lifterlms_section_items($inserted_section_id, $quiz_post_id, 'llms_quiz');
}
}
$quiz_meta_array['_llms_duration'] = isset($post_values['_llms_duration']) ? $post_values['_llms_duration'] : '10 minute';
$quiz_meta_array['_llms_minus_points'] = isset($post_values['_llms_minus_points']) ? $post_values['_llms_minus_points'] : 0;
$quiz_meta_array['_llms_minus_skip_questions'] = isset($post_values['_llms_minus_skip_questions']) ? $post_values['_llms_minus_skip_questions'] : 'no';
$quiz_meta_array['_llms_passing_grade'] = isset($post_values['_llms_passing_grade']) ? $post_values['_llms_passing_grade'] : 80;
$quiz_meta_array['_llms_retake_count'] = isset($post_values['_llms_quiz_retake_count']) ? $post_values['_llms_quiz_retake_count'] : 0;
$quiz_meta_array['_llms_instant_check'] = isset($post_values['_llms_instant_check']) ? $post_values['_llms_instant_check'] : 'no';
$quiz_meta_array['_llms_negative_marking'] = isset($post_values['_llms_negative_marking']) ? $post_values['_llms_negative_marking'] : 'no';
$quiz_meta_array['_llms_pagination'] = isset($post_values['_llms_pagination']) ? $post_values['_llms_pagination'] : 1;
$quiz_meta_array['_llms_show_correct_review'] = isset($post_values['_llms_show_correct_review']) ? $post_values['_llms_show_correct_review'] : 'yes';
$quiz_meta_array['_llms_review'] = isset($post_values['_llms_review']) ? $post_values['_llms_review'] : 'yes';
foreach ($quiz_meta_array as $quiz_key => $quiz_value) {
update_post_meta($quiz_post_id, $quiz_key, $quiz_value);
}
if(isset($post_values['question_title'])){
$get_question_titles = explode(',', $post_values['question_title']);
$get_question_descriptions = explode(',', $post_values['question_description']);
$get_all_question_titles = $wpdb->get_results("SELECT post_title FROM {$wpdb->prefix}posts WHERE post_type = 'llms_question' AND post_status = 'publish' ", ARRAY_A);
$all_questions_title = array_column($get_all_question_titles, 'post_title');
$temp = 0;
foreach($get_question_titles as $question_titles){
if($mode == 'Insert'){
if(in_array($question_titles, $all_questions_title)){
$question_post_id = $wpdb->get_var("SELECT ID from {$wpdb->prefix}posts WHERE post_title = '$question_titles' AND post_type = 'llms_question' AND post_status = 'publish' ");
$post_values['quiz_id'] = $quiz_post_id;
$check_assigned_to_quiz = $wpdb->get_var("SELECT quiz_question_id FROM {$wpdb->prefix}lifterlms_quiz_questions WHERE question_id = $question_post_id ");
if(empty($check_assigned_to_quiz)){
LifterLmsImport::$lifterlms_instance->insert_coupon_details($type,$inserted_section_id, $question_post_id, $post_values, $temp, $mode, 'existing');
}
}else{
$question_description = isset($get_question_descriptions[$temp]) ? $get_question_descriptions[$temp] : '';
$question_post_id = LifterLmsImport::$lifterlms_instance->insert_post($question_titles, $question_description, 'llms_question');
$post_values['quiz_id'] = $quiz_post_id;
LifterLmsImport::$lifterlms_instance->insert_coupon_details($type,$inserted_section_id, $question_post_id, $post_values, $temp, $mode, 'existing');
}
}
if($mode == 'Update'){
if(in_array($question_titles, $all_questions_title)){
$question_post_id = $wpdb->get_var("SELECT ID from {$wpdb->prefix}posts WHERE post_title = '$question_titles' AND post_type = 'llms_question' AND post_status = 'publish' ");
$post_values['quiz_id'] = $quiz_post_id;
$check_assigned_to_quiz = $wpdb->get_var("SELECT quiz_question_id FROM {$wpdb->prefix}lifterlms_quiz_questions WHERE question_id = $question_post_id ");
if(empty($check_assigned_to_quiz)){
LifterLmsImport::$lifterlms_instance->insert_coupon_details($type,$inserted_section_id, $question_post_id, $post_values, $temp, $mode, 'existing');
}
}else{
$question_description = isset($get_question_descriptions[$temp]) ? $get_question_descriptions[$temp] : '';
$question_post_id = LifterLmsImport::$lifterlms_instance->insert_post($question_titles, $question_description, 'llms_question');
$post_values['quiz_id'] = $quiz_post_id;
LifterLmsImport::$lifterlms_instance->insert_coupon_details($type,$inserted_section_id, $question_post_id, $post_values, $temp, $mode, 'existing');
}
}
$temp++;
}
}
}
public function insert_coupon_details($type,$inserted_section_id, $question_post_id, $post_values, $temp, $mode, $condition){
global $wpdb;
$question_meta_array['_llms_enable_trial_discount'] = isset($post_values['_llms_enable_trial_discount']) ? $post_values['_llms_enable_trial_discount'] : '';
$question_meta_array['_llms_trial_amount'] = isset($post_values['_llms_trial_amount']) ? $post_values['_llms_trial_amount'] : '';
$question_meta_array['_llms_coupon_courses'] = isset($post_values['_llms_coupon_courses']) ? $post_values['_llms_coupon_courses'] : '';
$question_meta_array['_llms_coupon_membership'] = isset($post_values['_llms_coupon_membership']) ? $post_values['_llms_coupon_membership'] : '';
$question_meta_array['_llms_coupon_amount'] = isset($post_values['_llms_coupon_amount']) ? $post_values['_llms_coupon_amount'] : '';
$question_meta_array['_llms_usage_limit'] = isset($post_values['_llms_usage_limit']) ? $post_values['_llms_usage_limit'] : '';
$question_meta_array['_llms_discount_type'] = isset($post_values['_llms_discount_type']) ? $post_values['_llms_discount_type'] : '';
$question_meta_array['_llms_description'] = isset($post_values['_llms_description']) ? $post_values['_llms_description'] : '';
$question_meta_array['_llms_expiration_date'] = isset($post_values['_llms_expiration_date']) ? $post_values['_llms_expiration_date'] : '';
$question_meta_array['_llms_plan_type'] = isset($post_values['_llms_plan_type']) ? $post_values['_llms_plan_type'] : '';
foreach ($question_meta_array as $question_key => $question_value) {
if($question_key == '_llms_coupon_courses'){
$course_data = explode('|',$question_value);
update_post_meta($question_post_id, $question_key, $course_data);
}
else{
update_post_meta($question_post_id, $question_key, $question_value);
}
}
if(isset($post_values['quiz_id'])){
$quiz_id = $post_values['quiz_id'];
$question_order = 1;
$get_question_order = $wpdb->get_var("SELECT question_order FROM {$wpdb->prefix}lifterlms_quiz_questions WHERE quiz_id = $quiz_id ORDER BY quiz_question_id DESC LIMIT 1");
if(!empty($get_question_order)){
$question_order = $get_question_order + 1;
}
if($mode == 'Insert'){
LifterLmsImport::$lifterlms_instance->insert_to_lifterlms_quiz_questions($quiz_id, $question_post_id, $question_order);
}
if($mode == 'Update'){
LifterLmsImport::$lifterlms_instance->insert_to_lifterlms_quiz_questions($quiz_id, $question_post_id, $question_order);
if($condition == 'new'){
if(!empty($inserted_section_id)){
$check_for_same_section_id = $wpdb->get_var("SELECT section_id FROM {$wpdb->prefix}lifterlms_section_items WHERE item_id = $quiz_id AND item_type = 'llms_quiz' ");
if(!empty($check_for_same_section_id) && $inserted_section_id == $check_for_same_section_id){
$get_section_item_id = $wpdb->get_var("SELECT section_item_id FROM {$wpdb->prefix}lifterlms_section_items WHERE section_id = $check_for_same_section_id AND item_id = $quiz_id AND item_type = 'llms_quiz' ");
LifterLmsImport::$lifterlms_instance->update_to_lifterlms_section_items($inserted_section_id, $quiz_id, 'llms_quiz', $get_section_item_id);
}
}
}
}
if(!empty($inserted_section_id)){
$check_assigned_to_course = $wpdb->get_var("SELECT section_item_id FROM {$wpdb->prefix}lifterlms_section_items WHERE section_id = $inserted_section_id AND item_id = $quiz_id AND item_type = 'llms_quiz' ");
$check_assigned_to_another_course = $wpdb->get_var("SELECT section_id FROM {$wpdb->prefix}lifterlms_section_items WHERE item_id = $quiz_id AND item_type = 'llms_quiz' ");
if(empty($check_assigned_to_course) && empty($check_assigned_to_another_course)){
LifterLmsImport::$lifterlms_instance->insert_to_lifterlms_section_items($inserted_section_id, $quiz_id, 'llms_quiz');
}
}
}
else{
if(isset($post_values['question_options'])){
$get_separate_options = explode('->', $post_values['question_options']);
foreach($get_separate_options as $option_values){
$get_title_options = explode('|', $option_values);
$wpdb->insert(
"{$wpdb->prefix}lifterlms_question_answers",
array("question_id" => $question_post_id, "title" => $get_title_options[0], "is_true"=>$get_title_options[1]),
array('%d', '%s','%s')
);
}
}
}
}
public function insert_review_details($order_id, $post_values, $mode){
global $wpdb;
$review_meta_array['_thumbnail_id'] = isset($post_values['_thumbnail_id']) ? $post_values['_thumbnail_id'] : '';
$review_meta_array['_llms_reviews_enabled'] = isset($post_values['_llms_reviews_enabled']) ? $post_values['_llms_reviews_enabled'] : '';
$review_meta_array['_llms_display_reviews'] = isset($post_values['_llms_display_reviews']) ? $post_values['_llms_display_reviews'] : '';
$review_meta_array['_llms_num_reviews'] = isset($post_values['_llms_num_reviews']) ? $post_values['_llms_num_reviews'] : '';
$review_meta_array['_llms_multiple_reviews_disabled'] = isset($post_values['_llms_multiple_reviews_disabled']) ? $post_values['_llms_multiple_reviews_disabled'] : '';
foreach($review_meta_array as $order_key => $order_value){
update_post_meta($order_id, $order_key, $order_value);
}
}
public function insert_to_lifterlms_section_items($inserted_section_id, $post_id, $type){
global $wpdb;
$wpdb->insert(
"{$wpdb->prefix}lifterlms_section_items",
array("section_id" => $inserted_section_id, "item_id" => $post_id, "item_type" => "$type"),
array('%d', '%d', '%s')
);
}
public function update_to_lifterlms_section_items($inserted_section_id, $post_id, $type, $get_section_item_id){
global $wpdb;
$wpdb->update(
$wpdb->prefix.'lifterlms_section_items',
array('section_id' => $inserted_section_id,'item_id' => $post_id, "item_type" => "$type"),
array( 'section_item_id' => $get_section_item_id )
);
}
public function insert_to_lifterlms_quiz_questions($quiz_id, $question_post_id, $question_order){
global $wpdb;
$wpdb->insert(
"{$wpdb->prefix}lifterlms_quiz_questions",
array("quiz_id" => $quiz_id, "question_id" => $question_post_id, "question_order" => $question_order),
array('%d', '%d', '%d')
);
}
public function insert_post($post_title, $post_content, $post_type){
$post_array['post_title'] = $post_title;
$post_array['post_content'] = $post_content;
$post_array['post_type'] = $post_type;
$post_array['post_status'] = 'publish';
$post_id = wp_insert_post($post_array);
return $post_id;
}
public function update_post($post_title, $post_content, $post_type, $id){
$update_array['post_title'] = $post_title;
$update_array['post_content'] = $post_content;
$update_array['post_type'] = $post_type;
$update_array['post_status'] = 'publish';
$update_array['ID'] = $id;
wp_update_post($update_array);
}
}

View File

@@ -0,0 +1,54 @@
<?php
/******************************************************************************************
* Copyright (C) Smackcoders. - All Rights Reserved under Smackcoders Proprietary License
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* You can contact Smackcoders at email address info@smackcoders.com.
*******************************************************************************************/
namespace Smackcoders\FCSV;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class ListingImport {
private static $product_bundle_meta_instance = null;
public static function getInstance() {
if (ListingImport::$product_bundle_meta_instance == null) {
ListingImport::$product_bundle_meta_instance = new ListingImport;
return ListingImport::$product_bundle_meta_instance;
}
return ListingImport::$product_bundle_meta_instance;
}
function set_listing_values($header_array, $value_array, $maps , $post_id, $selected_type){
global $wpdb;
$helpers_instance = ImportHelpers::getInstance();
$post_values =$helpers_instance->get_header_values($maps , $header_array , $value_array);
foreach ($post_values as $meta_key => $value) {
print_r($post_values);
update_post_meta($post_id, $meta_key, $value);
if(is_plugin_active('geodirectory/geodirectory.php') ){
$wpdb->update(
$wpdb->prefix . 'geodir_gd_place_detail',
array($meta_key => $value),
array('post_id' => $post_id),
array('%s'),
array('%d')
);
//geodir_save_post($data, $post_id, 'gd_place');
}
}
}
}

View File

@@ -0,0 +1,336 @@
<?php
/******************************************************************************************
* Copyright (C) Smackcoders. - All Rights Reserved under Smackcoders Proprietary License
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* You can contact Smackcoders at email address info@smackcoders.com.
*******************************************************************************************/
namespace Smackcoders\FCSV;
if (!defined('ABSPATH'))
exit; // Exit if accessed directly
class MasterStudyLMSImport
{
private static $stm_instance = null;
public static function getInstance()
{
if (MasterStudyLMSImport::$stm_instance == null) {
MasterStudyLMSImport::$stm_instance = new MasterStudyLMSImport;
return MasterStudyLMSImport::$stm_instance;
}
return MasterStudyLMSImport::$stm_instance;
}
public function set_stm_values($header_array, $value_array, $map, $post_id, $type, $mode){
$post_values = [];
$helpers_instance = ImportHelpers::getInstance();
$post_values = $helpers_instance->get_header_values($map, $header_array, $value_array);
$this->stm_values_import($post_values, $post_id, $type, $mode);
}
public function stm_values_import($post_values, $post_id, $type, $mode){
global $wpdb;
if($type == 'stm-courses'){
$course_setting_array = [];
$dates = explode(",", $post_values['status_dates']);
$timestamps = array();
foreach ($dates as $date) {
$timestamp = strtotime($date);
if ($timestamp !== false) {
$timestamps[] = $timestamp;
}
}
$course_setting_array['featured'] = isset($post_values['featured']) ? $post_values['featured'] : 1000;
$course_setting_array['views'] = isset($post_values['views']) ? $post_values['views'] : 0;
$course_setting_array['level'] = isset($post_values['level']) ? $post_values['level'] : 0;
$course_setting_array['duration_info'] = isset($post_values['duration_info']) ? $post_values['duration_info'] : 'no';
$course_setting_array['video_duration'] = isset($post_values['video_duration']) ? $post_values['video_duration'] : '';
$course_setting_array['price'] = isset($post_values['price']) ? $post_values['price'] : 'yes';
$course_setting_array['sale_price'] = isset($post_values['sale_price']) ? $post_values['sale_price'] : 'yes';
$course_setting_array['status'] = isset($post_values['status']) ? $post_values['status'] : 0;
$course_setting_array['status_dates'] = isset($post_values['status_dates']) ? implode(',', array_map(function($timestamp) { return $timestamp * 1000; }, $timestamps)) : '';
$course_setting_array['status_dates_end'] = isset($post_values['status_dates_end']) ? strtotime($post_values['status_dates_end']) * 1000: '';
$course_setting_array['status_dates_start'] = isset($post_values['status_dates_start']) ? strtotime($post_values['status_dates_start']) * 1000: '';
$faq_string = isset($post_values['faq']) ? $post_values['faq'] : '';
$faq_array = array();
if (!empty($faq_string)) {
$faq_items = explode('|', $faq_string);
foreach ($faq_items as $faq_item) {
$faq = array();
$faq_parts = explode(',', $faq_item);
foreach ($faq_parts as $faq_part) {
$faq_part_parts = explode(':', $faq_part);
$faq[trim($faq_part_parts[0])] = trim($faq_part_parts[1]);
}
$faq_array[] = $faq;
}
}
$course_setting_array['faq'] = json_encode($faq_array);
$course_files_pack_string = isset($post_values['course_files_pack']) ? $post_values['course_files_pack'] : '';
$course_files_pack_array = array();
if (!empty($course_files_pack_string)) {
$course_files = explode('|', $course_files_pack_string);
foreach ($course_files as $course_file) {
$file_parts = explode(',', $course_file);
$file_name_parts = explode(':', $file_parts[0]);
$course_files_pack_array[] = array('course_files_label' => trim($file_name_parts[1]), 'course_files' => '');
}
}
$course_setting_array['course_files_pack'] = json_encode($course_files_pack_array);
$course_setting_array['expiration_course'] = isset($post_values['expiration_course']) ? $post_values['expiration_course'] : '';
$course_setting_array['not_membership'] = isset($post_values['not_membership']) ? $post_values['not_membership'] : '';
$course_setting_array['end_time'] = isset($post_values['end_time']) ? $post_values['end_time'] : '';
$course_setting_array['announcement'] = isset($post_values['announcement']) ? $post_values['announcement'] : '';
$course_setting_array['current_students'] = isset($post_values['current_students']) ? $post_values['current_students'] : '';
$quiz_id = isset($post_values['quiz_id']) ? trim(str_replace('|', ',', $post_values['quiz_id']), ',') : '';
$lesson_id = isset($post_values['lesson_id']) ? trim(str_replace('|', ',', $post_values['lesson_id']), ',') : '';
$quiz_name = isset($post_values['quiz_name']) ? trim(str_replace('|', ',', $post_values['quiz_name']), ',') : '';
$lesson_name = isset($post_values['lesson_name']) ? trim(str_replace('|', ',', $post_values['lesson_name']), ',') : '';
if (!empty($quiz_id)) {
$course_setting_array['quiz_id'] = $quiz_id;
}
if (!empty($lesson_id)) {
$course_setting_array['lesson_id'] = $lesson_id;
}
if (!empty($quiz_name)) {
$course_setting_array['quiz_name'] = $quiz_name;
}
if (!empty($lesson_name)) {
$course_setting_array['lesson_name'] = $lesson_name;
}
$curriculum = isset($post_values['curriculum']) ? $post_values['curriculum'] : '';
$lesson_array = explode(',', $lesson_id);
$quiz_array = explode(',', $quiz_id);
$curriculum_array = explode(',', $curriculum);
$new_curriculum_array = array();
for ($i = 0; $i < count($curriculum_array); $i++) {
$new_curriculum_array[] = $curriculum_array[$i];
$new_curriculum_array[] = $lesson_array[$i];
$new_curriculum_array[] = $quiz_array[$i];
}
$new_curriculum = implode(',', $new_curriculum_array);
$course_setting_array['curriculum'] = $new_curriculum;
foreach ($course_setting_array as $course_key => $course_value) {
update_post_meta($post_id, $course_key, $course_value);
}
}
if($type == 'stm-lessons' || $type == 'stm-quizzes' || $type == 'stm-questions'){
if($type == 'stm-lessons'){
MasterStudyLMSImport::$stm_instance->insert_lesson_details($get_section_id, $post_id, $post_values, $mode);
}
if($type == 'stm-quizzes'){
MasterStudyLMSImport::$stm_instance->insert_quiz_details($type,$get_section_id, $post_id, $post_values, $mode);
}
if($type == 'stm-questions'){
MasterStudyLMSImport::$stm_instance->insert_question_details($type,$get_section_id, $post_id, $post_values, 0, $mode, 'new');
}
}
if($type == 'stm-orders'){
MasterStudyLMSImport::$stm_instance->insert_order_details($post_id, $post_values, $mode);
}
}
public function insert_lesson_details($inserted_section_id, $lesson_post_id, $post_values, $mode){
global $wpdb;
if(isset($post_values['duration'])){
update_post_meta($lesson_post_id, 'duration', $post_values['duration']);
}
if(isset($post_values['preview'])){
update_post_meta($lesson_post_id, 'preview', $post_values['preview']);
}
if(isset($post_values['lesson_excerpt'])){
update_post_meta($lesson_post_id, 'lesson_excerpt', $post_values['lesson_excerpt']);
}
if (isset($post_values['lesson_files_pack'])) {
$pack_values = array();
$pack_parts = explode(',', $post_values['lesson_files_pack']);
foreach ($pack_parts as $part) {
$key_value = explode(':', $part);
$key = trim($key_value[0]);
$value = trim($key_value[1]);
if ($key == 'closed_tab') {
$pack_values[$key] = ($value == 1) ? true : false;
} elseif ($key == 'lesson_files_label') {
$pack_values[$key] = rtrim($value, ';');
}
}
update_post_meta($lesson_post_id, 'lesson_files_pack', json_encode(array($pack_values)));
}
if(isset($post_values['_thumbnail_id'])){
update_post_meta($lesson_post_id, '_thumbnail_id', $post_values['_thumbnail_id']);
}
if(isset($post_values['type'])){
update_post_meta($lesson_post_id, 'type', $post_values['type']);
}
if(isset($post_values['video_type'])){
update_post_meta($lesson_post_id, 'video_type', $post_values['video_type']);
}
if(isset($post_values['lesson_youtube_url'])){
update_post_meta($lesson_post_id, 'lesson_youtube_url', $post_values['lesson_youtube_url']);
}
if(isset($post_values['presto_player_idx'])){
update_post_meta($lesson_post_id, 'presto_player_idx', $post_values['presto_player_idx']);
}
if(isset($post_values['lesson_video'])){
update_post_meta($lesson_post_id, 'lesson_video', $post_values['lesson_video']);
}
if(isset($post_values['lesson_video_poster'])){
update_post_meta($lesson_post_id, 'lesson_video_poster', $post_values['lesson_video_poster']);
}
if(isset($post_values['lesson_video_width'])){
update_post_meta($lesson_post_id, 'lesson_video_width', $post_values['lesson_video_width']);
}
if(isset($post_values['lesson_shortcode'])){
update_post_meta($lesson_post_id, 'lesson_shortcode', $post_values['lesson_shortcode']);
}
if(isset($post_values['lesson_embed_ctx'])){
update_post_meta($lesson_post_id, 'lesson_embed_ctx', $post_values['lesson_embed_ctx']);
}
if(isset($post_values['lesson_stream_url'])){
update_post_meta($lesson_post_id, 'lesson_stream_url', $post_values['lesson_stream_url']);
}
if(isset($post_values['lesson_vimeo_url'])){
update_post_meta($lesson_post_id, 'lesson_vimeo_url', $post_values['lesson_vimeo_url']);
}
if(isset($post_values['lesson_ext_link_url'])){
update_post_meta($lesson_post_id, 'lesson_ext_link_url', $post_values['lesson_ext_link_url']);
}
}
public function insert_quiz_details($type,$inserted_section_id, $quiz_post_id, $post_values, $mode){
global $wpdb;
$quiz_meta_array['duration'] = isset($post_values['duration']) ? $post_values['duration'] : '10 minute';
$quiz_meta_array['lesson_excerpt'] = isset($post_values['lesson_excerpt']) ? $post_values['lesson_excerpt'] : 0;
$quiz_meta_array['quiz_style'] = isset($post_values['quiz_style']) ? $post_values['quiz_style'] : 'no';
$quiz_meta_array['correct_answer'] = isset($post_values['correct_answer']) ? $post_values['correct_answer'] : 80;
$quiz_meta_array['passing_grade'] = isset($post_values['passing_grade']) ? $post_values['passing_grade'] : 0;
$quiz_meta_array['re_take_cut'] = isset($post_values['re_take_cut']) ? $post_values['re_take_cut'] : 'no';
$quiz_meta_array['random_questions'] = isset($post_values['random_questions']) ? $post_values['random_questions'] : 'no';
$quiz_meta_array['questions'] = isset($post_values['questions']) ? $post_values['questions'] : 1;
foreach ($quiz_meta_array as $quiz_key => $quiz_value) {
update_post_meta($quiz_post_id, $quiz_key, $quiz_value);
}
}
public function insert_question_details($type,$inserted_section_id, $question_post_id, $post_values, $temp, $mode, $condition){
global $wpdb;
$temp=0;
if(isset($post_values['type'])){
$stm_questions_type = explode(',',$post_values['type']);
}
if(isset($post_values['question_explanation'])){
$stm_questions_explanation = explode(',',$post_values['question_explanation']);
}
if (isset($post_values['answers'])) {
$answers = $post_values['answers'];
$answers_array = explode('|', trim($answers, '|'));
$result_array = array();
$i = 0;
foreach ($answers_array as $answer) {
$answer_array = explode(',', $answer);
$result_array[$i]['text'] = $answer_array[0];
$result_array[$i]['isTrue'] = $answer_array[1];
$i++;
}
$question_meta_array['answers'] = $result_array;
}
if(isset($post_values['question'])){
$stm_questions = explode(',',$post_values['question']);
}
if(isset($post_values['question_hint'])){
$stm_questions_hint = explode(',',$post_values['question_hint']);
}
if(isset($post_values['question_view_type'])){
$stm_questions_view_type = explode(',',$post_values['question_view_type']);
}
if(isset($post_values['image'])){
$stm_questions_image = explode(',',$post_values['image']);
}
$question_meta_array['type'] = isset($stm_questions_type[$temp]) ? $stm_questions_type[$temp] : 'true_or_false';
$question_meta_array['question_explanation'] = isset($stm_questions_explanation[$temp]) ? $stm_questions_explanation[$temp] : NULL;
$question_meta_array['question'] = isset($stm_questions[$temp]) ? $stm_questions[$temp] : NULL;
$question_meta_array['question_hint'] = isset($stm_questions_hint[$temp]) ? $stm_questions_hint[$temp] : NULL;
$question_meta_array['question_view_type'] = isset($stm_questions_view_type[$temp]) ? $stm_questions_view_type[$temp] : NULL;
$question_meta_array['image'] = isset($stm_questions_image[$temp]) ? $stm_questions_image[$temp] : NULL;
foreach ($question_meta_array as $question_key => $question_value) {
update_post_meta($question_post_id, $question_key, $question_value);
}
}
public function insert_order_details($order_id, $post_values, $mode){
global $wpdb;
$order_key = strtoupper( uniqid( 'ORDER' ) );
$order_meta_array = [];
$order_meta_array['status'] = isset($post_values['status']) ? $post_values['status'] : '';
foreach($order_meta_array as $order_key => $order_value){
update_post_meta($order_id, $order_key, $order_value);
}
}
}

View File

@@ -0,0 +1,144 @@
<?php
/******************************************************************************************
* Copyright (C) Smackcoders. - All Rights Reserved under Smackcoders Proprietary License
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* You can contact Smackcoders at email address info@smackcoders.com.
*******************************************************************************************/
namespace Smackcoders\FCSV;
use Smackcoders\FCSV\CoreFieldsImport;
use Smackcoders\FCSV\ImportHelpers;
use Smackcoders\FCSV\LogManager;
use Smackcoders\FCSV\MediaHandling;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class MediaImport {
private static $media_core_instance = null,$media_instance;
public static function getInstance() {
if (MediaImport::$media_core_instance == null) {
MediaImport::$media_core_instance = new MediaImport;
MediaImport::$media_instance = new MediaHandling;
return MediaImport::$media_core_instance;
}
return MediaImport::$media_core_instance;
}
public function media_fields_import($data_array , $mode , $type , $media_type , $unikey , $unikey_name, $line_number,$hash_key,$header_array ,$value_array) {
$returnArr = array();
global $wpdb;
$image_type = '';
$helpers_instance = ImportHelpers::getInstance();
$core_instance = CoreFieldsImport::getInstance();
$log_manager_instance = LogManager::getInstance();
global $core_instance;
$import_detail_table_name = $wpdb->prefix ."import_detail_log";
$media_handle = get_option('smack_image_options');
$updated_row_counts = $helpers_instance->update_count($unikey,$unikey_name);
$created_count = $updated_row_counts['created'];
$updated_count = $updated_row_counts['updated'];
$skipped_count = $updated_row_counts['skipped'];
$failed_count = $updated_row_counts['failed'];
$title = isset($data_array['title']) ? $data_array['title'] : '';
$caption = isset($data_array['caption']) ? $data_array['caption'] : '';
$alt_text = isset($data_array['alt_text']) ? $data_array['alt_text'] : '';
$description = isset($data_array['description']) ? $data_array['description'] : '';
$actual_url = isset($data_array['actual_url']) ? $data_array['actual_url'] : '';
if(!empty($data_array['file_name'])){
$sanitized_filename = str_replace(' ', '-', basename($data_array['file_name']));
$img = preg_replace('/[^a-zA-Z0-9._\-\s]/', '', $sanitized_filename);
$file_name = $img;
}
if($media_type == 'External'){
$img = isset($data_array['actual_url']) ? $data_array['actual_url'] : '';
}
if($media_handle['media_settings']['media_handle_option'] == 'true'){
$media_handle['media_settings']['title'] = $title ;
$media_handle['media_settings']['caption'] = $caption ;
$media_handle['media_settings']['alttext'] = $alt_text;
$media_handle['media_settings']['description'] = $description ;
$media_handle['media_settings']['file_name'] = $file_name;
update_option('smack_image_options', $media_handle);
}
if ($mode == 'Insert') {
$mode_of_affect = 'Inserted';
if(!empty($img)){
$attach_id = MediaImport::$media_instance->image_meta_table_entry($line_number,$data_array, '', '',$img, $hash_key, 'Media', 'Media','','','','','','','',$media_type);
$attachment_id = $wpdb->get_results("SELECT ID FROM {$wpdb->prefix}posts WHERE post_type = 'attachment' AND post_title = 'image-failed' AND ID ={$attach_id}", ARRAY_A);
}else{
$core_instance->detailed_log[$line_number]['Message'] = "The provided image file is empty. Double-check your import file and retry";
$wpdb->get_results("UPDATE $import_detail_table_name SET failed = $failed_count WHERE $unikey_name = '$unikey'");
return array('MODE' => $mode, 'ERROR_MSG' =>"Can't insert this Image" );
}
if(!empty($attachment_id)) {
if($media_type == 'Local'){
$data = array('media_id' => $attach_id,'file_url' => wp_get_attachment_url($attach_id),'file_name' => $file_name,'title' => $title,'caption' => $caption,'alt_text'=> $alt_text,'description' => $description,'status' => 'failed');
$core_instance->detailed_log[$line_number]['Message'] = "Unable to detect the image in your import file. Please check and try again.";
}else if($media_type == 'External'){
$data = array('media_id' => $attach_id,'file_url' => wp_get_attachment_url($attach_id),'actual_url' => $actual_url,'file_name' => $file_name,'title' => $title,'caption' => $caption,'alt_text'=> $alt_text,'description' => $description,'status' => 'failed');
$core_instance->detailed_log[$line_number]['Message'] = "The provided image file URL is invalid. Please verify the URL and try again";
}
$core_instance->media_log[$line_number] = $data;
$core_instance->detailed_log[$line_number]['state'] = 'Failed';
$wpdb->get_results("UPDATE $import_detail_table_name SET failed = $failed_count WHERE $unikey_name = '$unikey'");
return array('MODE' => $mode, 'ERROR_MSG' =>"Can't insert this Image" );
}else{
if($media_type == 'Local'){
$data = $this->imageMetaImport($attach_id,$data_array,$media_type);
$core_instance->media_log[$line_number] = $data;
$core_instance->detailed_log[$line_number]['Message'] = 'Inserted Image ID: ' . $attach_id .' FileName: '.$file_name;
}else if($media_type == 'External'){
$data = array('media_id' => $attach_id,'file_url' => wp_get_attachment_url($attach_id),'actual_url' => $actual_url,'file_name' => $file_name,'title' => $title,'caption' => $caption,'alt_text' => $alt_text,'description' => $description,'status' => 'success');
$core_instance->media_log[$line_number] = $data;
$core_instance->detailed_log[$line_number]['Message'] = 'Inserted Image ID: ' . $attach_id .' FileName: '.$file_name;
}
$core_instance->detailed_log[$line_number]['state'] = 'Inserted';
$wpdb->get_results("UPDATE $import_detail_table_name SET created = $created_count WHERE $unikey_name = '$unikey'");
}
}
if($media_handle['media_settings']['media_handle_option'] == 'true'){
$media_handle['media_settings']['title'] = '';
$media_handle['media_settings']['caption'] = '';
$media_handle['media_settings']['alttext'] = '';
$media_handle['media_settings']['description'] = '';
$media_handle['media_settings']['file_name'] = '';
update_option('smack_image_options', $media_handle);
}
$returnArr['ID'] = $attach_id;
$returnArr['MODE'] = $mode_of_affect;
return $returnArr;
}
public function imageMetaImport($attach_id,$data_array,$media_type){
if(!empty($data_array['file_name'])){
$sanitized_filename = str_replace(' ', '-', basename($data_array['file_name']));
$file_name = preg_replace('/[^a-zA-Z0-9._\-\s]/', '', $sanitized_filename);
}
$title = isset($data_array['title']) ? $data_array['title'] : '';
$caption = isset($data_array['caption']) ? $data_array['caption'] : '';
$alt_text = isset($data_array['alt_text']) ? $data_array['alt_text'] : '';
$description = isset($data_array['description']) ? $data_array['description'] : '';
if(isset($caption) || isset($description)){
$updated=wp_update_post(array(
'ID' =>$attach_id,
'post_content' =>$description,
'post_excerpt' =>$caption
));
}
if(!empty($title)){
wp_update_post(array(
'ID' =>$attach_id,
'post_title' =>$title
));
}
if(isset($alt_text)){
$updated = update_post_meta($attach_id, '_wp_attachment_image_alt', $alt_text);
}
$attachment_data = array('media_id' => $attach_id,'file_url' => wp_get_attachment_url($attach_id),'file_name' => $file_name,'title' => $title,'caption' => $caption,'alt_text' => $alt_text,'description' => $description,'status' => 'success');
return $attachment_data;
}
}

View File

@@ -0,0 +1,186 @@
<?php
/**
* WP Ultimate CSV Importer plugin file.
*
* Copyright (C) 2010-2020, Smackcoders Inc - info@smackcoders.com
*/
namespace Smackcoders\FCSV;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class MetaBoxImport {
private static $metabox_instance = null, $media_instance;
public static function getInstance() {
if (MetaBoxImport::$metabox_instance == null) {
MetaBoxImport::$metabox_instance = new MetaBoxImport;
MetaBoxImport::$media_instance = new MediaHandling();
return MetaBoxImport::$metabox_instance;
}
return MetaBoxImport::$metabox_instance;
}
function set_metabox_values($line_number,$header_array ,$value_array , $map, $post_id , $type,$hash_key){
$post_values = [];
$helpers_instance = ImportHelpers::getInstance();
$post_values = $helpers_instance->get_header_values($map , $header_array , $value_array);
$this->metabox_import_function($line_number,$post_values, $post_id , $header_array , $value_array, $type,$hash_key);
}
public function metabox_import_function ($line_number,$data_array, $pID, $header_array, $value_array, $type,$hash_key) {
global $wpdb;
$helpers_instance = ImportHelpers::getInstance();
$media_instance = MediaHandling::getInstance();
$extension_object = new ExtensionHandler;
$import_as = $extension_object->import_post_types($type );
$listTaxonomy = get_taxonomies();
$get_metabox_fields = \rwmb_get_object_fields( $import_as );
foreach($data_array as $data_key => $data_value){
if(str_contains($data_key,"checkbox_list_")){
$checkbox_list_fields = explode(',', $data_value);
$existing_values = get_post_meta($pID, $data_key, false);
if (empty($existing_values)) {
foreach($checkbox_list_fields as $data_val){
add_user_meta($pID, $data_key, $data_val);
}
} else {
delete_user_meta($pID, $data_key);
foreach($checkbox_list_fields as $data_val){
add_user_meta($pID, $data_key, $data_val);
}
}
}
$field_type = $get_metabox_fields[$data_key]['type'];
$check_for_multiple = isset($get_metabox_fields[$data_key]['multiple']) ? $get_metabox_fields[$data_key]['multiple'] : '';
if($field_type == 'text_list' || $field_type == 'select' || $field_type == 'select_advanced'){
$get_text_list_fields = explode(',', $data_value);
foreach($get_text_list_fields as $text_list_fields){
if($check_for_multiple){
add_post_meta($pID, $data_key, $text_list_fields);
}
else{
update_post_meta($pID, $data_key, $text_list_fields);
}
}
}
elseif($field_type == 'checkbox_list'){
$get_checkbox_list_fields = explode(',', $data_value);
$existing_values = get_post_meta($pID, $data_key, false);
if (empty($existing_values)) {
foreach ($get_checkbox_list_fields as $checkbox_list_fields) {
add_post_meta($pID, $data_key, $checkbox_list_fields);
}
} else {
delete_post_meta($pID, $data_key);
foreach ($get_checkbox_list_fields as $checkbox_list_fields) {
add_post_meta($pID, $data_key, $checkbox_list_fields);
}
}
}
elseif($field_type == 'fieldset_text'){
$get_fieldset_text_fields = explode(',', $data_value);
$get_fieldset_options = $get_metabox_fields[$data_key]['options'];
$temp = 0;
$fieldset_array = [];
foreach($get_fieldset_options as $fieldset_key => $fieldset_options){
$fieldset_array[$fieldset_key] = $get_fieldset_text_fields[$temp];
$temp++;
}
update_post_meta($pID, $data_key, $fieldset_array);
}
elseif($field_type == 'image' || $field_type == 'video' || $field_type == 'file' || $field_type == 'file_advanced' || $field_type == 'image_advanced'){
$get_uploads_fields = explode(',', $data_value);
$get_fields_count = count($get_uploads_fields);
$indexs = 0;
foreach($get_uploads_fields as $uploads_fields){
MetaBoxImport::$media_instance->store_image_ids($i=1);
$attachmentId = MetaBoxImport::$media_instance->image_meta_table_entry($line_number ,'', $pID ,$data_key, $uploads_fields, $hash_key,'metabox',$type,'','',$header_array, $value_array,'','',$indexs);
if($get_fields_count > 1){
add_post_meta($pID, $data_key, $attachmentId);
}
else{
update_post_meta($pID, $data_key, $attachmentId);
}
$indexs++;
}
}
elseif($field_type == 'videos'){
$media_fd = explode(',',$data_value);
$media_arr = array();
foreach($media_fd as $data){
if(is_numeric($data)){
$media_arr[] = $data;
}
else {
$attachmentId = MetaBoxImport::$media_instance->media_handling($data, $pID);
if($attachmentId)
$media_arr[] = $data;
}
}
$media_arr = implode(',',$media_arr);
update_post_meta($pID, $data_key, $media_arr);
}
elseif($field_type == 'file_input'){
$attachmentId = MetaBoxImport::$media_instance->media_handling($data_value, $pID);
$get_file_url = $wpdb->get_var("SELECT guid FROM {$wpdb->prefix}posts WHERE post_type = 'attachment' AND ID = $attachmentId");
update_post_meta($pID, $data_key, $get_file_url);
}
elseif($field_type == 'password'){
$data_value = wp_hash_password($data_value);
update_post_meta($pID, $data_key, $data_value);
}
elseif($field_type == 'post' || $field_type == 'user' || $field_type == 'taxonomy'){
if(is_numeric($data_value)){
update_post_meta($pID, $data_key, $data_value);
}
else{
if($field_type == 'post'){
$get_post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->prefix}posts WHERE post_title = '$data_value' AND post_status != 'trash' ");
}
elseif($field_type == 'user'){
$get_post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->prefix}users WHERE user_login = '$data_value' ");
}
elseif($field_type == 'taxonomy'){
//$get_post_id = $wpdb->get_var("SELECT term_id FROM {$wpdb->prefix}terms WHERE name = '$data_value' ");
$term_fd = explode('|',$data_value);
foreach($term_fd as $value){
$taxonomy = $get_metabox_fields[$data_key]['taxonomy']['0'];
$get_post_id = $wpdb->get_var("SELECT tax.term_taxonomy_id FROM {$wpdb->prefix}terms t INNER JOIN {$wpdb->prefix}term_taxonomy tax ON t.term_id=tax.term_id WHERE t.name='$value' AND tax.taxonomy='$taxonomy'");
$wpdb->get_results("INSERT into {$wpdb->prefix}term_relationships (`object_id`,`term_taxonomy_id`) VALUES($pID,$get_post_id)");
}
}
update_post_meta($pID, $data_key, $get_post_id);
}
}
else{
if(in_array($type, $listTaxonomy)){ //term module
foreach($data_array as $data_key => $data_value){
update_term_meta($pID,$data_key,$data_value);
}
}
update_post_meta($pID, $data_key, $data_value);
}
}
}
}

View File

@@ -0,0 +1,79 @@
<?php
/******************************************************************************************
* Copyright (C) Smackcoders. - All Rights Reserved under Smackcoders Proprietary License
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* You can contact Smackcoders at email address info@smackcoders.com.
*******************************************************************************************/
namespace Smackcoders\FCSV;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class OpenAIHelper {
private $apiKey;
private $baseUrl = 'https://api.openai.com/v1/chat/completions';
private $image_baseUrl = 'https://api.openai.com/v1/images/generations';
public function generateContent($prompt) {
$get_key =get_option('openAI_settings');
$this->apiKey = $get_key;
$data = [
'messages' => [['role' => 'user', 'content' => $prompt]],
'model' => 'gpt-3.5-turbo',
'max_tokens' => $maxCharacters,
];
$headers = [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $this->apiKey,
];
$response = wp_remote_post($this->baseUrl, array(
'body' => json_encode($data),
'headers' => $headers,
));
$httpCode = wp_remote_retrieve_response_code($response);
$decodedResponse = json_decode(wp_remote_retrieve_body($response), true);
if (isset($httpCode) && $httpCode != 200) {
return $httpCode;
}
if (isset($decodedResponse['choices'][0]['message']['content'])) {
return $decodedResponse['choices'][0]['message']['content'];
} else {
return false;
}
}
public function generateImage($prompt) {
$get_key =get_option('openAI_settings');
$this->apiKey = $get_key;
$data = [
'prompt' => $prompt,
'model' => 'dall-e-3',
];
$headers = [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $this->apiKey,
];
$response = wp_remote_post($this->image_baseUrl, array(
'body' => json_encode($data),
'headers' => $headers,
'timeout' => 60,
));
$httpCode = wp_remote_retrieve_response_code($response);
$decodedResponse = json_decode(wp_remote_retrieve_body($response), true);
if ($httpCode !== 200) {
return $httpCode;
}
if (isset($decodedResponse['data'][0]['url'])) {
return $decodedResponse['data'][0]['url'];
} else {
return false;
}
}
}

View File

@@ -0,0 +1,258 @@
<?php
/**
* WP Ultimate CSV Importer plugin file.
*
* Copyright (C) 2010-2020, Smackcoders Inc - info@smackcoders.com
*/
namespace Smackcoders\FCSV;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class PodsImport {
private static $pods_instance = null;
public static function getInstance() {
if (PodsImport::$pods_instance == null) {
PodsImport::$pods_instance = new PodsImport;
return PodsImport::$pods_instance;
}
return PodsImport::$pods_instance;
}
public function set_pods_values($line_number,$header_array ,$value_array , $map, $post_id , $type, $hash_key, $lang_map = null){
$post_values = [];
$helpers_instance = ImportHelpers::getInstance();
$post_values = $helpers_instance->get_header_values($map , $header_array , $value_array);
$lang_values = $helpers_instance->get_header_values($lang_map , $header_array , $value_array);
$this->pods_import_function($line_number,$post_values, $type, $post_id , $header_array , $value_array, $lang_values, $hash_key);
}
public function pods_import_function($line_number,$data_array, $importas, $pID, $header_array , $value_array, $wpml_array, $hash_key) {
global $wpdb;
$helpers_instance = ImportHelpers::getInstance();
$media_instance = MediaHandling::getInstance();
$list_taxonomy = get_taxonomies();
$podsFields = array();
$import_type = $helpers_instance->import_post_types($importas, null);
if($import_type == 'WooCommerce Product'){
$import_type = 'product';
}
if($import_type == 'Media'){
$import_type = 'media';
}
$post_id = $wpdb->get_results($wpdb->prepare("select ID from {$wpdb->prefix}posts where post_name= %s and post_type = %s", $import_type, '_pods_pod'));
if(!empty($post_id)) {
$lastId = $post_id[0]->ID;
$get_pods_fields = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name FROM {$wpdb->prefix}posts where post_parent = %d AND post_type = %s", $lastId, '_pods_field' ) );
if ( ! empty( $get_pods_fields ) ) :
foreach ( $get_pods_fields as $pods_field ) {
$get_pods_types = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM {$wpdb->prefix}postmeta where post_id = %d AND meta_key = %s", $pods_field->ID, 'type' ) );
$get_pods_object = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM {$wpdb->prefix}postmeta where post_id = %d AND meta_key = %s", $pods_field->ID, 'pick_object' ) );
$podsFields["PODS"][ $pods_field->post_name ]['label'] = $pods_field->post_name;
$podsFields["PODS"][ $pods_field->post_name ]['type'] = $get_pods_types[0]->meta_value;
if(isset($get_pods_object[0]->meta_value)){
$podsFields["PODS"][ $pods_field->post_name ]['pick_object']=$get_pods_object[0]->meta_value;
}
if($podsFields["PODS"][ $pods_field->post_name ]['type'] == 'pick'){
$get_pods_objecttype = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM {$wpdb->prefix}postmeta where post_id = %d AND meta_key = %s", $pods_field->ID, 'pick_format_type' ) );
$podsFields["PODS"][ $pods_field->post_name ]['pick_objecttype']=$get_pods_objecttype[0]->meta_value;
}
}
endif;
}
$createdFields = array();
foreach ($data_array as $dkey => $dvalue) {
$createdFields[] = $dkey;
}
foreach ($data_array as $custom_key => $custom_value) {
$plugin = 'pods';
if($podsFields["PODS"][$custom_key]['type'] == 'file' || $podsFields["PODS"][$custom_key]['type'] == 'avatar'){
if (strpos($custom_value, ',') !== false) {
$exploded_file_items = explode(',', $custom_value);
} elseif (strpos($custom_value, '|') !== false) {
$exploded_file_items = explode('|', $custom_value);
}
else{
$exploded_file_items[] = $custom_value;
}
$gallery_ids = array();
$indexs= 0;
foreach($exploded_file_items as $file) {
$file = trim($file);
$media_instance->store_image_ids($i=1);
$ext = pathinfo($file, PATHINFO_EXTENSION);
if(preg_match_all( '/\b(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)[-A-Z0-9+&@#\/%=~_|$?!:,.]*[A-Z0-9+&@#\/%=~_|$]/i', $file)){
$get_file_id = $media_instance->image_meta_table_entry($line_number ,'', $pID ,$custom_key, $file, $hash_key,'pods',$import_type,'','',$header_array, $value_array,'','',$indexs);
// $get_file_id = $media_instance->media_handling($file, $pID);
if($get_file_id != '') {
$gallery_ids[] = $get_file_id;
}
} else {
$galleryLen = strlen($file);
$checkgalleryid = intval($file);
$verifiedGalleryLen = strlen($checkgalleryid);
if($galleryLen == $verifiedGalleryLen) {
$gallery_ids[] = $file;
}
}
$indexs++;
}
if(in_array($importas, $list_taxonomy)){
update_term_meta($pID,$custom_key, $gallery_ids);
}
elseif($importas == 'Users'){
update_user_meta($pID, $custom_key, $gallery_ids);
}
elseif($importas == 'Comments'){
update_comment_meta($pID, $custom_key, $gallery_ids);
}
else{
update_post_meta($pID, $custom_key, $gallery_ids);
}
global $sitepress;
if($sitepress != null && is_plugin_active('wpml-ultimate-importer/wpml-ultimate-importer.php')){
$wpdb->prepare("UPDATE {$wpdb->prefix}posts SET post_parent = $pID WHERE ID = $gallery_ids[0]");
$image_id = $gallery_ids[0];
$meta_value = array('posts'=> array($pID));
update_post_meta( $image_id, '_wpml_media_usage', $meta_value);
}
}
elseif($podsFields["PODS"][$custom_key]['type'] == 'pick'){
$pick_obj=$podsFields["PODS"][$custom_key]['pick_object'];
$pick_objtype = $podsFields["PODS"][$custom_key]['pick_objecttype'];
$termitem = [];
$item = [];
$exploded_rel_items =array();
//$exploded_rel_items = explode(',', $custom_value);
if (strpos($custom_value, ',') !== false) {
$exploded_rel_items = explode(',', $custom_value);
} elseif (strpos($custom_value, '|') !== false) {
$exploded_rel_items = explode('|', $custom_value);
}
else{
$exploded_rel_items[] = $custom_value;
}
if($pick_obj == 'taxonomy'){
foreach($exploded_rel_items as $items){
if(is_numeric($items)){
$termitem[]=$items;
}
else{
$items = trim($items);
$ids = $wpdb->get_results( $wpdb->prepare( "SELECT term_id FROM {$wpdb->prefix}terms where name = %s ",$items) );
foreach($ids as $id){
$termitem[]=$id->term_id;
}
}
}
}
else{
foreach($exploded_rel_items as $items){
$items = trim($items);
if(!empty($items)){
$ids = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM {$wpdb->prefix}posts where post_title = %s and post_status=%s",$items,'publish') );
foreach($ids as $id){
$item[]=$id->ID;
}
}
}
}
if(in_array($importas, $list_taxonomy)){
update_term_meta($pID, $custom_key, $item);
}
elseif($importas == 'Users'){
update_user_meta($pID, $custom_key, $exploded_rel_items);
}
elseif($importas == 'Comments'){
update_comment_meta($pID, $custom_key, $exploded_rel_items);
}
else{
if($pick_obj=='custom-simple'){
update_post_meta($pID, $custom_key,$exploded_rel_items);
}
elseif($pick_obj=='taxonomy'){
update_post_meta($pID, $custom_key,$termitem);
}
elseif($pick_obj=='user'){
foreach($exploded_rel_items as $items){
if(is_numeric($items)){
$item[]=$items;
}
else{
$ids = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM {$wpdb->prefix}users where user_login = %s ",$items) );
foreach($ids as $id){
$item[]=$id->ID;
}
}
}
if($pick_objtype == 'multi'){
foreach($item as $key=>$value){
add_post_meta($pID, $custom_key,$value);
}
}
else{
foreach($item as $key=>$value){
$cust_key ='_pods_'. $custom_key;
$values[]=$value;
update_post_meta($pID, $cust_key,$values);
update_post_meta($pID, $custom_key,$value);
}
}
}
elseif(!empty($item)){
if($pick_objtype == 'multi'){
foreach($item as $key=>$value){
add_post_meta($pID, $custom_key,$value);
}
}
else{
foreach($item as $key=>$value){
update_post_meta($pID, $custom_key,$value);
}
}
}
}
}
else{
if(in_array($importas, $list_taxonomy)){
update_term_meta($pID, $custom_key, $custom_value);
}
/*elseif(!in_array($importas, $list_taxonomy)){
$wpdb->update($wpdb->prefix.'termmeta' , array('meta_value' => $custom_value ) , array('meta_key' => $custom_key , 'term_id' => $pID ));
}*/
elseif($importas == 'Users'){
update_user_meta($pID, $custom_key, $custom_value);
}
elseif($importas == 'Comments'){
update_comment_meta($pID, $custom_key, $custom_value);
}
else{
update_post_meta($pID, $custom_key, $custom_value);
}
}
}
return $createdFields;
}
}

View File

@@ -0,0 +1,223 @@
<?php
/**
* WP Ultimate CSV Importer plugin file.
*
* Copyright (C) 2010-2020, Smackcoders Inc - info@smackcoders.com
*/
namespace Smackcoders\FCSV;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class PolylangImport {
private static $polylang_instance = null;
public static function getInstance() {
if (PolylangImport::$polylang_instance == null) {
PolylangImport::$polylang_instance = new PolylangImport;
return PolylangImport::$polylang_instance;
}
return PolylangImport::$polylang_instance;
}
function set_polylang_values($header_array ,$value_array , $map, $post_id , $type){
$post_values = [];
$helpers_instance = ImportHelpers::getInstance();
$post_values = $helpers_instance->get_header_values($map , $header_array , $value_array);
$this->polylang_import_function($post_values,$type, $post_id);
}
function polylang_import_function($data_array, $importas,$pId) {
global $wpdb;
$term_id = $checkid = "";
$code = trim($data_array['language_code']);
$language = $wpdb->get_results("select term_id, term_taxonomy_id, description from {$wpdb->prefix}term_taxonomy where taxonomy ='language'");
$language_id = $wpdb->get_results($wpdb->prepare("select term_taxonomy_id from {$wpdb->prefix}term_relationships WHERE object_id = %d",$pId));
$listTaxonomy = get_taxonomies();
$lang_list = pll_languages_list();
if (in_array($importas, $listTaxonomy)) {
if(empty($code) || !in_array($code,$lang_list)){
$code=pll_default_language();
}
pll_set_term_language($pId, $code);
$arr = pll_get_term_translations($pId);
$translated_titles = explode(',',$data_array['translated_taxonomy_title']);
foreach($translated_titles as $translated_title){
$translated_post_id = $wpdb->get_var("SELECT term_id FROM {$wpdb->prefix}terms WHERE name ='$translated_title'");
$get_language = pll_get_term_language($translated_post_id);
$arr[$get_language] =$translated_post_id;
pll_save_term_translations( $arr );
}
}
else{
if(empty($code) || !in_array($code,$lang_list)){
$code=pll_default_language();
}
pll_set_post_language($pId, $code);
$arr = pll_get_post_translations($pId);
$translated_titles = explode(',',$data_array['translated_post_title']);
if($importas == 'WooCommerce Product Variations'){
$translated_titles = explode('|',$data_array['translated_post_title']);
}
else{
$translated_titles = explode(',',$data_array['translated_post_title']);
}
foreach($translated_titles as $translated_title){
$translated_post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->prefix}posts WHERE post_title = '$translated_title' and post_status='publish'");
if(!empty($translated_post_id)){
$get_language = pll_get_post_language($translated_post_id);
$arr[$get_language] =$translated_post_id;
pll_save_post_translations( $arr );
}
}
}
// foreach($language_id as $key=>$lang_ids){
// $taxonomy = $wpdb->get_results($wpdb->prepare("select taxonomy from {$wpdb->prefix}term_taxonomy where term_taxonomy_id = %d",$lang_ids->term_taxonomy_id));
// if(!empty($taxonomy)) {
// $language_name=$taxonomy[0];
// $lang_name=$language_name->taxonomy;
// }
// else {
// $lang_name = "";
// }
// if($lang_name == 'language'){
// $wpdb->get_results($wpdb->prepare("DELETE FROM {$wpdb->prefix}term_relationships WHERE object_id = %d and term_taxonomy_id = %d ",$pId,$lang_ids->term_taxonomy_id));
// }
// }
// foreach($language as $langkey => $langval){
// $description=unserialize($langval->description);
// $descript=explode('_',$description['locale']);
// $languages=$descript[0];
// if($languages == $code){
// $term_id=$langval->term_id;
// }
// }
// if(!empty($term_id)) {
// $wpdb->insert($wpdb->prefix.'term_relationships',array(
// 'term_taxonomy_id' => $term_id,
// 'object_id' => $pId
// ),
// array(
// '%s',
// '%s'
// )
// );
// }
// //$get_term=$wpdb->get_results($wpdb->prepare("select term_id from {$wpdb->prefix}terms where slug like %s ",'%-'.$code));
// $get_term=$wpdb->get_results($wpdb->prepare("select term_id from {$wpdb->prefix}terms where slug like %s ",$code));
// foreach($get_term as $keys =>$values){
// $id = $values->term_id;
// $wpdb->insert($wpdb->prefix.'term_relationships',array(
// 'term_taxonomy_id' => $id,
// 'object_id' => $pId
// ),
// array(
// '%s',
// '%s'
// )
// );
// }
// if($data_array['language_code']){
// $translatepost=isset($data_array['translated_post_title']) ? $data_array['translated_post_title'] : "";
// $child=$wpdb->get_results($wpdb->prepare("select ID from {$wpdb->prefix}posts where post_title = %s and post_status != %s order by ID desc",$translatepost,'trash'));
// $result_of_check = $wpdb->get_results("select description,term_id from {$wpdb->prefix}term_taxonomy where taxonomy='post_translations' ");
// $array=json_decode(json_encode($result_of_check),true);
// $trans_post_id = !empty($child) ? $child[0]->ID : "";
// $languageid = $wpdb->get_results($wpdb->prepare("select term_id from {$wpdb->prefix}terms where slug= %s",$code));
// $lang_id = !empty($languageid) ? $languageid[0]->term_id : "";
// if(!empty($lang_id)) {
// $langcount = $wpdb->get_results($wpdb->prepare("select count from {$wpdb->prefix}term_taxonomy where term_id= %d",$lang_id));
// $termcount=$langcount[0]->count;
// $termcount = $termcount + 1;
// $wpdb->update( $wpdb->term_taxonomy , array( 'count' => $termcount ) , array( 'term_id' => $lang_id ) );
// }
// foreach($array as $res_key => $res_val){
// $get_term_id = $array[$res_key]['term_id'];
// $description = unserialize($array[$res_key]['description']);
// $values = is_array($description)? array_values($description): array();
// if(is_array($values)){
// if (!empty($trans_post_id) && in_array($trans_post_id,$values)) {
// $checkid = $get_term_id;
// }
// }
// }
// if($checkid){
// $language=$wpdb->get_results("select term_id,description from {$wpdb->prefix}term_taxonomy where taxonomy ='language'");
// $wpdb->insert($wpdb->prefix.'term_relationships',array(
// 'term_taxonomy_id' => $checkid,
// 'object_id' => $pId
// ),
// array(
// '%s',
// '%s'
// )
// );
// $result=$wpdb->get_results($wpdb->prepare("select description from {$wpdb->prefix}term_taxonomy where term_id = %d",$checkid));
// $description=unserialize($result[0]->description);
// foreach($description as $desckey =>$descval){
// //insert with update
// $array2= array($code => $pId);
// $descript=array_merge($description,$array2);
// $count = count($descript);
// $description_data = serialize($descript);
// $wpdb->update( $wpdb->term_taxonomy , array( 'description' => $description_data ) , array( 'term_id' => $checkid ) );
// $wpdb->update( $wpdb->term_taxonomy , array( 'count' => $count ) , array( 'term_id' => $checkid ) );
// }
// }
// else{
// global $wpdb;
// $term_name=uniqid('pll_');
// $terms=wp_insert_term($term_name,'post_translations');
// $term_id=$terms['term_id'];
// $term_tax_id=$terms['term_taxonomy_id'];
// $language=$wpdb->get_results("select term_id,description from {$wpdb->prefix}term_taxonomy where taxonomy ='language'");
// $wpdb->insert($wpdb->prefix.'term_relationships',array(
// 'term_taxonomy_id' => $term_tax_id,
// 'object_id' => $pId
// ),
// array(
// '%s',
// '%s'
// )
// );
// $taxonomyid = $wpdb->get_results($wpdb->prepare("select term_taxonomy_id from {$wpdb->prefix}term_relationships where object_id = %d",$trans_post_id));
// foreach($taxonomyid as $key => $taxo_id){
// $tid = $taxo_id->term_taxonomy_id;
// $get_details = $wpdb->get_results($wpdb->prepare("select description,taxonomy from {$wpdb->prefix}term_taxonomy where term_taxonomy_id = %d",$tid));
// if(!empty($get_details) && $get_details[0]->taxonomy == 'language'){
// $description=unserialize($get_details[0]->description);
// $descript=explode('_',$description['locale']);
// $language = array_key_exists(0,$descript) ? $descript[0] : "";
// if(!empty($language)) {
// $array = array($language => $trans_post_id);
// $post_description=array_merge($array,array($code => $pId));
// $count=count($post_description);
// $description_data=serialize($post_description);
// $wpdb->update( $wpdb->term_taxonomy , array( 'description' => $description_data ) , array( 'term_id' => $term_id ) );
// $wpdb->update( $wpdb->term_taxonomy , array( 'count' => $count ) , array( 'term_id' => $term_id ) );
// }
// }
// }
// }
// }
}
}

View File

@@ -0,0 +1,39 @@
<?php
/**
* WP Ultimate CSV Importer plugin file.
*
* Copyright (C) 2010-2020, Smackcoders Inc - info@smackcoders.com
*/
namespace Smackcoders\FCSV;
use Smackcoders\FCSV\WooCommerceMetaImport;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class ProductAttrImport {
private static $product_attr_instance = null;
public static function getInstance() {
if (ProductAttrImport::$product_attr_instance == null) {
ProductAttrImport::$product_attr_instance = new ProductAttrImport;
return ProductAttrImport::$product_attr_instance;
}
return ProductAttrImport::$product_attr_instance;
}
function set_product_attr_values($header_array ,$value_array , $map ,$maps, $post_id, $variation_id,$type , $line_number , $mode , $hash_key, $wpml_map){
global $wpdb;
$woocommerce_meta_instance = WooCommerceMetaImport::getInstance();
$helpers_instance = ImportHelpers::getInstance();
$data_array = $helpers_instance->get_header_values($map , $header_array , $value_array);
$core_array = [];
$image_meta = [];
if(($type == 'WooCommerce Product') || ($type == 'WooCommerce Product Variations')){
$woocommerce_meta_instance->woocommerce_meta_import_function($data_array,$image_meta,$post_id ,$variation_id , $type , $line_number , $mode , $header_array, $value_array,'',$hash_key,'','');
}
}
}

View File

@@ -0,0 +1,39 @@
<?php
/**
* WP Ultimate CSV Importer plugin file.
*
* Copyright (C) 2010-2020, Smackcoders Inc - info@smackcoders.com
*/
namespace Smackcoders\FCSV;
use Smackcoders\FCSV\WooCommerceMetaImport;
if (!defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class ProductMetaImport {
private static $product_meta_instance = null;
public static function getInstance() {
if (ProductMetaImport::$product_meta_instance == null) {
ProductMetaImport::$product_meta_instance = new ProductMetaImport;
return ProductMetaImport::$product_meta_instance;
}
return ProductMetaImport::$product_meta_instance;
}
function set_product_meta_values($header_array ,$value_array , $map , $post_id ,$variation_id ,$type , $line_number , $mode,$hash_key,$selected_type=null){
global $wpdb;
$woocommerce_meta_instance = WooCommerceMetaImport::getInstance();
$helpers_instance = ImportHelpers::getInstance();
$data_array = [];
$data_array = $helpers_instance->get_header_values($map , $header_array , $value_array);
$image_meta = $helpers_instance->get_meta_values($map , $header_array , $value_array);
if(($type == 'WooCommerce Product') || ($type =='WooCommerce Product Variations')){
$woocommerce_meta_instance->woocommerce_meta_import_function($data_array,$image_meta,$post_id ,$variation_id , $type , $line_number , $mode , $header_array, $value_array,'',$hash_key,'','');
}
}
}

View File

@@ -0,0 +1,460 @@
<?php
/******************************************************************************************
* Copyright (C) Smackcoders. - All Rights Reserved under Smackcoders Proprietary License
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* You can contact Smackcoders at email address info@smackcoders.com.
*******************************************************************************************/
namespace Smackcoders\FCSV;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class RankMathImport {
private static $rankmath_instance = null;
public static function getInstance() {
if (RankMathImport::$rankmath_instance == null) {
RankMathImport::$rankmath_instance = new RankMathImport;
return RankMathImport::$rankmath_instance;
}
return RankMathImport::$rankmath_instance;
}
function set_rankmath_values($header_array ,$value_array , $map, $post_id , $type){
$post_values = [];
$helpers_instance = ImportHelpers::getInstance();
$post_values = $helpers_instance->get_header_values($map , $header_array , $value_array);
$this->rankmath_import_function($post_values,$type, $post_id, $header_array , $value_array);
}
function rankmath_import_function($data_array, $importas, $pID, $header_array , $value_array) {
global $wpdb;
$createdFields = $rankmathData = $property_details = $image_details = $speakable_details = $property_group_details = array();
$media_instance = MediaHandling::getInstance();
foreach ($data_array as $dkey => $dvalue) {
$createdFields[] = $dkey;
}
if (isset($data_array['rank_math_focus_keyword'])) {
$custom_array['rank_math_focus_keyword'] = $data_array['rank_math_focus_keyword'];
}
if (isset($data_array['rank_math_pillar_content'])) {
$custom_array['rank_math_pillar_content']= $data_array['rank_math_pillar_content'];
}
if (isset($data_array['rank_math_robots'])) {
$robots_meta= $data_array['rank_math_robots'];
$custom_array['rank_math_robots']=explode('|', $robots_meta);
}
if (isset($data_array['rank_math_advanced_robots'])) {
$rank_math_advanced_robots = $data_array['rank_math_advanced_robots'];
$rank_math_advanced=explode(',',$rank_math_advanced_robots);
$max_snippet=$rank_math_advanced[0];
$max_video_preview=$rank_math_advanced[1];
$max_image_preview=$rank_math_advanced[2];
$custom_array['rank_math_advanced_robots'] = [
'max-snippet' => $max_snippet,
'max-video-preview' => $max_video_preview,
'max-image-preview' => $max_image_preview,
];
}
if (isset($data_array['rank_math_canonical_url'])) {
$custom_array['rank_math_canonical_url']= $data_array['rank_math_canonical_url'];
}
if (isset($data_array['redirection_type'])) {
$redirection_type= $data_array['redirection_type'];
$redirection_table_name=$wpdb->prefix ."rank_math_redirections";
$destination_url= $data_array['destination_url'];
$sources=[
'ignore'=> '',
'pattern' => 'index.php'.'/'.date('y/d/m').'/'.$data_array['rank_math_focus_keyword'],
'comparison' => 'exact',
];
$from_url='index.php'.'/'.date('y/d/m').'/'.$data_array['rank_math_focus_keyword'];
$sourcess=array($sources);
$source=serialize($sourcess);
$wpdb->insert("{$wpdb->prefix}rank_math_redirections", array('sources' => $source,'url_to' => $destination_url,'header_code' => $redirection_type,'created'=>date('Y-m-d H:i:s'),'updated'=>date('Y-m-d H:i:s')));
$get_id=$wpdb->get_results("select id from {$wpdb->prefix}rank_math_redirections where url_to = '$destination_url'" ,ARRAY_A);
$redirection_id=$get_id[0]['id'];
$wpdb->insert("{$wpdb->prefix}rank_math_redirections_cache", array('from_url' => $from_url,'redirection_id' => $redirection_id,'object_id' => $pID,'is_redirected'=>'1'));
}
if (isset($data_array['headline'])) {
$headline= $data_array['headline'];
}
if (isset($data_array['schema_description'])) {
$schema_description = $data_array['schema_description'];
}
if (isset($data_array['article_type'])) {
$article_type= $data_array['article_type'];
}
if(isset($data_array['image_type'])){
$image_type=$data_array['image_type'];
}
if(isset($data_array['image_url'])){
$image_url=$data_array['image_url'];
}
if(isset($data_array['author_type'])){
$author_type=$data_array['author_type'];
}
if(isset($data_array['author_name'])){
$author_name=$data_array['author_name'];
}
if(isset($data_array['enable_speakable'])){
$enable_speakable=$data_array['enable_speakable'];
}
if(isset($data_array['speakable_type'])){
$speakable_type=$data_array['speakable_type'];
}
if(isset($data_array['date_modified'])){
$date_modified=$data_array['date_modified'];
}
if(isset($data_array['date_published'])){
$date_published=$data_array['date_published'];
}
if(isset($data_array['cssSelector'])){
$cssSelector=$data_array['cssSelector'];
}
if(isset($data_array['advanced_editor'])){
$advanced_editor_value=$data_array['advanced_editor'];
$values=explode('|',$advanced_editor_value);
foreach($values as $value){
$advanced_value=explode('->',$value);
$editor_values=$advanced_value[0];
if($editor_values == 'image'){
$editor_value=$advanced_value[1];
$image_values=explode(';',$editor_value);
$image_details=array();
foreach($image_values as $img_values){
$img_value=explode(':',$img_values);
$image_key=$img_value[0];
$image_value=$img_value[1];
$image_details[$image_key]=$image_value;
}
}
else if($editor_values == 'author'){
$editor_value=$advanced_value[1];
$author_values=explode(';',$editor_value);
$author_details=array();
foreach($author_values as $auth_values){
$auth_value=explode(':',$auth_values);
$author_key=$auth_value[0];
$author_value=$auth_value[1];
$author_details[$author_key]=$author_value;
}
}
else if($editor_values == 'speakable'){
$editor_value=$advanced_value[1];
$speakable_values=explode(';',$editor_value);
$speakable_details=array();
foreach($speakable_values as $speak_values){
$speak_value=explode(':',$speak_values);
$speakable_key=$speak_value[0];
$speakable_value=$speak_value[1];
$speakable_details[$speakable_key]=$speakable_value;
}
}
else{
$editor_value=$advanced_value[1];
$new_property=explode(';',$editor_value);
$property_details=array();
foreach($new_property as $property){
$new_property_value=explode(':',$property);
$property_key=$new_property_value[0];
$property_value=$new_property_value[1];
$property_details[$property_key]=$property_value;
}
}
}
}
if(isset($data_array['advanced_editor_group_values'])){
$advanced_editor_group_values=$data_array['advanced_editor_group_values'];
$values=explode('|',$advanced_editor_group_values);
foreach($values as $value){
$advanced_group_value=explode('->',$value);
$group_editor_values=$advanced_group_value[0];
if($group_editor_values == 'image'){
$editor_group_value=$advanced_group_value[1];
$editor_values=explode(',',$editor_group_value);
foreach($editor_values as $editor_value){
$image_group_values=explode(';',$editor_value);
$image_detail=array();
foreach($image_group_values as $img_group_values){
$img_group_value=explode(':',$img_group_values);
$image_group_key=$img_group_value[0];
$image_group_value=$img_group_value[1];
$image_detail[$image_group_key]=$image_group_value;
}
$image_group_details[] = $image_detail;
}
}
else if($group_editor_values == 'author'){
$editor_group_value=$advanced_group_value[1];
$editor_values=explode(',',$editor_group_value);
foreach($editor_values as $editor_value){
$author_group_values=explode(';',$editor_value);
$author_detail=array();
foreach($author_group_values as $auth_group_values){
$auth_group_value=explode(':',$auth_group_values);
$author_group_key=$auth_group_value[0];
$author_group_value=$auth_group_value[1];
$author_detail[$author_group_key]=$author_group_value;
}
$author_group_details[] = $author_detail;
}
}
else if($group_editor_values == 'speakable'){
$editor_group_value=$advanced_group_value[1];
$editor_values=explode(',',$editor_group_value);
foreach($editor_values as $editor_value){
$speakable_group_values=explode(';',$editor_value);
$speakable_detail=array();
foreach($speakable_group_values as $speak_group_values){
$speak_group_value=explode(':',$speak_group_values);
$speakable_group_key=$speak_group_value[0];
$speakable_group_value=$speak_group_value[1];
$speakable_detail[$speakable_group_key]=$speakable_group_value;
}
$speakable_group_details[] = $speakable_detail;
}
}
else{
$editor_group_value=$advanced_group_value[1];
$editor_values=explode(',',$editor_group_value);
foreach($editor_values as $editor_value){
$new_property_group=explode(';',$editor_value);
$property_detail=array();
foreach($new_property_group as $property_group){
$new_property_group_value=explode(':',$property_group);
$property_group_key=$new_property_group_value[0];
$property_group_value=$new_property_group_value[1];
$property_detail[$property_group_key]=$property_group_value;
}
$property_group_details[] = $property_detail;
}
}
}
}
if (isset($data_array['cssSelector'])) {
$selector=explode(',',$cssSelector);
}
if(is_plugin_active('seo-by-rank-math-pro/rank-math-pro.php')){
$key=array("headline","description","@type","enableSpeakable","datePublished","dateModified");
if(!empty($headline)&& !empty($schema_description)&& !empty($article_type)&& !empty($enable_speakable) && !empty($date_published)&& !empty($date_modified)){
$rank_math_schema=array($headline,$schema_description,$article_type,$enable_speakable,$date_published,$date_modified);
}
if(isset($rank_math_schema)){
$rank_math_schem=array_combine($key,$rank_math_schema);
$rank_math=array_merge($rank_math_schem,$property_details,$property_group_details);
}
//image details
$image_key=array("@type","url");
if(!empty($image_type)){
$schema_values=array($image_type,$image_url);
}
if(isset($schema_values)){
$schema_value=array_combine($image_key,$schema_values);
}
if(isset($image_details) && isset($image_group_details)){
$schema['image']=array_merge($schema_value,$image_details,$image_group_details);
}
//author details
$author_key=array("@type","name");
if(!empty($author_type) && !empty($author_name)){
$author_values=array($author_type,$author_name);
$author_value=array_combine($author_key,$author_values);
$author['author']=array_merge($author_value,$author_details,$author_group_details);
}
//speakable details
$speakable_key=array("@type","cssSelector");
if(!empty($speakable_type) && !empty($selector)){
$speakable_values=array($speakable_type,$selector);
$speakable_value=array_combine($speakable_key,$speakable_values);
$speakable['speakable']=array_merge($speakable_value,$speakable_details,$speakable_group_details);
}
$enable_speakable = isset($enable_speakable)?$enable_speakable:'';
$schems['metadata']=[
'title' => 'Article' ,
'type' => 'template',
'shortcode' => uniqid( 's-' ),
'isPrimary' => true,
'enableSpeakable'=>$enable_speakable,
];
if(isset($schema) && is_array($schema) && is_array($rank_math) && is_array($speakable) && is_array($author)){
$array_rank_math=array_merge($schems,$schema,$rank_math,$speakable,$author);
update_post_meta($pID, 'rank_math_schema_BlogPosting', $array_rank_math);
}
$schems['metadata']=[
'title' => 'Dataset' ,
'type' => 'template',
'shortcode' => uniqid( 's-' ),
'isPrimary' => true,
];
$dataset_basic = [
'@type' => 'Dataset',
'name' => $data_array['ds_name'],
'description' => $data_array['ds_description'],
'url' => $data_array['ds_url'],
'sameAs' => $data_array['ds_sameAs'],
'license' => $data_array['ds_license'],
'identifier' => explode(',',$data_array['ds_identifier']),
'keywords' => explode(',',$data_array['ds_keywords']),
'includedInDataCatalog' => [
'@type' => 'DataCatalog',
'name' => $data_array['ds_cat_name']
],
'temporalCoverage' => $data_array['ds_temp_coverage'],
'spatialCoverage' => $data_array['ds_spatial_coverage']
];
$encoding_formats = explode(',',$data_array['encodingFormat']);
$content_urls = explode(',', $data_array['contentUrl']);
$dataset_distribution = ['distribution' => []];
foreach ($encoding_formats as $index => $format) {
$dataset_distribution['distribution'][] = [
'@type' => 'DataDownload',
'encodingFormat' => $format,
'contentUrl' => $content_urls[$index] ?? '',
];
}
// Merge all arrays to form the complete dataset schema
$dataset_schema = array_merge(
$schems,
$dataset_basic,
$dataset_distribution,
);
update_post_meta( $pID, 'rank_math_schema_Dataset', $dataset_schema );
}
else{
$key=array("headline","description","@type");
$rank_math_schema=array($headline,$schema_description,$article_type);
$rank_math=array_combine($key,$rank_math_schema);
$schems['metadata']=[
'title' => 'Article' ,
'type' => 'template',
'shortcode' => uniqid( 's-' ),
'isPrimary' => true,
];
$author['author']=[
'@type'=>'Person',
'name'=>'%name%',
];
$date_variables = [
'datePublished' => '%date(Y-m-dTH:i:sP)%',
'dateModified' => '%modified(Y-m-dTH:i:sP)%',
];
$schema['image'] = [
'@type' => 'ImageObject',
'url' => '%post_thumbnail%',
];
$custom_array['rank_math_schema_BlogPosting']=array_merge($schems,$schema,$rank_math,$author,$date_variables);
}
if (isset($data_array['rank_math_title'])) {
$custom_array['rank_math_title']= $data_array['rank_math_title'];
}
if (isset($data_array['_wp_old_slug'])) {
$custom_array['_wp_old_slug']= $data_array['_wp_old_slug'];
}
if (isset($data_array['rank_math_description'])) {
$custom_array['rank_math_description'] = $data_array['rank_math_description'];
}
if (isset($data_array['rank_math_facebook_title'])) {
$custom_array['rank_math_facebook_title']= $data_array['rank_math_facebook_title'];
}
if (isset($data_array['rank_math_facebook_description'])) {
$custom_array['rank_math_facebook_description'] = $data_array['rank_math_facebook_description'];
}
if (isset($data_array['rank_math_facebook_image'])) {
$custom_array['rank_math_facebook_image'] = $data_array['rank_math_facebook_image'];
}
if (isset($data_array['rank_math_facebook_enable_image_overlay'])) {
$custom_array['rank_math_facebook_enable_image_overlay'] = $data_array['rank_math_facebook_enable_image_overlay'];
}
if (isset($data_array['rank_math_facebook_image_overlay'])) {
$custom_array['rank_math_facebook_image_overlay']= $data_array['rank_math_facebook_image_overlay'];
}
if (isset($data_array['rank_math_twitter_use_facebook'])) {
$custom_array['rank_math_twitter_use_facebook'] = $data_array['rank_math_twitter_use_facebook'];
}
if (isset($data_array['rank_math_twitter_card_type'])) {
$custom_array['rank_math_twitter_card_type'] = $data_array['rank_math_twitter_card_type'];
}
if(isset($data_array['rank_math_twitter_app_description'])) {
$custom_array['rank_math_twitter_app_description'] = $data_array['rank_math_twitter_app_description'];
}
if(isset($data_array['rank_math_twitter_app_iphone_name'])) {
$custom_array['rank_math_twitter_app_iphone_name'] = $data_array['rank_math_twitter_app_iphone_name'];
}
if(isset($data_array['rank_math_twitter_app_iphone_id'])) {
$custom_array['rank_math_twitter_app_iphone_id']= $data_array['rank_math_twitter_app_iphone_id'];
}
if(isset($data_array['rank_math_twitter_app_iphone_url'])) {
$custom_array['rank_math_twitter_app_iphone_url']= $data_array['rank_math_twitter_app_iphone_url'];
}
if(isset($data_array['rank_math_twitter_app_ipad_name'])) {
$custom_array['rank_math_twitter_app_ipad_name']= $data_array['rank_math_twitter_app_ipad_name'];
}
if(isset($data_array['rank_math_twitter_app_ipad_id'])) {
$custom_array['rank_math_twitter_app_ipad_id'] = $data_array['rank_math_twitter_app_ipad_id'];
}
if(isset($data_array['rank_math_twitter_app_ipad_url'])) {
$custom_array['rank_math_twitter_app_ipad_url']= $data_array['rank_math_twitter_app_ipad_url'];
}
if(isset($data_array['rank_math_twitter_app_googleplay_name'])) {
$custom_array['rank_math_twitter_app_googleplay_name']= $data_array['rank_math_twitter_app_googleplay_name'];
}
if(isset($data_array['rank_math_twitter_app_googleplay_id'])) {
$custom_array['rank_math_twitter_app_googleplay_id']= $data_array['rank_math_twitter_app_googleplay_id'];
}
if(isset($data_array['rank_math_twitter_app_googleplay_url'])) {
$custom_array['rank_math_twitter_app_googleplay_url']= $data_array['rank_math_twitter_app_googleplay_url'];
}
if(isset($data_array['rank_math_twitter_app_country'])) {
$custom_array['rank_math_twitter_app_country']= $data_array['rank_math_twitter_app_country'];
}
if(isset($data_array['rank_math_twitter_player_url'])) {
$custom_array['rank_math_twitter_player_url'] = $data_array['rank_math_twitter_player_url'];
}
if(isset($data_array['rank_math_twitter_player_size'])) {
$custom_array['rank_math_twitter_player_size']= $data_array['rank_math_twitter_player_size'];
}
if(isset($data_array['rank_math_twitter_player_stream'])) {
$custom_array['rank_math_twitter_player_stream']= $data_array['rank_math_twitter_player_stream'];
}
if(isset($data_array['rank_math_twitter_player_stream_ctype'])) {
$custom_array['rank_math_twitter_player_stream_ctype']= $data_array['rank_math_twitter_player_stream_ctype'];
}
if (!empty ($custom_array)) {
foreach ($custom_array as $custom_key => $custom_value) {
update_post_meta($pID, $custom_key, $custom_value);
}
}
}
}

View File

@@ -0,0 +1,48 @@
<?php
/******************************************************************************************
* Copyright (C) Smackcoders. - All Rights Reserved under Smackcoders Proprietary License
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* You can contact Smackcoders at email address info@smackcoders.com.
*******************************************************************************************/
namespace Smackcoders\FCSV;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class SeoPressImport {
private static $seopress_instance = null;
public static function getInstance() {
if (SeoPressImport::$seopress_instance == null) {
SeoPressImport::$seopress_instance = new SeoPressImport;
return SeoPressImport::$seopress_instance;
}
return SeoPressImport::$seopress_instance;
}
function set_seopress_values($header_array ,$value_array , $map, $post_id , $type, $hash_key,$gmode,$templatekey){
$post_values = [];
$helpers_instance = ImportHelpers::getInstance();
$post_values = $helpers_instance->get_header_values($map , $header_array , $value_array);
$this->seopress_import_function($post_values,$type, $post_id, $header_array , $value_array, $hash_key,$gmode,$templatekey);
}
function seopress_import_function($data_array, $importas, $pID, $header_array , $value_array, $hash_key,$gmode,$templatekey) {
$createdFields = $seoPressData = array();
$media_instance = MediaHandling::getInstance();
if (!empty ($data_array)) {
foreach ($data_array as $dataKey => $dataValue) {
update_post_meta($pID, $dataKey, $dataValue);
}
}
return $createdFields;
}
}

View File

@@ -0,0 +1,180 @@
<?php
/**
* WP Ultimate CSV Importer plugin file.
*
* Copyright (C) 2010-2020, Smackcoders Inc - info@smackcoders.com
*/
namespace Smackcoders\FCSV;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class TaxonomiesImport {
private static $taxonomies_instance = null;
public static function getInstance() {
if (TaxonomiesImport::$taxonomies_instance == null) {
TaxonomiesImport::$taxonomies_instance = new TaxonomiesImport;
return TaxonomiesImport::$taxonomies_instance;
}
return TaxonomiesImport::$taxonomies_instance;
}
public function taxonomies_import_function ($data_array, $mode, $importType , $unmatched_row, $check , $unikey_value , $unikey_name , $line_number ,$header_array ,$value_array) {
$returnArr = array();
$mode_of_affect = 'Inserted';
global $wpdb;
$helpers_instance = ImportHelpers::getInstance();
$core_instance = CoreFieldsImport::getInstance();
$media_instance = MediaHandling::getInstance();
global $core_instance;
$log_table_name = $wpdb->prefix ."import_detail_log";
$events_table = $wpdb->prefix."em_meta" ;
$updated_row_counts = $helpers_instance->update_count($unikey_value , $unikey_name);
$created_count = $updated_row_counts['created'];
$updated_count = $updated_row_counts['updated'];
$skipped_count = $updated_row_counts['skipped'];
$terms_table = $wpdb->term_taxonomy;
//$taxonomy = $importAs;
$taxonomy = $importType;
$term_children_options = get_option("$taxonomy" . "_children");
$_name = isset($data_array['name']) ? $data_array['name'] : '';
$_slug = isset($data_array['slug']) ? $data_array['slug'] : '';
$_desc = isset($data_array['description']) ? $data_array['description'] : '';
$_image = isset($data_array['image']) ? $data_array['image'] : '';
$_parent = isset($data_array['parent']) ? $data_array['parent'] : '';
$_display_type = isset($data_array['display_type']) ? $data_array['display_type'] : '';
$_color = isset($data_array['color']) ? $data_array['color'] : '';
$_top_content = isset($data_array['top_content']) ? $data_array['top_content'] : '';
$_bottom_content = isset($data_array['bottom_content']) ? $data_array['bottom_content'] : '';
$get_category_list = array();
// if (strpos($_name, ',') !== false) {
// $get_category_list = explode(',', $_name);
// }
if (strpos($_name, '>') !== false) {
$get_category_list = explode('>', $_name);
} else {
$get_category_list[] = trim($_name);
}
$parent_term_id = 0;
$termID = '';
if (count($get_category_list) == 1) {
$_name = trim($get_category_list[0]);
if($_parent){
$get_parent = term_exists("$_parent", "$taxonomy");
$parent_term_id = $get_parent['term_id'];
}
else{
// $termid_value = $wpdb->get_results("SELECT term_id FROM {$wpdb->prefix}terms WHERE slug = '$_slug'");
$termid_value = $wpdb->get_results($wpdb->prepare("SELECT term.term_id FROM {$wpdb->prefix}terms AS term INNER JOIN {$wpdb->prefix}term_taxonomy AS tax ON term.term_id = tax.term_id WHERE term.slug = %s AND tax.taxonomy = %s", $_slug, $taxonomy));
if(isset($termid_value[0]->term_id)){
$termid_val = $termid_value[0]->term_id;
$term_parent_value = $wpdb->get_results("SELECT parent FROM {$wpdb->prefix}term_taxonomy WHERE term_id = '$termid_val'");
$parent_term_id = $term_parent_value[0]->parent;
}
}
} else {
$count = count($get_category_list);
$_name = trim($get_category_list[$count - 1]);
$checkParent = trim($get_category_list[$count - 2]);
$parent_term = term_exists("$checkParent", "$taxonomy");
$parent_term_id = $parent_term['term_id'];
}
if($check == 'termid'){
$termID = $data_array['TERMID'];
}
if($check == 'slug'){
$get_termid = get_term_by( "slug" ,"$_slug" , "$taxonomy");
$termID = $get_termid->term_id;
}
if($_display_type){
$_display_type = $_display_type;
}else{
// $term_id_value = $wpdb->get_results("SELECT term_id FROM {$wpdb->prefix}terms WHERE slug = '$_slug'");
$term_id_value =$wpdb->get_results($wpdb->prepare("SELECT term.term_id FROM {$wpdb->prefix}terms AS term INNER JOIN {$wpdb->prefix}term_taxonomy AS tax ON term.term_id = tax.term_id WHERE term.slug = %s AND tax.taxonomy = %s", $_slug, $taxonomy));
if(isset($term_id_value[0]->term_id)){
$term_id_val = $term_id_value[0]->term_id;
// $term_display_type_value = $wpdb->get_results("SELECT display_type FROM {$wpdb->prefix}termmeta WHERE term_id = '$term_id_val'");
// $_display_type = $term_display_type_value[0]->display_type;
$term_display_type_value = $wpdb->get_results("SELECT meta_value FROM {$wpdb->prefix}termmeta WHERE term_id = '$term_id_val' AND meta_key = 'display_type' ");
if(!empty($term_display_type_value)){
$_display_type = $term_display_type_value[0]->meta_value;
}
}
}
if($mode == 'Insert'){
if(!empty($termID)){
$core_instance->detailed_log[$line_number]['Message'] = "Skipped, Due to duplicate Term found!.";
$core_instance->detailed_log[$line_number]['cat_name'] = $_name;
$wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey_value'");
return array('MODE' => $mode, 'ERROR_MSG' => 'The term already exists!');
}else{
$taxoID = wp_insert_term("$_name", "$taxonomy", array('description' => $_desc, 'slug' => $_slug));
if(is_wp_error($taxoID)){
$core_instance->detailed_log[$line_number]['Message'] = "Can't insert this " . $taxonomy . ". " . $taxoID->get_error_message();
$core_instance->detailed_log[$line_number]['state'] = 'Skipped';
$core_instance->detailed_log[$line_number]['cat_name'] = $_name;
$wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey_value'");
}else{
$termID= $taxoID['term_id'];
$date = date("Y-m-d H:i:s");
if(isset($_image)){
$media_instance->store_image_ids($i=1);
$imageid = $media_instance->media_handling($_image , $termID ,$data_array ,'','','',$header_array ,$value_array);
//$imageid = $media_instance->image_meta_table_entry('', $termID, 'thumbnail_id', $_image, $hash_key, 'term', 'term',$templatekey);
if($importType == 'product_cat'){
add_term_meta($termID , 'thumbnail_id' , $imageid);
}
}
if(isset($_display_type)){
add_term_meta($termID , 'display_type' , $_display_type);
}
if(isset($parent_term_id)){
$update = $wpdb->get_results("UPDATE $terms_table SET `parent` = $parent_term_id WHERE `term_id` = $termID ");
}
$returnArr = array('ID' => $termID, 'MODE' => $mode_of_affect);
$core_instance->detailed_log[$line_number]['Message'] = 'Inserted ' . $taxonomy . ' ID: ' . $termID;
$core_instance->detailed_log[$line_number]['state'] = 'Inserted';
$core_instance->detailed_log[$line_number]['cat_name'] = $_name;
$core_instance->detailed_log[$line_number]['id'] = $termID;
$wpdb->get_results("UPDATE $log_table_name SET created = $created_count WHERE $unikey_name = '$unikey_value'");
}
}
if($unmatched_row == 'true'){
global $wpdb;
$post_entries_table = $wpdb->prefix ."post_entries_table";
$file_table_name = $wpdb->prefix."smackcsv_file_events";
$get_id = $wpdb->get_results( "SELECT file_name FROM $file_table_name WHERE $unikey_name = '$unikey_value'");
$file_name = $get_id[0]->file_name;
$wpdb->get_results("INSERT INTO $post_entries_table (`ID`,`type`, `file_name`,`status`) VALUES ( '{$termID}','{$type}', '{$file_name}','Inserted')");
}
}
if(!is_wp_error($termID)) {
update_option("$taxonomy" . "_children", $term_children_options);
delete_option($taxonomy . "_children");
}
return $returnArr;
}
}

View File

@@ -0,0 +1,448 @@
<?php
/**
* WP Ultimate CSV Importer plugin file.
*
* Copyright (C) 2010-2020, Smackcoders Inc - info@smackcoders.com
*/
namespace Smackcoders\FCSV;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class TermsandTaxonomiesImport {
private static $terms_taxo_instance = null;
public static function getInstance() {
if (TermsandTaxonomiesImport::$terms_taxo_instance == null) {
TermsandTaxonomiesImport::$terms_taxo_instance = new TermsandTaxonomiesImport;
return TermsandTaxonomiesImport::$terms_taxo_instance;
}
return TermsandTaxonomiesImport::$terms_taxo_instance;
}
function set_terms_taxo_values($header_array ,$value_array , $map, $post_id , $type, $mode , $line_number,$poly_array = null){
$post_values = [];
$helpers_instance = ImportHelpers::getInstance();
$post_values = $helpers_instance->get_header_values($map , $header_array , $value_array);
$poly_values = $helpers_instance->get_header_values($poly_array , $header_array , $value_array);
$this->terms_taxo_import_function($post_values,$type, $post_id , $mode , $line_number,$poly_values);
}
public function terms_taxo_import_function ($data_array, $type ,$pID , $mode , $line_number,$poly_values) {
$core_instance = CoreFieldsImport::getInstance();
$helpers_instance = ImportHelpers::getInstance();
global $core_instance;
if ($type == 'WooCommerce Product') {
if ($mode == 'Update') {
if (empty($data_array['product_category'])) {
$categories = wp_get_post_terms($pID, 'product_cat', array('fields' => 'names'));
$data_array['product_category'] = !empty($categories) ? implode(', ', $categories) : 'Uncategorized';
}
} else {
$data_array['product_category'] = empty($data_array['product_category']) ? 'Uncategorized' : $data_array['product_category'];
}
$uncategorized = get_term_by( 'name', 'Uncategorized', 'product_cat' );
if ( $uncategorized && ! is_wp_error( $uncategorized ) ) {
wp_remove_object_terms( $pID, (int) $uncategorized->term_id, 'product_cat' );
}
}
unset($data_array['post_format']);
unset($data_array['product_type']);
$categories = $tags = array();
foreach ($data_array as $termKey => $termVal) {
$smack_taxonomy = array();
switch ($termKey) {
case 'post_category' :
$categories [$termKey] = $data_array [$termKey];
if(preg_match("(Can't|Skipped|Duplicate)", $core_instance->detailed_log[$line_number]['Message']) === 0) {
$core_instance->detailed_log[$line_number]['Categories'] = $data_array[$termKey];
}
$category_name = 'category';
if($mode == 'Update'){
$categories_before = wp_get_object_terms($pID, 'category');
foreach($categories_before as $category_before){
wp_remove_object_terms($pID, $category_before->name , 'category');
}
}
// Create / Assign categories to the post types
if(isset($categories[$termKey]) && $categories[$termKey] != '')
$this->assignTermsAndTaxonomies($categories, $category_name, $pID,$poly_values);
//Get Default Category id
$default_category_id = get_option('default_category');
//Get Default Category Name
$default_category_details = get_term_by('id', $default_category_id , 'category');
//Remove Default Category
$categories = wp_get_object_terms($pID, 'category');
if (count($categories) > 1) {
foreach ($categories as $key => $category) {
if ((!empty($category) && !empty($default_category_details)) && $category->name == $default_category_details->name ) {
wp_remove_object_terms($pID, $default_category_details->name , 'category');
}
}
}
break;
case 'post_tag' :
$tags [$termKey] = $data_array [$termKey];
if(preg_match("(Can't|Skipped|Duplicate)", $core_instance->detailed_log[$line_number]['Message']) === 0){
$core_instance->detailed_log[$line_number]['Tags'] = $data_array[$termKey];
}
$tag_name = 'post_tag';
break;
case 'product_tag':
$tags [$termKey] = $data_array [$termKey];
if(preg_match("(Can't|Skipped|Duplicate)", $core_instance->detailed_log[$line_number]['Message']) === 0){
$core_instance->detailed_log[$line_number]['Tags'] = $data_array[$termKey];
}
$tag_name = 'product_tag';
break;
case 'product_category':
if($type == 'WooCommerce Product')
$category_name = 'product_cat';
if($type == 'WPeCommerce Products')
$category_name = 'wpsc_product_category';
else
$category_name = 'product_cat';
$categories [$termKey] = $data_array [$termKey];
if(preg_match("(Can't|Skipped|Duplicate)", $core_instance->detailed_log[$line_number]['Message']) === 0){
$core_instance->detailed_log[$line_number]['Categories'] = $data_array[$termKey];
}
// Create / Assign categories to the post types
if(isset($categories[$termKey]) && $categories[$termKey] != '')
$this->assignTermsAndTaxonomies($categories, $category_name, $pID,$poly_values);
break;
case 'event_tags':
$eventtags [$termKey] = $data_array [$termKey];
if(!empty($eventtags)){
if(preg_match("(Can't|Skipped|Duplicate)", $core_instance->detailed_log[$line_number]['Message']) === 0){
$core_instance->detailed_log[$line_number]['Tags'] = $data_array[$termKey];
}
foreach($eventtags as $e_key => $e_value){
if(!empty($e_value)){
if (strpos($e_value, ',') !== false) {
$split_etag = explode(',', $e_value);
} else {
$split_etag = $e_value;
}
if(is_array($split_etag)) {
foreach($split_etag as $item) {
$etagData[] = (string)$item;
}
} else {
$etagData = (string)$split_etag;
}
wp_set_object_terms($pID, $etagData,'event-tags');
}
}
}
break;
case 'event_categories':
$event_categories [$termKey] = $data_array [$termKey];
if(!empty($event_categories)) {
if(preg_match("(Can't|Skipped|Duplicate)", $core_instance->detailed_log[$line_number]['Message']) === 0){
$core_instance->detailed_log[$line_number]['Categories'] = $data_array[$termKey];
}
foreach($event_categories as $ec_key => $ec_value){
if(!empty($ec_value)) {
if (strpos($ec_value, ',') !== false) {
$split_ecat = explode(',', $ec_value);
} else {
$split_ecat = $ec_value;
}
if(is_array($split_ecat)) {
foreach($split_ecat as $item) {
$ecatData[] = (string)$item;
}
} else {
$ecatData = (string)$split_ecat;
}
wp_set_object_terms($pID, $ecatData,'event-categories');
}
}
}
break;
default :
$smack_taxonomy[$termKey] = $data_array[$termKey];
if($termKey != 'post_format')
$term_space = '&nbsp'.$termKey;
$core_instance->detailed_log[$line_number][$term_space] = $data_array[$termKey] ;
$taxonomy_name = $termKey;
// Create / Assign taxonomies to the post types
if(isset($smack_taxonomy[$termKey]) && $smack_taxonomy[$termKey] != '')
$this->assignTermsAndTaxonomies($smack_taxonomy, $taxonomy_name, $pID,$poly_values);
break;
}
}
// Create / Assign tags to the post types
if (!empty ($tags)) {
foreach ($tags as $tag_key => $tag_value) {
if (!empty($tag_value)) {
if (strpos($tag_value, ',') !== false) {
$split_tag = explode(',', $tag_value);
} else {
$split_tag = $tag_value;
}
if(is_array($split_tag)) {
foreach($split_tag as $item) {
$tag_list[] = $item;
}
} else {
$tag_list = $split_tag;
}
wp_set_object_terms($pID, $tag_list, $tag_name);
}
}
}
}
public function assignTermsAndTaxonomies($categories, $category_name, $pID,$poly_values = '') {
if(!empty($poly_values)){
$lang_list = pll_languages_list();
}
$get_category_list = $category_list = array();
// Create / Assign categories to the post types
if (!empty($categories)) {
foreach ( $categories as $cat_key => $cat_value ) {
if (strpos($cat_value, ',') !== false) {
$get_category_list = explode(',', $cat_value);
} else {
$get_category_list[] = $cat_value;
}
}
}
if(!empty($get_category_list)) {
$i = 0;
foreach($get_category_list as $key => $value) {
if (strpos($value, '>') !== false) {
$split_line = explode('>', $value);
if(is_array($split_line)) {
foreach($split_line as $category) {
$category_list[$i][] = $category;
}
}
} else {
$category_list[$i][] = $value;
}
$i++;
}
}
foreach($category_list as $index => $category_set) {
foreach ( $category_set as $item => $category_value ) {
$term_children_options= get_option( "$category_name" . "_children" );
$parentTerm = $item;
$termName = trim( $category_value );
$_name = (string) $termName;
$_slug = preg_replace( '/\s\s+/', '-', strtolower( $_name ) );
// Check if the current category is a parent
$is_parent = true;
if (!empty($category_set[1]) && isset($category_set[1]) && $item == 0) {
// The first category in the set is a parent
$is_parent = false;
}
$checkAvailable = array();
$checkSuperParent = $checkParent1 = $checkParent2 = null;
$super_parent_term_id = $parent_term_id1 = $parent_term_id2 = 0;
if ( $parentTerm != 0 ) {
if ( isset( $category_set[ $item - 1 ] ) ) {
$checkParent1 = trim( $category_set[ $item - 1 ] );
$checkParent1 = (string) $checkParent1;
// $parent_term = term_exists( "$checkParent1", "$category_name" );
$parent_new =get_term_by('name',$category_set[ $item - 2],$category_name);
$parents_id=$parent_new->term_id;
$parent_term = term_exists( "$checkParent1", "$category_name", $parents_id);
if ( isset( $parent_term['term_id'] ) ) {
$parent_term_id1 = $parent_term['term_id'];
}
}
if ( isset( $category_set[ $item - 2 ] ) ) {
// $parent_term_id1 = 0;
$checkSuperParent = trim( $category_set[ $item - 2 ] );
$checkSuperParent = (string) $checkSuperParent;
$super_parent_term = term_exists( "$checkSuperParent", "$category_name" );
if ( isset( $super_parent_term['term_id'] ) ) {
$super_parent_term_id = $super_parent_term['term_id'];
}
$checkParent2 = trim( $category_set[ $item - 1 ] );
$checkParent2 = (string) $checkParent2;
$parent_term = term_exists( "$checkParent2", "$category_name", $super_parent_term_id );
if ( isset( $parent_term['term_id'] ) ) {
$parent_term_id2 = $parent_term['term_id'];
}
}
}
if ( $super_parent_term_id != 0 ) {
if ( $parent_term_id2 == 0 ) {
$checkAvailable = term_exists( "$checkParent2", "$category_name" );
if ( ! is_array( $checkAvailable ) ) {
$taxonomyID = wp_insert_term( "$checkParent2", "$category_name", array(
'description' => '',
'slug' => $_slug,
'parent' => $super_parent_term_id
) );
if(!is_wp_error($taxonomyID)){
$parent_term_id2 = $retID = $taxonomyID['term_id'];
wp_set_object_terms( $pID, $retID, $category_name, true );
if(!empty($poly_values)){
$lang = $poly_values['language_code'];
if(empty($lang) || !in_array($lang,$lang_list)){
$lang=pll_default_language();
}
$t_id=$taxonomyID['term_id'];
pll_set_term_language($t_id,$lang);
}
}
} else {
$exist_term_id = array( $checkAvailable['term_id'] );
$exist_term_id = array_map( 'intval', $exist_term_id );
$exist_term_id = array_unique( $exist_term_id );
$parent_term_id2 = $checkAvailable['term_id'];
wp_set_object_terms( $pID, $exist_term_id, $category_name, true );
}
}
unset( $checkAvailable );
$checkAvailable = term_exists( "$_name", "$category_name", $parent_term_id2 );
if ( ! is_array( $checkAvailable ) ) {
$taxonomyID = wp_insert_term( "$_name", "$category_name", array(
'description' => '',
'slug' => $_slug,
'parent' => $parent_term_id2
) );
if(!is_wp_error($taxonomyID)){
$retID = $taxonomyID['term_id'];
wp_set_object_terms( $pID, $retID, $category_name, true );
if(!empty($poly_values)){
$lang = $poly_values['language_code'];
if(empty($lang) || !in_array($lang,$lang_list)){
$lang=pll_default_language();
}
$t_id=$taxonomyID['term_id'];
pll_set_term_language($t_id,$lang);
}
}
} else {
$exist_term_id = array( $checkAvailable['term_id'] );
$exist_term_id = array_map( 'intval', $exist_term_id );
$exist_term_id = array_unique( $exist_term_id );
wp_set_object_terms( $pID, $exist_term_id, $category_name, true );
}
unset( $checkAvailable );
}
elseif ( $parent_term_id1 != 0 ) {
$checkAvailable = term_exists( "$_name", "$category_name", $parent_term_id1 );
if ( ! is_array( $checkAvailable ) ) {
$taxonomyID = wp_insert_term( "$_name", "$category_name", array(
'description' => '',
'slug' => $_slug,
'parent' => $parent_term_id1
) );
if(!is_wp_error($taxonomyID)){
$retID = $taxonomyID['term_id'];
wp_set_object_terms( $pID, $retID, $category_name, true );
if(!empty($poly_values)){
$lang = $poly_values['language_code'];
if(empty($lang) || !in_array($lang,$lang_list)){
$lang=pll_default_language();
}
$t_id=$taxonomyID['term_id'];
pll_set_term_language($t_id,$lang);
}
}
} else {
$exist_term_id = array( $checkAvailable['term_id'] );
$exist_term_id = array_map( 'intval', $exist_term_id );
$exist_term_id = array_unique( $exist_term_id );
wp_set_object_terms( $pID, $exist_term_id, $category_name, true );
}
unset( $checkAvailable );
}
elseif ( $super_parent_term_id == 0 && $parent_term_id2 == 0 && $parent_term_id1 == 0 ) {
$checkAvailable = term_exists( "$_name", "$category_name" );
if(!empty($_name)){
if ( !is_array( $checkAvailable ) ) {
$taxonomyID = wp_insert_term( "$_name", "$category_name", array(
'description' => '',
'slug' => $_slug,
) );
if(!is_wp_error($taxonomyID) && $is_parent){
$retID = $taxonomyID['term_id'];
wp_set_object_terms( $pID, $retID, $category_name, true );
if(!empty($poly_values)){
$lang = $poly_values['language_code'];
if(empty($lang) || !in_array($lang,$lang_list)){
$lang=pll_default_language();
}
$t_id=$taxonomyID['term_id'];
pll_set_term_language($t_id,$lang);
}
}
} else {
if($is_parent){
$exist_term_id = array( $checkAvailable['term_id'] );
$exist_term_id = array_map( 'intval', $exist_term_id );
$exist_term_id = array_unique( $exist_term_id );
wp_set_object_terms( $pID, $exist_term_id, $category_name, true );
}
}
}
unset( $checkAvailable );
}
#if ( ! is_wp_error( $retID ) ) {
update_option( "$category_name" . "_children", $term_children_options );
delete_option( $category_name . "_children" );
#}
$categoryData[] = (string) $category_value;
}
}
return $categoryData;
}
}

View File

@@ -0,0 +1,302 @@
<?php
/******************************************************************************************
* Copyright (C) Smackcoders. - All Rights Reserved under Smackcoders Proprietary License
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* You can contact Smackcoders at email address info@smackcoders.com.
*******************************************************************************************/
namespace Smackcoders\FCSV;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class ToolsetImport {
private static $toolset_instance = null;
public static function getInstance() {
if (ToolsetImport::$toolset_instance == null) {
ToolsetImport::$toolset_instance = new ToolsetImport;
return ToolsetImport::$toolset_instance;
}
return ToolsetImport::$toolset_instance;
}
function set_toolset_values($header_array ,$value_array , $map, $maps, $post_id , $type , $mode, $hash_key,$line_number,$gmode,$templatekey){
$post_values = [];
$helpers_instance = ImportHelpers::getInstance();
$post_values = $helpers_instance->get_header_values($map , $header_array , $value_array);
//$post_val = $helpers_instance->get_meta_values($maps , $header_array , $value_array);
$this->types_import_function($post_values,$post_val,$type, $post_id, $mode, $hash_key,$line_number,$gmode,$templatekey);
}
public function types_import_function($data_array,$post_val, $type, $postId ,$mode, $hash_key,$line_number,$gmode,$templatekey)
{
$newtoolset_instance = new ToolsetNewImport();
$wptypesfields=array();
//include_once( 'wp-admin/includes/plugin.php' );
$plugins = get_plugins();
$plugin_version = $plugins['types/wpcf.php']['Version'];
$result=array_key_exists('types_relationship',$data_array);
$intermediateResult=array_key_exists('intermediate',$data_array);
if($result==1)
{ if($plugin_version < '3.4.1'){
$this->normalRelationship($data_array,$postId,$mode);
}
else{
$newtoolset_instance->normalRelationshipnew($data_array,$postId,$mode,$type);
}
}
elseif($intermediateResult==1)
{
if($plugin_version < '3.4.1'){
$this->intermediateRelationship($data_array,$postId);
}
else{
$newtoolset_instance->intermediateRelationshipnew($data_array,$postId,$type);
}
}
$createdFields = $types_fieldtype = array();
foreach($data_array as $dkey => $dvalue)
{
$createdFields[] = $dkey;
}
$types_fieldname = array();
$field_type= array();
$wptypesfields = get_option('wpcf-fields');
foreach($wptypesfields as $types_field)
{
$types_fieldname[$types_field['slug']] = $types_field['meta_key'];
$types_fieldtype[$types_field['slug']] = $types_field['type'];
}
$getUserMetas = get_option('wpcf-usermeta');
if (is_array($getUserMetas))
{
foreach($getUserMetas as $types_field)
{
$types_fieldname[$types_field['slug']] = $types_field['meta_key'];
$types_fieldtype[$types_field['slug']] = $types_field['type'];
}
}
$getTermMetas = get_option('wpcf-termmeta');
if (is_array($getTermMetas))
{
foreach($getTermMetas as $types_field)
{
$types_fieldname[$types_field['slug']] = $types_field['meta_key'];
$types_fieldtype[$types_field['slug']] = $types_field['type'];
}
}
$result=array_intersect_key($types_fieldname,$data_array); //meta table entry.
foreach ($result as $key => $value) {
if (array_key_exists($key, $types_fieldtype)) {
$field_type[$key] = $types_fieldtype[$key];
}
}
if ($type =='Users') {
$wptypesfields=$getUserMetas;
}
else{
if(empty($wptypesfields)){
$wptypesfields=$getTermMetas;
}
}
if ($mode=='Update') {
if(!empty($data_array)) {
require_once "toolsetHelper/WPToolsetUpdater.php";
$WPToolsetUpdater = WPToolsetUpdater::getInstance();
$WPToolsetUpdater->set($data_array, $result, $field_type,$wptypesfields,$type);
$WPToolsetUpdater->update($postId,$post_val,$hash_key,$line_number,$gmode,$templatekey);
}
}elseif ($mode =='Insert') {
if(!empty($data_array)) {
require_once "toolsetHelper/WPToolsetImporter.php";
$wpToolsetImporter = WPToolsetImporter::getInstance();
$wpToolsetImporter->set($data_array, $result, $field_type,$wptypesfields,$type);
$wpToolsetImporter->import($postId,$post_val,$hash_key,$line_number,$gmode,$templatekey);
}
}
return $createdFields;
}
public function normalRelationship($data_array,$pID,$mode)
{
$value=$data_array['types_relationship'];
global $wpdb;
$x = preg_replace('/\s*,\s*/', ',', $value);
$split=explode('|', $x);
$get_rel_val = array();
foreach($split as $key=>$item){
foreach(explode(',',$item) as $value){
$get_rel_val[$key][] = $value;
}
}
$slug=explode('|', $data_array['relationship_slug']);
foreach ($get_rel_val as $key1 => $get_rel_vals) {
foreach ($slug as $key2 => $value) {
if ($key1 == $key2){
for ($i = 0; $i < count($get_rel_vals); $i++){
if (ctype_digit($get_rel_vals[$i])){
$post = get_post($get_rel_vals[$i]);
global $wpdb;
$pquery = "select id from {$wpdb->prefix}toolset_relationships where slug ='{$value}'";
$post = $wpdb->get_results($pquery);
$wpdb->insert($wpdb->prefix . 'toolset_associations', array(
'relationship_id' => $post[0]->id,
'parent_id' => $get_rel_vals[$i],
'child_id' => $pID,
'intermediary_id' => '0'
));
$wpdb->insert($wpdb->prefix . 'toolset_associations', array(
'relationship_id' => $post[0]->id,
'parent_id' => $pID,
'child_id' => $get_rel_vals[$i],
'intermediary_id' => '0'
));
}
else{
$get_rel_value = $wpdb->_real_escape($get_rel_vals[$i]);
$pquery = "select * from {$wpdb->prefix}posts where post_title = '{$get_rel_value}' and post_status != 'trash'";
$post = $wpdb->get_results($pquery, ARRAY_A);
$pquery = "select id from {$wpdb->prefix}toolset_relationships where slug ='{$value}'";
$post1 = $wpdb->get_results($pquery);
if($mode=='Update'){
if(!empty($get_rel_value)) {
global $wpdb;
$parentquery = "select parent_id,child_id from {$wpdb->prefix}toolset_associations where relationship_id ='{$post1[0]->id}' AND parent_id='{$pID}'";
$parent_id=$wpdb->get_results($parentquery, ARRAY_A);
$array=json_decode(json_encode($parent_id),true);
foreach($array as $parkey => $parval){
if($parval['parent_id']==$pID && $parval['child_id']==$post[0]['ID']){
$query1 = "select id,intermediary_id from {$wpdb->prefix}toolset_associations where relationship_id ='{$post1[0]->id}' AND parent_id='{$pID}' AND child_id='{$post[0]['ID']}'";
$id1 =$wpdb->get_results($query1, ARRAY_A);
$array1=json_decode(json_encode($id1),true);
$wpdb->delete($wpdb->prefix . 'toolset_associations',array('id'=>$array1[0]['id']));
$wpdb->delete($wpdb->prefix . 'posts',array('ID'=>$array1[0]['intermediary_id']));
}
elseif($parval['parent_id']==$pID){
$wpdb->delete($wpdb->prefix . 'toolset_associations',array('parent_id'=>$pID));
}
}
$interpostquery ="select display_name_plural,intermediary_type from {$wpdb->prefix}toolset_relationships where slug ='{$value}'";
$interpost = $wpdb->get_results($interpostquery);
$array=array('post_title' => $interpost[0]->display_name_plural.': '.$post[0]['ID'].'-'.$pID,
'post_type' => $interpost[0]->intermediary_type,'post_status'=> 'publish');
$interid=wp_insert_post($array);
$wpdb->insert($wpdb->prefix . 'toolset_associations', array(
'relationship_id' => $post1[0]->id,
'parent_id' => $pID,
'child_id' => $post[0]['ID'],
'intermediary_id' => $interid
));
$wpdb->insert($wpdb->prefix . 'toolset_associations', array(
'relationship_id' => $post1[0]->id,
'parent_id' => $post[0]['ID'],
'child_id' => $pID,
'intermediary_id' => '0'
));
}
else{
$wpdb->delete($wpdb->prefix . 'toolset_associations',array('parent_id'=>$pID));
}
}
else{
$interpostquery ="select display_name_plural,intermediary_type from {$wpdb->prefix}toolset_relationships where slug ='{$value}'";
$interpost = $wpdb->get_results($interpostquery);
$array=array('post_title' => $interpost[0]->display_name_plural.': '.$post[0]['ID'].'-'.$pID,
'post_type' => $interpost[0]->intermediary_type,'post_status'=> 'publish');
$interid=wp_insert_post($array);
$wpdb->insert($wpdb->prefix . 'toolset_associations', array(
'relationship_id' => $post1[0]->id,
'parent_id' => $pID,
'child_id' => $post[0]['ID'],
'intermediary_id' => $interid
));
$wpdb->insert($wpdb->prefix . 'toolset_associations', array(
'relationship_id' => $post1[0]->id,
'parent_id' => $post[0]['ID'],
'child_id' => $pID,
'intermediary_id' => '0'
));
}
}
}
}
}
}
}
public function intermediateRelationship($data_array,$pID)
{
$value=$data_array['intermediate'];
$get_rel_vals = explode(',', $value);
global $wpdb;
$row = $wpdb->delete($wpdb->prefix.'toolset_associations',array('intermediary_id' => $pID));
if(intval($get_rel_vals[0])){
$post = get_post($get_rel_vals[0]);
$pquery = "select id from {$wpdb->prefix}toolset_relationships where slug ='{$data_array['relationship_slug']}'";
$post = $wpdb->get_results($pquery);
$wpdb->insert($wpdb->prefix.'toolset_associations',array('relationship_id' =>$post[0]->id ,'parent_id' => $get_rel_vals[0] ,'child_id' => $get_rel_vals[1]
,'intermediary_id' => $pID ));
}else{
$pquery = "select * from {$wpdb->prefix}posts where post_title = '{$get_rel_vals[0]}' and post_status != 'trash'";
$post = $wpdb->get_results($pquery,ARRAY_A);
$pqueryc = "select * from {$wpdb->prefix}posts where post_title = '{$get_rel_vals[1]}' and post_status != 'trash'";
$postc = $wpdb->get_results($pqueryc,ARRAY_A);
$pquery = "select id from {$wpdb->prefix}toolset_relationships where slug ='{$data_array['relationship_slug']}'";
$post1 = $wpdb->get_results($pquery);
$wpdb->insert($wpdb->prefix.'toolset_associations',array('relationship_id' => $post1[0]->id,'parent_id' => $post[0]['ID'] ,'child_id' => $postc[0]['ID']
,'intermediary_id' => $pID));
}
}
}

View File

@@ -0,0 +1,982 @@
<?php
/******************************************************************************************
* Copyright (C) Smackcoders. - All Rights Reserved under Smackcoders Proprietary License
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* You can contact Smackcoders at email address info@smackcoders.com.
*******************************************************************************************/
namespace Smackcoders\FCSV;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class ToolsetNewImport {
private static $toolset_new_instance = null;
public static function getInstance() {
if (ToolsetNewImport::$toolset_new_instance == null) {
ToolsetNewImport::$toolset_new_instance = new ToolsetNewImport;
return ToolsetNewImport::$toolset_new_instance;
}
return ToolsetNewImport::$toolset_new_instance;
}
public function normalRelationshipnew($data_array,$pID,$mode,$type)
{
$value=$data_array['types_relationship'];
if($type == 'Posts')
$type = 'post';
global $wpdb;
$x = preg_replace('/\s*,\s*/', ',', $value);
$split=explode('|', $x);
$get_rel_val = array();
foreach($split as $key=>$item){
foreach(explode(',',$item) as $value){
$get_rel_val[$key][] = $value;
}
}
$slug=explode('|', $data_array['relationship_slug']);
foreach ($get_rel_val as $key1 => $get_rel_vals) {
foreach ($slug as $key2 => $value) {
if ($key1 == $key2){
for ($i = 0; $i < count($get_rel_vals); $i++){
if (ctype_digit($get_rel_vals[$i])){
$post = get_post($get_rel_vals[$i]);
global $wpdb;
$checkinter = "select intermediary_type,parent_types,child_types from {$wpdb->prefix}toolset_relationships where slug ='{$value}'";
$is_inter = $wpdb->get_results($checkinter);
$is_intermediate = $is_inter[0]->intermediary_type;
$is_parenttype = $is_inter[0]->parent_types;
$is_childtype = $is_inter[0]->child_types;
$parent_typequery = "select type from {$wpdb->prefix}toolset_type_sets where set_id ='{$is_parenttype}'";
$partyperes = $wpdb->get_results($parent_typequery);
$parent_type = $partyperes[0]->type;
$child_typequery = "select type from {$wpdb->prefix}toolset_type_sets where set_id ='{$is_childtype}'";
$childtyperes = $wpdb->get_results($child_typequery);
$child_type = $childtyperes[0]->type;
$pquery = "select id from {$wpdb->prefix}toolset_relationships where slug ='{$value}'";
$post = $wpdb->get_results($pquery);
//for version 3.4.1 and above
$parrelid = $get_rel_vals[$i];
$parcon = "select group_id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$parrelid}'";
$parconid = $wpdb->get_results($parcon, ARRAY_A);
$childcon = "select group_id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$pID}'";
$childconid = $wpdb->get_results($childcon, ARRAY_A);
if($parconid[0]['group_id']){
$parent_id =$parconid[0]['group_id'];
}
else{
$get_trid = $wpdb->get_results("select trid from {$wpdb->prefix}icl_translations where element_id ='$parrelid'");
if (class_exists('SitePress')) {
$trid = $get_trid[0]->trid;
if(empty($trid)){
$trid = 0;
}
}
else{
$trid = 0;
}
$wpdb->insert($wpdb->prefix . 'toolset_connected_elements', array(
'element_id' => $parrelid,
'domain' => 'posts',
'wpml_trid' => $trid
));
$pq = "select id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$parrelid}'";
$pqres = $wpdb->get_results($pq);
$parent_id = $pqres[0]->id;
$wpdb->get_results("UPDATE {$wpdb->prefix}toolset_connected_elements set group_id = '$parent_id' where id = $parent_id");
//$wpdb->update($wpdb->toolset_connected_elements, ['group_id' => $parent_id], ['id' => $parent_id]);
}
if($childconid[0]['group_id']){
$child_id =$childconid[0]['group_id'];
}
else{
if (class_exists('SitePress')) {
$get_trid = $wpdb->get_results("select trid from {$wpdb->prefix}icl_translations where element_id ='$pID'");
$trid = $get_trid[0]->trid;
if(empty($trid)){
$trid = 0;
}
}
else{
$trid = 0;
}
$wpdb->insert($wpdb->prefix . 'toolset_connected_elements', array(
'element_id' => $pID,
'domain' => 'posts',
'wpml_trid' => $trid
));
$pq1 = "select id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$pID}'";
$pqres1 = $wpdb->get_results($pq1);
$child_id = $pqres1[0]->id;
$wpdb->get_results("UPDATE {$wpdb->prefix}toolset_connected_elements set group_id = '$child_id' where id = $child_id");
//$wpdb->update($wpdb->toolset_connected_elements, ['group_id' => $child_id], ['id' => $child_id]);
}
if(!empty($is_intermediate)){
$interpostquery ="select display_name_plural,intermediary_type from {$wpdb->prefix}toolset_relationships where slug ='{$value}'";
$interpost = $wpdb->get_results($interpostquery);
$array=array('post_title' => $interpost[0]->display_name_plural.': '.$pID.' - '.$get_rel_vals[$i],
'post_type' => $interpost[0]->intermediary_type,'post_status'=> 'publish');
$interid=wp_insert_post($array);
$wptypesfields = get_option('wpcf-fields');
foreach($wptypesfields as $types_field)
{
$types_fieldname[$types_field['slug']] = $types_field['meta_key'];
$types_fieldtype[$types_field['slug']] = $types_field['type'];
}
$result=array_intersect_key($types_fieldname,$data_array); //meta table entry.
foreach ($result as $key => $value) {
if (array_key_exists($key, $types_fieldtype)) {
$field_type[$key] = $types_fieldtype[$key];
}
}
if (class_exists('SitePress')) {
$get_trid = $wpdb->get_results("select trid from {$wpdb->prefix}icl_translations where element_id ='$interid'");
$trid = $get_trid[0]->trid;
if(empty($trid)){
$trid = 0;
}
}
else{
$trid = 0;
}
$wpdb->insert($wpdb->prefix . 'toolset_connected_elements', array(
'element_id' => $interid,
'domain' => 'posts',
'wpml_trid' => $trid
));
$pinter = "select id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$interid}'";
$pinterres = $wpdb->get_results($pinter);
$inter_id = $pinterres[0]->id;
//$wpdb->update($wpdb->toolset_connected_elements, ['group_id' => $inter_id], ['id' => $inter_id]);
$wpdb->get_results("UPDATE {$wpdb->prefix}toolset_connected_elements set group_id = '$inter_id' where id = $inter_id");
}
else{
$inter_id = 0;
}
if($type == $parent_type){
if(!empty($post)){
$wpdb->insert($wpdb->prefix . 'toolset_associations', array(
'relationship_id' => $post[0]->id,
'parent_id' => $child_id,
'child_id' => $parent_id,
'intermediary_id' => '0'
));
}
}
else{
if(!empty($post)){
$wpdb->insert($wpdb->prefix . 'toolset_associations', array(
'relationship_id' => $post[0]->id,
'parent_id' => $parent_id,
'child_id' => $child_id,
'intermediary_id' => $inter_id
));
}
}
}
else{
$get_rel_value = $wpdb->_real_escape($get_rel_vals[$i]);
$pquery = "select * from {$wpdb->prefix}posts where post_title = '{$get_rel_value}' and post_status != 'trash'";
$post = $wpdb->get_results($pquery, ARRAY_A);
$pquery = "select id from {$wpdb->prefix}toolset_relationships where slug ='{$value}'";
$post1 = $wpdb->get_results($pquery);
$checkinter = "select intermediary_type,parent_types,child_types from {$wpdb->prefix}toolset_relationships where slug ='{$value}'";
$is_inter = $wpdb->get_results($checkinter);
if(!empty($is_inter)){
$is_intermediate = $is_inter[0]->intermediary_type;
$is_parenttype = $is_inter[0]->parent_types;
$is_childtype = $is_inter[0]->child_types;
}
else{
$is_intermediate = '';
$is_parenttype = '';
$is_childtype = '';
}
$parent_typequery = "select type from {$wpdb->prefix}toolset_type_sets where set_id ='{$is_parenttype}'";
$partyperes = $wpdb->get_results($parent_typequery);
if(!empty( $partyperes)) {
$parent_type = $partyperes[0]->type;
}
else{
$parent_type = '';
}
$child_typequery = "select type from {$wpdb->prefix}toolset_type_sets where set_id ='{$is_childtype}'";
$childtyperes = $wpdb->get_results($child_typequery);
if(!empty($childtyperes)){
$child_type = $childtyperes[0]->type;
}
else{
$child_type = '';
}
if($mode=='Update'){
if(!empty($get_rel_value)) {
global $wpdb;
//new
//parentid
$parcon = "select group_id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$pID}'";
$parconid = $wpdb->get_results($parcon, ARRAY_A);
if($parconid[0]['group_id']){
$parentid =$parconid[0]['group_id'];
}
else{
if (class_exists('SitePress')) {
$get_trid = $wpdb->get_results("select trid from {$wpdb->prefix}icl_translations where element_id ='$pID'");
$trid = $get_trid[0]->trid;
if(empty($trid)){
$trid = 0;
}
}
else{
$trid = 0;
}
$wpdb->insert($wpdb->prefix . 'toolset_connected_elements', array(
'element_id' => $pID,
'domain' => 'posts',
'wpml_trid' => $trid
));
$pq = "select id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$pID}'";
$pqres = $wpdb->get_results($pq);
$parentid = $pqres[0]->id;
$wpdb->get_results("UPDATE {$wpdb->prefix}toolset_connected_elements set group_id = '$parentid' where id = $parentid");
}
////childid
$childcon = "select group_id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$post[0]['ID']}'";
$childconid = $wpdb->get_results($childcon, ARRAY_A);
if($childconid[0]['group_id']){
$child_id =$childconid[0]['group_id'];
}
else{
if (class_exists('SitePress')) {
$get_trid = $wpdb->get_results("select trid from {$wpdb->prefix}icl_translations where element_id ='{$post[0]['ID']}'");
$trid = $get_trid[0]->trid;
if(empty($trid)){
$trid = 0;
}
}
else{
$trid = 0;
}
$wpdb->insert($wpdb->prefix . 'toolset_connected_elements', array(
'element_id' => $post[0]['ID'],
'domain' => 'posts',
'wpml_trid' => $trid
));
$pq1 = "select id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$post[0]['ID']}'";
$pqres1 = $wpdb->get_results($pq1);
$child_id = $pqres1[0]->id;
$wpdb->get_results("UPDATE {$wpdb->prefix}toolset_connected_elements set group_id = '$child_id' where id = $child_id");
//$wpdb->update($wpdb->toolset_connected_elements, ['group_id' => $child_id], ['id' => $child_id]);
}
if(!empty($is_intermediate)){
$interpostquery ="select display_name_plural,intermediary_type from {$wpdb->prefix}toolset_relationships where slug ='{$value}'";
$interpost = $wpdb->get_results($interpostquery);
$array=array('post_title' => $interpost[0]->display_name_plural.': '.$post[0]['ID'].' - '.$pID,
'post_type' => $interpost[0]->intermediary_type,'post_status'=> 'publish');
$interid=wp_insert_post($array);
$wptypesfields = get_option('wpcf-fields');
foreach($wptypesfields as $types_field)
{
$types_fieldname[$types_field['slug']] = $types_field['meta_key'];
$types_fieldtype[$types_field['slug']] = $types_field['type'];
}
$result=array_intersect_key($types_fieldname,$data_array); //meta table entry.
foreach ($result as $key => $value) {
if (array_key_exists($key, $types_fieldtype)) {
$field_type[$key] = $types_fieldtype[$key];
}
}
if (class_exists('SitePress')) {
$get_trid = $wpdb->get_results("select trid from {$wpdb->prefix}icl_translations where element_id ='$interid'");
$trid = $get_trid[0]->trid;
if(empty($trid)){
$trid = 0;
}
}
else{
$trid = 0;
}
$wpdb->insert($wpdb->prefix . 'toolset_connected_elements', array(
'element_id' => $interid,
'domain' => 'posts',
'wpml_trid' => $trid
));
$pinter = "select id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$interid}'";
$pinterres = $wpdb->get_results($pinter);
$inter_id = $pinterres[0]->id;
//$wpdb->update($wpdb->toolset_connected_elements, ['group_id' => $inter_id], ['id' => $inter_id]);
$wpdb->get_results("UPDATE {$wpdb->prefix}toolset_connected_elements set group_id = '$inter_id' where id = $inter_id");
}
else{
$inter_id = 0;
}
///
if($type == $parent_type){
$parentquery = "select parent_id,child_id from {$wpdb->prefix}toolset_associations where relationship_id ='{$post1[0]->id}' AND parent_id='{$parentid}'";
$parent_id=$wpdb->get_results($parentquery, ARRAY_A);
$array=json_decode(json_encode($parent_id),true);
foreach($array as $parkey => $parval){
//if($parval['parent_id']==$parentid && $parval['child_id']==$child_id){
if($parval['parent_id']==$parentid ){
$child =explode(',',$childidarray);
$count = count($child);
if($count <= 2){
//$query1 = "select id,intermediary_id from {$wpdb->prefix}toolset_associations where relationship_id ='{$post1[0]->id}' AND parent_id='{$parentid}'";
$query1 = "select id,intermediary_id from {$wpdb->prefix}toolset_associations where relationship_id ='{$post1[0]->id}' AND parent_id='{$parentid}'";
$id1 =$wpdb->get_results($query1, ARRAY_A);
$array1=json_decode(json_encode($id1),true);
foreach($array1 as $arraykey1 => $arrval1){
$delconinter =$arrval1['intermediary_id'];
$wpdb->delete($wpdb->prefix . 'toolset_associations',array('id'=>$arrval1['id']));
$q = "select element_id from {$wpdb->prefix}toolset_connected_elements where id ='{$delconinter}' ";
$delinter =$wpdb->get_results($q, ARRAY_A);
$delinterid = $delinter[0]['element_id'];
$wpdb->get_results("DELETE FROM {$wpdb->prefix}posts WHERE `ID` = $delinterid");
// $wpdb->delete($wpdb->prefix . 'posts',array('ID'=>$arrval1['intermediary_id']));
}
}
}
}
$childarray .= $child_id.',';
// $childcount = count($childarray);
$checkchildmax = "select cardinality_child_max from {$wpdb->prefix}toolset_relationships where id ='{$post1[0]->id}'";
$childmax = $wpdb->get_results($checkchildmax, ARRAY_A);
if($childmax[0]['cardinality_child_max'] == 1){
$childexp = explode(',',$childarray);
if($child_id == $childexp[0]){
if(!empty($post1)){
$wpdb->insert($wpdb->prefix . 'toolset_associations', array(
'relationship_id' => $post1[0]->id,
'parent_id' => $parentid,
'child_id' => $child_id,
'intermediary_id' => $inter_id
));
}
}
}
else{
if(!empty($post1)){
$wpdb->insert($wpdb->prefix . 'toolset_associations', array(
'relationship_id' => $post1[0]->id,
'parent_id' => $parentid,
'child_id' => $child_id,
'intermediary_id' => $inter_id
));
}
}
}
else{
$childquery = "select parent_id,child_id from {$wpdb->prefix}toolset_associations where relationship_id ='{$post1[0]->id}' AND child_id ='{$parentid}'";
$childquery1=$wpdb->get_results($childquery, ARRAY_A);
$array1=json_decode(json_encode($childquery1),true);
foreach($array1 as $parkey => $parval){
if($parval['parent_id']==$child_id ){
$child =explode(',',$childidarray);
$count = count($child);
if($count <= 2){
$query1 = "select id,intermediary_id from {$wpdb->prefix}toolset_associations where relationship_id ='{$post1[0]->id}' AND child_id='{$parentid}'";
$id1 =$wpdb->get_results($query1, ARRAY_A);
$array2=json_decode(json_encode($id1),true);
foreach($array2 as $arraykey2 => $arrval2){
$delconinter =$arrval2['intermediary_id'];
$wpdb->delete($wpdb->prefix . 'toolset_associations',array('id'=>$arrval2['id']));
$q = "select element_id from {$wpdb->prefix}toolset_connected_elements where id ='{$delconinter}' ";
$delinter =$wpdb->get_results($q, ARRAY_A);
$delinterid = $delinter[0]['element_id'];
$wpdb->get_results("DELETE FROM {$wpdb->prefix}posts WHERE `ID` = $delinterid");
}
}
}
}
$childarray .= $child_id.',';
// $childcount = count($childarray);
$checkchildmax = "select cardinality_parent_max from {$wpdb->prefix}toolset_relationships where id ='{$post1[0]->id}'";
$childmax = $wpdb->get_results($checkchildmax, ARRAY_A);
if($childmax[0]['cardinality_parent_max'] == 1){
$childexp = explode(',',$childarray);
if($child_id == $childexp[0]){
if(!empty($post1)){
$wpdb->insert($wpdb->prefix . 'toolset_associations', array(
'relationship_id' => $post1[0]->id,
'parent_id' => $child_id,
'child_id' =>$parentid,
'intermediary_id' => '0'
));
}
}
}
else{
if(!empty($post1)){
$wpdb->insert($wpdb->prefix . 'toolset_associations', array(
'relationship_id' => $post1[0]->id,
'parent_id' => $child_id,
'child_id' =>$parentid,
'intermediary_id' => '0'
));
}
}
}
}
else{
$wpdb->delete($wpdb->prefix . 'toolset_associations',array('parent_id'=>$pID));
}
}
else{
//insert into association table for version >= 3.4.1
$po =$post[0]['ID'];
global $wpdb;
//$pquery1 = "select id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$po}'";
$pquery1 = "select group_id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$pID}'";
$pmquery1 = "select group_id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$po}'";
$pqueryres1 = $wpdb->get_results($pquery1);
if(isset($pqueryres1[0]->group_id) && $pqueryres1[0]->group_id){
$parent_id = $pqueryres1[0]->group_id;
}
else{
if (class_exists('SitePress')) {
$get_trid = $wpdb->get_results("select trid from {$wpdb->prefix}icl_translations where element_id ='$pID'");
$trid = $get_trid[0]->trid;
if(empty($trid)){
$trid = 0;
}
}
else{
$trid = 0;
}
$wpdb->insert($wpdb->prefix . 'toolset_connected_elements', array(
'element_id' => $pID,
'domain' => 'posts',
'wpml_trid' => $trid
));
$pq1 = "select id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$pID}'";
$pqres1 = $wpdb->get_results($pq1);
$parent_id = $pqres1[0]->id;
//$wpdb->update($wpdb->toolset_connected_elements, ['group_id' => $parent_id], ['id' => $parent_id]);
$wpdb->get_results("UPDATE {$wpdb->prefix}toolset_connected_elements set group_id = '$parent_id' where id = $parent_id");
}
$pmqueryres1 = $wpdb->get_results($pmquery1);
if($pmqueryres1[0]->group_id){
$child_id = $pmqueryres1[0]->group_id;
}
else{
if (class_exists('SitePress')) {
$get_trid = $wpdb->get_results("select trid from {$wpdb->prefix}icl_translations where element_id ='$po'");
$trid = $get_trid[0]->trid;
if(empty($trid)){
$trid = 0;
}
}
else{
$trid = 0;
}
$wpdb->insert($wpdb->prefix . 'toolset_connected_elements', array(
'element_id' => $po,
'domain' => 'posts',
'wpml_trid' => $trid
));
$pq2 = "select id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$po}'";
$pqres2 = $wpdb->get_results($pq2);
$child_id = $pqres2[0]->id;
$wpdb->get_results("UPDATE {$wpdb->prefix}toolset_connected_elements set group_id = '$child_id' where id = $child_id");
}
$inter_id = 0;
if(!empty($is_intermediate)){
$interpostquery ="select display_name_plural,intermediary_type from {$wpdb->prefix}toolset_relationships where slug ='{$value}'";
$interpost = $wpdb->get_results($interpostquery);
$array=array('post_title' => $interpost[0]->display_name_plural.': '.$post[0]['ID'].' - '.$pID,
'post_type' => $interpost[0]->intermediary_type,'post_status'=> 'publish');
$interid=wp_insert_post($array);
$wptypesfields = get_option('wpcf-fields');
foreach($wptypesfields as $types_field)
{
$types_fieldname[$types_field['slug']] = $types_field['meta_key'];
$types_fieldtype[$types_field['slug']] = $types_field['type'];
}
$result=array_intersect_key($types_fieldname,$data_array); //meta table entry.
foreach ($result as $key => $value) {
if (array_key_exists($key, $types_fieldtype)) {
$field_type[$key] = $types_fieldtype[$key];
}
}
foreach ($data_array as $key => $value) {
if($field_type[$key] =='checkboxes'){
$values = $wptypesfields[$key];
$options = $wptypesfields[$key]['data']['options'];
$checkbox_array = array();
$check_values = explode(',',$value);
foreach($check_values as $check_val){
foreach ($options as $key1 => $value1) {
if ($check_val == $value1['set_value']) {
$checkbox_array[$key1] = array($value1['set_value']);
}
}
}
$meta_key = $values['meta_key'];
// update_post_meta($interid,$meta_key,$checkbox_array);
}
if($field_type[$key] == 'radio'){
$values = $wptypesfields[$key];
$meta_key = $values['meta_key'];
// update_post_meta($interid,$meta_key,$value);
}
}
if (class_exists('SitePress')) {
$get_trid = $wpdb->get_results("select trid from {$wpdb->prefix}icl_translations where element_id ='$interid'");
$trid = $get_trid[0]->trid;
if(empty($trid)){
$trid = 0;
}
}
else{
$trid = 0;
}
$wpdb->insert($wpdb->prefix . 'toolset_connected_elements', array(
'element_id' => $interid,
'domain' => 'posts',
'wpml_trid' => $trid
));
$pinter = "select id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$interid}'";
$pinterres = $wpdb->get_results($pinter);
$inter_id = $pinterres[0]->id;
//$wpdb->update($wpdb->toolset_connected_elements, ['group_id' => $inter_id], ['id' => $inter_id]);
$wpdb->get_results("UPDATE {$wpdb->prefix}toolset_connected_elements set group_id = '$inter_id' where id = $inter_id");
}
else{
$inter_id = 0;
}
if($type == $parent_type){
$childarray .= $child_id.',';
// $childcount = count($childarray);
$checkchildmax = "select cardinality_child_max from {$wpdb->prefix}toolset_relationships where id ='{$post1[0]->id}'";
$childmax = $wpdb->get_results($checkchildmax, ARRAY_A);
if($childmax[0]['cardinality_child_max'] == 1){
$childexp = explode(',',$childarray);
if($child_id == $childexp[0]){
if(!empty($post1)){
$wpdb->insert($wpdb->prefix . 'toolset_associations', array(
'relationship_id' => $post1[0]->id,
'parent_id' => $parent_id,
'child_id' => $child_id,
'intermediary_id' => $inter_id
));
}
}
}
else{
if(!empty($post1)){
$wpdb->insert($wpdb->prefix . 'toolset_associations', array(
'relationship_id' => $post1[0]->id,
'parent_id' => $parent_id,
'child_id' => $child_id,
'intermediary_id' => $inter_id
));
}
}
}
else{
$childarray.= $child_id.',';
// $childcount = count($childarray);
$checkchildmax = "select cardinality_parent_max from {$wpdb->prefix}toolset_relationships where id ='{$post1[0]->id}'";
$childmax = $wpdb->get_results($checkchildmax, ARRAY_A);
if($childmax[0]['cardinality_parent_max'] == 1){
$childexp = explode(',',$childarray);
if($child_id == $childexp[0]){
if(!empty($post1)){
$wpdb->insert($wpdb->prefix . 'toolset_associations', array(
'relationship_id' => $post1[0]->id,
'parent_id' => $child_id,
'child_id' => $parent_id,
'intermediary_id' => $inter_id
));
}
}
}
else{
if(!empty($post1)){
$wpdb->insert($wpdb->prefix . 'toolset_associations', array(
'relationship_id' => $post1[0]->id,
'parent_id' => $child_id,
'child_id' => $parent_id,
'intermediary_id' => $inter_id
));
}
}
}
}
}
}
}
}
}
}
public function intermediateRelationshipnew($data_array,$pID,$type)
{
$value=$data_array['intermediate'];
$get_rel_vals = explode(',', $value);
global $wpdb;
$row = $wpdb->delete($wpdb->prefix.'toolset_associations',array('intermediary_id' => $pID));
if(intval($get_rel_vals[0])){
$parrelid = $get_rel_vals[0];
$parcon = "select group_id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$parrelid}'";
$parconid = $wpdb->get_results($parcon, ARRAY_A);
$childrelid =$get_rel_vals[1];
$childcon = "select group_id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$childrelid}'";
$childconid = $wpdb->get_results($childcon, ARRAY_A);
if($parconid[0]['group_id']){
$parent_id =$parconid[0]['group_id'];
}
else{
if (class_exists('SitePress')) {
$get_trid = $wpdb->get_results("select trid from {$wpdb->prefix}icl_translations where element_id ='$parrelid'");
$trid = $get_trid[0]->trid;
if(empty($trid)){
$trid = 0;
}
}
else{
$trid = 0;
}
$wpdb->insert($wpdb->prefix . 'toolset_connected_elements', array(
'element_id' => $parrelid,
'domain' => 'posts',
'wpml_trid' => $trid
));
$pq = "select id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$parrelid}'";
$pqres = $wpdb->get_results($pq);
$parent_id = $pqres[0]->id;
$wpdb->get_results("UPDATE {$wpdb->prefix}toolset_connected_elements set group_id = '$parent_id' where id = $parent_id");
//$wpdb->update($wpdb->toolset_connected_elements, ['group_id' => $parent_id], ['id' => $parent_id]);
}
if($childconid[0]['group_id']){
$child_id =$childconid[0]['group_id'];
}
else{
if (class_exists('SitePress')) {
$get_trid = $wpdb->get_results("select trid from {$wpdb->prefix}icl_translations where element_id ='$childrelid'");
$trid = $get_trid[0]->trid;
if(empty($trid)){
$trid = 0;
}
}
else{
$trid = 0;
}
$wpdb->insert($wpdb->prefix . 'toolset_connected_elements', array(
'element_id' => $childrelid,
'domain' => 'posts',
'wpml_trid' => $trid
));
$pq1 = "select id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$childrelid}'";
$pqres1 = $wpdb->get_results($pq1);
$child_id = $pqres1[0]->id;
//$wpdb->update($wpdb->toolset_connected_elements, ['group_id' => $child_id], ['id' => $child_id]);
$wpdb->get_results("UPDATE {$wpdb->prefix}toolset_connected_elements set group_id = '$child_id' where id = $child_id");
}
$intercon = "select id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$pID}'";
$interconid = $wpdb->get_results($intercon, ARRAY_A);
if($interconid[0]['id']){
$inter_id =$interconid[0]['id'];
}
else{
if (class_exists('SitePress')) {
$get_trid = $wpdb->get_results("select trid from {$wpdb->prefix}icl_translations where element_id ='$pID'");
$trid = $get_trid[0]->trid;
if(empty($trid)){
$trid = 0;
}
}
else{
$trid = 0;
}
$wpdb->insert($wpdb->prefix . 'toolset_connected_elements', array(
'element_id' => $pID,
'domain' => 'posts',
'wpml_trid' => $trid
));
$pqc1 = "select id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$pID}'";
$pqresc1 = $wpdb->get_results($pqc1);
$inter_id = $pqresc1[0]->id;
//$wpdb->update($wpdb->toolset_connected_elements, ['group_id' => $inter_id], ['id' => $inter_id]);
$wpdb->get_results("UPDATE {$wpdb->prefix}toolset_connected_elements set group_id = '$inter_id' where id = $inter_id");
}
$post = get_post($get_rel_vals[0]);
$pquery = "select id from {$wpdb->prefix}toolset_relationships where slug ='{$data_array['relationship_slug']}'";
$post = $wpdb->get_results($pquery);
$wpdb->insert($wpdb->prefix.'toolset_associations',array('relationship_id' =>$post[0]->id ,'parent_id' => $parent_id ,'child_id' => $child_id
,'intermediary_id' => $inter_id ));
}else{
$pquery = "select * from {$wpdb->prefix}posts where post_title = '{$get_rel_vals[0]}' and post_status != 'trash'";
$post = $wpdb->get_results($pquery,ARRAY_A);
$pqueryc = "select * from {$wpdb->prefix}posts where post_title = '{$get_rel_vals[1]}' and post_status != 'trash'";
$postc = $wpdb->get_results($pqueryc,ARRAY_A);
$parrelid = $post[0]['ID'];
$childrelid =$postc[0]['ID'];
$parcon = "select group_id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$parrelid}'";
$parconid = $wpdb->get_results($parcon, ARRAY_A);
$childcon = "select group_id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$childrelid }'";
$childconid = $wpdb->get_results($childcon, ARRAY_A);
if($parconid[0]['group_id']){
$parent_id =$parconid[0]['group_id'];
}
else{
if (class_exists('SitePress')) {
$get_trid = $wpdb->get_results("select trid from {$wpdb->prefix}icl_translations where element_id ='$parrelid'");
$trid = $get_trid[0]->trid;
if(empty($trid)){
$trid = 0;
}
}
else{
$trid = 0;
}
$wpdb->insert($wpdb->prefix . 'toolset_connected_elements', array(
'element_id' => $parrelid,
'domain' => 'posts',
'wpml_trid' => $trid
));
$pq = "select id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$parrelid}'";
$pqres = $wpdb->get_results($pq);
$parent_id = $pqres[0]->id;
$wpdb->get_results("UPDATE {$wpdb->prefix}toolset_connected_elements set group_id = '$parent_id' where id = $parent_id");
}
if($childconid[0]['group_id']){
$child_id =$childconid[0]['group_id'];
}
else{
if (class_exists('SitePress')) {
$get_trid = $wpdb->get_results("select trid from {$wpdb->prefix}icl_translations where element_id ='$childrelid'");
$trid = $get_trid[0]->trid;
if(empty($trid)){
$trid = 0;
}
}
else{
$trid = 0;
}
$wpdb->insert($wpdb->prefix . 'toolset_connected_elements', array(
'element_id' => $childrelid,
'domain' => 'posts',
'wpml_trid' => $trid
));
$pq1 = "select id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$childrelid}'";
$pqres1 = $wpdb->get_results($pq1);
$child_id = $pqres1[0]->id;
$wpdb->get_results("UPDATE {$wpdb->prefix}toolset_connected_elements set group_id = '$child_id' where id = $child_id");
}
$intercon = "select id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$pID}'";
$interconid = $wpdb->get_results($intercon, ARRAY_A);
if($interconid[0]['id']){
$inter_id =$interconid[0]['id'];
}
else{
if (class_exists('SitePress')) {
$get_trid = $wpdb->get_results("select trid from {$wpdb->prefix}icl_translations where element_id ='$pID'");
$trid = $get_trid[0]->trid;
if(empty($trid)){
$trid = 0;
}
}
else{
$trid = 0;
}
$wpdb->insert($wpdb->prefix . 'toolset_connected_elements', array(
'element_id' => $pID,
'domain' => 'posts',
'wpml_trid' => $trid
));
$pqc1 = "select id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$pID}'";
$pqresc1 = $wpdb->get_results($pqc1);
$inter_id = $pqresc1[0]->id;
$wpdb->get_results("UPDATE {$wpdb->prefix}toolset_connected_elements set group_id = '$inter_id' where id = $inter_id");
}
$pquery = "select id from {$wpdb->prefix}toolset_relationships where slug ='{$data_array['relationship_slug']}'";
$post1 = $wpdb->get_results($pquery);
$rel_id = $post1[0]->id;
$get_id = "select id from {$wpdb->prefix}toolset_associations where parent_id=$parent_id and child_id =$child_id and relationship_id=$rel_id";
$getid = $wpdb->get_var($get_id);
if(!empty($getid)){
$wpdb->get_results("UPDATE {$wpdb->prefix}toolset_associations set intermediary_id = $inter_id where id = $getid");
// $wpdb->update($wpdb->prefix.'toolset_associations',array('relationship_id' => $post1[0]->id,'parent_id' => $parent_id ,'child_id' => $child_id
// ,'intermediary_id' => $inter_id));
}
else{
$wpdb->insert($wpdb->prefix.'toolset_associations',array('relationship_id' => $post1[0]->id,'parent_id' => $parent_id ,'child_id' => $child_id
,'intermediary_id' => $inter_id));
}
}
}
}

View File

@@ -0,0 +1,50 @@
<?php
/******************************************************************************************
* Copyright (C) Smackcoders. - All Rights Reserved under Smackcoders Proprietary License
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* You can contact Smackcoders at email address info@smackcoders.com.
*******************************************************************************************/
namespace Smackcoders\FCSV;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class WPcompleteImport {
private static $wpcomplete_instance = null;
public static function getInstance() {
if (WPCompleteImport::$wpcomplete_instance == null) {
WPCompleteImport::$wpcomplete_instance = new WPCompleteImport;
return WPCompleteImport::$wpcomplete_instance;
}
return WPCompleteImport::$wpcomplete_instance;
}
function set_wpcomplete_values($header_array ,$value_array , $map, $post_id , $type, $hash_key,$gmode,$templatekey){
$post_values = [];
$helpers_instance = ImportHelpers::getInstance();
$post_values = $helpers_instance->get_header_values($map , $header_array , $value_array);
$this->wpcomplete_import_function($post_values,$type, $post_id, $header_array , $value_array, $hash_key,$gmode,$templatekey);
}
function wpcomplete_import_function($data_array, $importas, $pID, $header_array , $value_array, $hash_key,$gmode,$templatekey) {
if(isset($data_array['checkbox']) && $data_array['checkbox']=='yes'){
$d_array =array();
$d_array['buttons'][0] =$pID;
if(isset($data_array['course'])){
$d_array['course'] =$data_array['course'];
}
if(isset($data_array['redirect_url'])){
$d_array['redirect']['title'] =$data_array['redirect_url'];
$d_array['redirect']['url'] ='';
}
}
if(!empty($d_array)){
update_post_meta($pID,'wpcomplete',json_encode($d_array));
}
}
}

View File

@@ -0,0 +1,201 @@
<?php
/******************************************************************************************
* Copyright (C) Smackcoders. - All Rights Reserved under Smackcoders Proprietary License
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* You can contact Smackcoders at email address info@smackcoders.com.
*******************************************************************************************/
namespace Smackcoders\FCSV;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class WPMLImport {
private static $wpml_instance = null;
public static function getInstance() {
if (WPMLImport::$wpml_instance == null) {
WPMLImport::$wpml_instance = new WPMLImport;
return WPMLImport::$wpml_instance;
}
return WPMLImport::$wpml_instance;
}
function set_wpml_values($header_array ,$value_array , $map, $post_id , $type, $line_number){
$post_values = [];
$helpers_instance = ImportHelpers::getInstance();
$post_values = $helpers_instance->get_header_values($map , $header_array , $value_array);
$this->wpml_import_function($post_values,$type, $post_id, $line_number);
}
function wpml_import_function($data_array, $import_as, $pId, $line_number) {
global $sitepress, $wpdb;
global $core_instance;
$site_lang = get_locale();
$lang_code = $data_array['language_code'];
$core_instance = CoreFieldsImport::getInstance();
$extension_object = new ExtensionHandler;
$taxonomies = get_taxonomies();
$is_active = $wpdb->get_var("select active from {$wpdb->prefix}icl_languages where code = '$lang_code'");
if(!$is_active){
$lang_tag = $wpdb->get_var("select code from {$wpdb->prefix}icl_languages where default_locale = '$site_lang'");
if(!empty($lang_tag))
$data_array['language_code'] = $lang_tag;
$core_instance->detailed_log[$line_number]['Instruction'] = "The given language code not configured in WPML.So all are done under default language section.";
}
if (isset($import_as) && in_array($import_as, $taxonomies)) {
$import_type = $import_as;
if($import_type == 'category' || $import_type == 'product_category' || $import_type == 'product_cat' || $import_type == 'wpsc_product_category' || $import_type == 'event-categories'):
$import_as = 'Categories';
elseif($import_type == 'product_tag' || $import_type == 'event-tags' || $import_type == 'post_tag'):
$import_as = 'Tags';
else:
$import_as = 'Taxonomies';
endif;
}
$importAs = $extension_object->import_post_types($import_as );
$get_trid = $wpdb->get_results("select trid from {$wpdb->prefix}icl_translations ORDER BY translation_id DESC limit 1");
$trid = $get_trid[0]->trid;
//Parent lang
if((isset($data_array['translated_taxonomy_title']) && empty($data_array['translated_taxonomy_title'])) || (isset($data_array['translated_post_title']) && empty($data_array['translated_post_title']))){
if($import_as == 'Taxonomies' || $import_as == 'Categories' || $import_as == 'Tags'){
$termdata = get_term_by('name', $data_array['translated_taxonomy_title'],$import_type,'ARRAY_A');
if(is_array($termdata) && !empty($termdata)) {
$element_id = $termdata['term_id'];
$taxo_type = $termdata['taxonomy'];
}
else{
$taxo_type = $import_type;
}
$element_type = 'tax_'.$taxo_type;
$trids = $trid+1;
$term_taxonomy_id = $wpdb->get_var("select term_taxonomy_id from {$wpdb->prefix}term_taxonomy where term_id = $pId");
$set_language_args = array(
'element_id' => $term_taxonomy_id,
'trid' => $trids,
'element_type' => $element_type,
'language_code' => $data_array['language_code']
);
}
else{
//POST,PAGE and Custom Posts
$update_query = $wpdb->prepare("select ID,post_type from $wpdb->posts where post_title = %s and post_type=%s order by ID DESC",$data_array['translated_post_title'] , $importAs);
$ID_result = $wpdb->get_results($update_query);
if(is_array($ID_result) && !empty($ID_result)) {
$element_id = $ID_result[0]->ID;
$post_type = $ID_result[0]->post_type;
}else{
$post_type = $importAs;
}
$element_type = 'post_'.$post_type;
$trids = $trid+1;
$set_language_args = array(
'element_id' => $pId,
'trid' => $trids,
'element_type' => $element_type,
'language_code' => $data_array['language_code']
);
}
do_action( 'wpml_set_element_language_details', $set_language_args );
}
//Child lang
else if(!empty($data_array['language_code'])
&&
((isset($data_array['translated_post_title']) && !empty($data_array['translated_post_title']))
||
(isset($data_array['translated_taxonomy_title']) && !empty($data_array['translated_taxonomy_title'])))
){
if($import_as == 'Taxonomies' || $import_as == 'Categories' || $import_as == 'Tags'){
if($import_as == 'Categories')
$import_as = 'category';
$translate_title = $data_array['translated_taxonomy_title'];
$termdata = get_term_by('name', "$translate_title","$import_type","ARRAY_A");
if(is_array($termdata) && !empty($termdata)) {
$term_id = $termdata['term_id'];
$taxo_type = $termdata['taxonomy'];
$element_id = $wpdb->get_var("select term_taxonomy_id from {$wpdb->prefix}term_taxonomy where term_id = $term_id");
}
else {
$taxo_type = $import_type;
}
if (isset($element_id)) {
$trid_id = apply_filters( 'wpml_element_trid', NULL, $element_id, 'tax_'.$taxo_type);
$args = array('element_id' => $element_id, 'element_type' => 'tax_'.$taxo_type );
$my_language_info = apply_filters( 'wpml_element_language_details', NULL, $args );
if (isset($my_language_info) && isset($my_language_info->language_code)) {
$translate_lcode = $my_language_info->language_code;
}
}
$element_type = 'tax_'.$taxo_type;
$term_taxonomy_id = $wpdb->get_var("select term_taxonomy_id from {$wpdb->prefix}term_taxonomy where term_id = $pId");
$set_language_args = array(
'element_id' => $term_taxonomy_id,
'element_type' => $element_type,
'trid' => isset($trid_id) ? $trid_id : '',
'language_code' => $data_array['language_code'],
'source_language_code' => isset($translate_lcode) ? $translate_lcode : ''
);
do_action( 'wpml_set_element_language_details', $set_language_args );
}
else{
//POST,PAGE,Custom Post
$update_query = $wpdb->prepare("SELECT ID,post_type FROM $wpdb->posts WHERE post_title = %s AND post_type=%s AND post_status NOT IN('%s')order by ID ASC",$data_array['translated_post_title'] , $importAs,'trash');
$ID_result = $wpdb->get_results($update_query);
if(is_array($ID_result) && !empty($ID_result)) {
$element_id = $ID_result[0]->ID;
$post_type = $ID_result[0]->post_type;
}
else{
$post_type = $importAs;
}
$trid_id = apply_filters( 'wpml_element_trid', NULL, $element_id, 'post_'.$post_type );
$args = array('element_id' => $element_id, 'element_type' => 'post_'.$post_type );
$my_language_info = apply_filters( 'wpml_element_language_details', null, $args );
$translate_lcode = $my_language_info->language_code;
$element_type = 'post_'.$post_type;
$set_language_args = array(
'element_id' => $pId,
'element_type' => $element_type,
'trid' => $trid_id,
'language_code' => $data_array['language_code'],
'source_language_code' => $translate_lcode
);
do_action( 'wpml_set_element_language_details', $set_language_args );
}
}
//added - to change lang code in admin view link
if(isset($core_instance->detailed_log[$line_number]['adminLink'])){
$admin_view_link = $this->check_for_wpml_urls($core_instance->detailed_log[$line_number]['adminLink'], $data_array['language_code']);
$core_instance->detailed_log[$line_number]['adminLink'] = $admin_view_link;
}
}
public function check_for_wpml_urls($admin_view_link, $lang_code){
global $wpdb;
if(strpos($admin_view_link, 'lang=') !== FALSE){
$get_existing_lang = explode('lang=', $admin_view_link);
$get_existing_lang_code = substr($get_existing_lang[1], 0, 2);
$existing_lang_string = 'lang='. $get_existing_lang_code;
$current_lang_string = 'lang=' . $lang_code;
$admin_view_link = str_replace($existing_lang_string, $current_lang_string, $admin_view_link);
return $admin_view_link;
}
else {
return $admin_view_link;
}
}
}

View File

@@ -0,0 +1,893 @@
<?php
/******************************************************************************************
* Copyright (C) Smackcoders. - All Rights Reserved under Smackcoders Proprietary License
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* You can contact Smackcoders at email address info@smackcoders.com.
*******************************************************************************************/
namespace Smackcoders\FCSV;
use Smackcoders\FCSV\CoreFieldsImport;
use Smackcoders\FCSV\ImportHelpers;
use Smackcoders\FCSV\MediaHandling;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class WooCommerceCoreImport {
private static $woocommerce_core_instance = null,$media_instance;
public static function getInstance() {
if (WooCommerceCoreImport::$woocommerce_core_instance == null) {
WooCommerceCoreImport::$woocommerce_core_instance = new WooCommerceCoreImport;
WooCommerceCoreImport::$media_instance = new MediaHandling;
return WooCommerceCoreImport::$woocommerce_core_instance;
}
return WooCommerceCoreImport::$woocommerce_core_instance;
}
public function woocommerce_variations_import($data_array , $mode , $check , $unikey ,$unikey_name, $line_number, $variation_count) {
global $wpdb;
$log_table_name = $wpdb->prefix ."import_detail_log";
$core_instance = CoreFieldsImport::getInstance();
$helpers_instance = ImportHelpers::getInstance();
$updated_row_counts = $helpers_instance->update_count($unikey,$unikey_name);
$skipped_count = $updated_row_counts['skipped'];
$productInfo = '';
$returnArr = array('MODE' => $mode , 'ID' => '');
$product_id = isset($data_array['PRODUCTID']) ? $data_array['PRODUCTID'] : '';
$parent_sku = isset($data_array['PARENTSKU']) ? $data_array['PARENTSKU'] : '';
$variation_id = isset($data_array['VARIATIONID']) ? $data_array['VARIATIONID'] : '';
$variation_sku = isset($data_array['VARIATIONSKU']) ? $data_array['VARIATIONSKU'] : '';
if($product_id != '') {
$variation_condition = 'insert_using_product_id';
}
elseif($parent_sku != '') {
$get_parent_product_id = $wpdb->get_results("select id from {$wpdb->prefix}posts where post_status != 'trash' and post_type = 'product' and id in (select post_id from {$wpdb->prefix}postmeta where meta_value = '$parent_sku')");
$count = count( $get_parent_product_id );
$key = 0;
if ( ! empty( $get_parent_product_id ) ) {
$product_id = $get_parent_product_id[$key]->id;
//Check whether the product is variable type
$term_details = wp_get_object_terms($product_id,'product_type');
if((!empty($term_details)) && ($term_details[0]->name != 'variable')){
$core_instance->detailed_log[$line_number]['Message'] = "Skipped,Product is not variable in type.";
$wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey'");
return array('MODE' => $mode,'ID' => '');
}
} else {
$product_id = '';
$core_instance->detailed_log[$line_number]['Message'] = "Skipped,Product is not available.";
$wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey'");
return array('MODE' => $mode,'ID' => '');
}
if($mode == 'Insert'){
$variation_condition = 'insert_using_product_sku';
}
if($variation_sku != '' && $mode == 'Update'){
$variation_condition = 'update_using_variation_sku';
}
if($variation_id != ''){
$variation_condition = 'update_using_variation_id';
}
}
elseif($parent_sku == '' && ($variation_sku != '' || $variation_id != '')){
if($variation_sku != ''){
$variation_condition = 'update_using_variation_sku';
}
if($variation_id != ''){
$variation_condition = 'update_using_variation_id';
}
}
if($variation_sku != '' && $variation_id != ''){
update_post_meta($variation_id, '_sku', $variation_sku);
}
if($product_id != '') {
$is_exist_product = $wpdb->get_results($wpdb->prepare("select * from {$wpdb->prefix}posts where ID = %d", $product_id));
if(!empty($is_exist_product) && $is_exist_product[0]->ID == $product_id) {
$productInfo = $is_exist_product[0];
} else {
#return $returnArr;
}
}
if(isset($variation_condition)){
switch ($variation_condition) {
case 'update_using_variation_id_and_sku':
$get_variation_data = $wpdb->get_results( $wpdb->prepare( "select DISTINCT pm.post_id from {$wpdb->prefix}posts p join {$wpdb->prefix}postmeta pm on p.ID = pm.post_id where p.ID = %d and p.post_type = %s and pm.meta_value = %s", $variation_id, 'product_variation', $variation_sku ) );
if ( ! empty( $get_variation_data ) && $get_variation_data[0]->post_id == $variation_id ) {
$returnArr = $this->importVariationData( $product_id, $variation_id, 'update_using_variation_id_and_sku' ,$unikey , $unikey_name, $line_number, $variation_count,$get_variation_data);
} else {
$returnArr = $this->importVariationData( $product_id, $variation_id, 'default' ,$unikey , $unikey_name, $line_number, $variation_count, $productInfo);
}
break;
case 'update_using_variation_id':
$get_variation_data = $wpdb->get_results( $wpdb->prepare( "select * from {$wpdb->prefix}posts where ID = %d and post_type = %s", $variation_id, 'product_variation' ) );
if ( ! empty( $get_variation_data ) && $get_variation_data[0]->ID == $variation_id ) {
$returnArr = $this->importVariationData( $product_id, $variation_id, 'update_using_variation_id' ,$unikey , $unikey_name, $line_number, $variation_count, $get_variation_data);
} else {
$returnArr = $this->importVariationData( $product_id, $variation_id, 'default',$unikey , $unikey_name, $line_number, $variation_count, $productInfo );
}
break;
case 'update_using_variation_sku':
$variation_data = $wpdb->get_results("select post_id from {$wpdb->prefix}postmeta where meta_value = '$variation_sku' and post_id in (select id from {$wpdb->prefix}posts where post_type = 'product_variation' and post_status != 'trash' and post_parent = $product_id)");
$variation_id = !empty($variation_data) ? $variation_data[0]->post_id : "";
if($variation_id)
$get_variation_data = $wpdb->get_results( $wpdb->prepare( "select * from {$wpdb->prefix}posts where ID = %d and post_type = %s", $variation_id, 'product_variation' ) );
else
$get_variation_data = [];
if ( ! empty( $get_variation_data ) && $get_variation_data[0]->ID == $variation_id) {
$returnArr = $this->importVariationData( $product_id,$variation_id, 'update_using_variation_sku' ,$unikey , $unikey_name, $line_number, $variation_count,$get_variation_data);
} else {
$returnArr = $this->importVariationData( $product_id, $variation_id, 'default' ,$unikey , $unikey_name, $line_number, $variation_count, $productInfo);
}
break;
case 'insert_using_product_id':
$returnArr = $this->importVariationData( $product_id, $variation_id, 'insert_using_product_id',$unikey , $unikey_name, $line_number, $variation_count, $productInfo);
break;
case 'insert_using_product_sku':
$returnArr = $this->importVariationData( $product_id, $variation_id, 'insert_using_product_sku',$unikey ,$unikey_name, $line_number, $variation_count, $productInfo );
break;
default:
$returnArr = $this->importVariationData( $product_id, $variation_id, 'default',$unikey ,$unikey_name, $line_number, $variation_count, $productInfo);
break;
}
}
return $returnArr;
}
public function importVariationData ($product_id, $variation_id, $type,$unikey , $unikey_name, $line_number, $variation_count, $exist_variation_data = array()) {
global $wpdb;
$helpers_instance = ImportHelpers::getInstance();
$core_instance = CoreFieldsImport::getInstance();
global $core_instance;
$log_table_name = $wpdb->prefix ."import_detail_log";
$updated_row_counts = $helpers_instance->update_count($unikey,$unikey_name);
$created_count = $updated_row_counts['created'];
$updated_count = $updated_row_counts['updated'];
$skipped_count = $updated_row_counts['skipped'];
if($type == 'default' || $type == 'insert_using_product_id' || $type == 'insert_using_product_sku') {
$get_count_of_variations = $wpdb->get_results( $wpdb->prepare( "select count(*) as variations_count from {$wpdb->prefix}posts where post_parent = %d and post_type = %s", $product_id, 'product_variation' ) );
$variations_count = $get_count_of_variations[0]->variations_count;
$menu_order_count = 0;
if ($variations_count == 0) {
$variations_count = '';
$menu_order= 0 ;
} else {
$variations_count = $variations_count + 1;
$menu_order_count = $variations_count - 1;
$variations_count = '-' . $variations_count;
}
$get_variation_data = $wpdb->get_results($wpdb->prepare("select * from {$wpdb->prefix}posts where ID = %d", $product_id));
foreach($get_variation_data as $key => $val) {
if($product_id == $val->ID){
$variation_data = array();
$variation_data['post_title'] = $val->post_title ;
$variation_data['post_date'] = $val->post_date;
$variation_data['post_type'] = 'product_variation';
$variation_data['post_status'] = 'publish';
$variation_data['comment_status'] = 'closed';
$variation_data['ping_status'] = 'closed';
$variation_data['menu_order'] = $menu_order_count;
$variation_data['post_name'] = 'product-' . $val->ID . '-variation' . $variations_count;
$variation_data['post_parent'] = $val->ID;
}
}
//$variation_data=isset($variation_data)?$variation_data:'';
$variationid = wp_insert_post($variation_data);
if(empty($variation_count)){
$core_instance->detailed_log[$line_number]['Message'] = 'Inserted Variation ID: ' . $variationid;
}
else{
$parent_id = $wpdb->get_var( "SELECT post_parent FROM {$wpdb->prefix}posts WHERE id = '$variationid' " );
$core_instance->detailed_log[$line_number]['Message'] = 'Inserted Product ID: ' . $parent_id . ' Inserted Variation ID: ' . $variationid;
}
$wpdb->get_results("UPDATE $log_table_name SET created = $created_count WHERE $unikey_name = '$unikey'");
$returnArr = array( 'ID' => $variationid, 'MODE' => 'Inserted' );
return $returnArr;
} elseif ($type == 'update_using_variation_id' || $type == 'update_using_variation_sku' || $type == 'update_using_variation_id_and_sku') {
$core_instance->detailed_log[$line_number]['Message'] = 'Updated Variation ID: ' . $variation_id;
$wpdb->get_results("UPDATE $log_table_name SET updated = $updated_count WHERE $unikey_name = '$unikey'");
$returnArr = array( 'ID' => $variation_id, 'MODE' => 'Updated');
return $returnArr;
}
}
public function woocommerce_orders_import($data_array , $mode , $check , $unikey , $unikey_name, $line_number) {
$returnArr = array();
global $wpdb;
$helpers_instance = ImportHelpers::getInstance();
$core_instance = CoreFieldsImport::getInstance();
global $core_instance;
$log_table_name = $wpdb->prefix ."import_detail_log";
$updated_row_counts = $helpers_instance->update_count($unikey,$unikey_name);
$created_count = $updated_row_counts['created'];
$updated_count = $updated_row_counts['updated'];
$skipped_count = $updated_row_counts['skipped'];
$data_array['post_type'] = 'shop_order';
$arraykey = array_keys($data_array);
if(!in_array('customer_note',$arraykey)){
$data_array['post_excerpt'] = '';
}
else{
$data_array['post_excerpt'] = $data_array['customer_note'];
}
if(isset($data_array['order_status'])) {
$data_array['post_status'] = $data_array['order_status'];}
/* Assign order date */
if(!isset( $data_array['order_date'] )) {
$data_array['post_date'] = current_time('Y-m-d H:i:s');
} else {
if(strtotime( $data_array['order_date'] )) {
$data_array['post_date'] = date( 'Y-m-d H:i:s', strtotime( $data_array['order_date'] ) );
} else {
$data_array['post_date'] = current_time('Y-m-d H:i:s');
}
}
if ($mode == 'Insert') {
$retID = wp_insert_post( $data_array );
$mode_of_affect = 'Inserted';
if(is_wp_error($retID) || $retID == '') {
$core_instance->detailed_log[$line_number]['Message'] = "Can't insert this Order. " . $retID->get_error_message();
$wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey'");
return array('MODE' => $mode, 'ERROR_MSG' => $retID->get_error_message());
}
$core_instance->detailed_log[$line_number]['Message'] = 'Inserted Order ID: ' . $retID;
$wpdb->get_results("UPDATE $log_table_name SET created = $created_count WHERE $unikey_name = '$unikey'");
} else {
if ($mode == 'Update') {
if($check == 'ORDERID'){
$orderid = $data_array['ORDERID'];
$post_type = $data_array['post_type'];
$update_query = "select ID from {$wpdb->prefix}posts where ID = '$orderid' and post_type = '$post_type' order by ID DESC";
$ID_result = $wpdb->get_results($update_query);
if (is_array($ID_result) && !empty($ID_result)) {
$retID = $ID_result[0]->ID;
$data_array['ID'] = $retID;
wp_update_post($data_array);
$mode_of_affect = 'Updated';
$core_instance->detailed_log[$line_number]['Message'] = 'Updated Order ID: ' . $retID;
$wpdb->get_results("UPDATE $log_table_name SET updated = $updated_count WHERE $unikey_name = '$unikey'");
} else{
$core_instance->detailed_log[$line_number]['Message'] = "Skipped.";
$wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey'");
return array('MODE' => $mode);
}
}else{
$core_instance->detailed_log[$line_number]['Message'] = "Skipped.";
$wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey'");
return array('MODE' => $mode);
}
}
}
$returnArr['ID'] = $retID;
$returnArr['MODE'] = $mode_of_affect;
return $returnArr;
}
public function woocommerce_coupons_import($data_array , $mode , $check , $unikey , $unikey_name, $line_number) {
global $wpdb;
$helpers_instance = ImportHelpers::getInstance();
$core_instance = CoreFieldsImport::getInstance();
global $core_instance;
$log_table_name = $wpdb->prefix ."import_detail_log";
$updated_row_counts = $helpers_instance->update_count($unikey,$unikey_name);
$created_count = $updated_row_counts['created'];
$updated_count = $updated_row_counts['updated'];
$skipped_count = $updated_row_counts['skipped'];
$returnArr = array();
$data_array['post_type'] = 'shop_coupon';
$data_array['post_title'] = $data_array['coupon_code'];
$data_array['post_name'] = $data_array['coupon_code'];
if(isset($data_array['description'])) {
$data_array['post_excerpt'] = $data_array['description'];
}
/* Post Status Options */
if ( !empty($data_array['coupon_status']) ) {
$data_array = $helpers_instance->assign_post_status( $data_array );
} else {
$data_array['coupon_status'] = 'publish';
}
if ($mode == 'Insert') {
$retID = wp_insert_post($data_array);
$mode_of_affect = 'Inserted';
if(is_wp_error($retID) || $retID == '') {
$core_instance->detailed_log[$line_number]['Message'] = "Can't insert this Coupon. " . $retID->get_error_message();
$wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey'");
return array('MODE' => $mode, 'ERROR_MSG' => $retID->get_error_message());
}
$core_instance->detailed_log[$line_number]['Message'] = 'Inserted Coupon ID: ' . $retID;
$wpdb->get_results("UPDATE $log_table_name SET created = $created_count WHERE $unikey_name = '$unikey'");
} else {
if($check == 'COUPONID'){
$coupon_id = $data_array['COUPONID'];
$post_type = $data_array['post_type'];
$update_query = "select ID from {$wpdb->prefix}posts where ID = '$coupon_id' and post_type = '$post_type' and post_status not in('trash','draft') order by ID DESC";
$ID_result = $wpdb->get_results($update_query);
if (is_array($ID_result) && !empty($ID_result)) {
$retID = $ID_result[0]->ID;
$data_array['ID'] = $retID;
wp_update_post($data_array);
$mode_of_affect = 'Updated';
$core_instance->detailed_log[$line_number]['Message'] = 'Updated Coupon ID: ' . $retID;
$wpdb->get_results("UPDATE $log_table_name SET updated = $updated_count WHERE $unikey_name = '$unikey'");
} else{
$core_instance->detailed_log[$line_number]['Message'] = "Skipped.";
$wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey'");
return array('MODE' => $mode);
}
}
else{
$core_instance->detailed_log[$line_number]['Message'] = "Skipped.";
$wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey'");
return array('MODE' => $mode);
}
//}
}
$returnArr['ID'] = $retID;
$returnArr['MODE'] = $mode_of_affect;
return $returnArr;
}
public function woocommerce_refunds_import($data_array , $mode , $check ,$unikey , $unikey_name, $line_number) {
$returnArr = array();
$mode_of_affect = 'Inserted';
global $wpdb;
$helpers_instance = ImportHelpers::getInstance();
$core_instance = CoreFieldsImport::getInstance();
global $core_instance;
$log_table_name = $wpdb->prefix ."import_detail_log";
$updated_row_counts = $helpers_instance->update_count($unikey,$unikey_name);
$created_count = $updated_row_counts['created'];
$updated_count = $updated_row_counts['updated'];
$skipped_count = $updated_row_counts['skipped'];
$parent_order_id = 0;
$post_excerpt = '';
if(isset($data_array['REFUNDID']))
$order_id = $data_array['REFUNDID'];
elseif(isset($data_array['post_parent']))
$parent_order_id = $data_array['post_parent'];
if(isset($data_array['post_excerpt']))
$post_excerpt = $data_array['post_excerpt'];
$get_order_id = $wpdb->get_results($wpdb->prepare("select * from {$wpdb->prefix}posts where ID = %d", $parent_order_id));
if(!empty($get_order_id)){
$refund = $get_order_id[0]->ID;
if(isset($refund)){
$date_format = date('m-j-Y-Hi-a');
$date_read = date('M j, Y @ H:i a');
$data_array['post_title'] = 'Refund &ndash;' . $date_read;
$data_array['post_type'] = 'shop_order_refund';
$data_array['post_parent'] = $parent_order_id;
$data_array['post_status'] = 'wc-completed';
$data_array['post_name'] = 'refund-'.$date_format;
$data_array['guid'] = site_url() . '?shop_order_refund=' . 'refund-'.$date_format;
}
}
if ($mode == 'Insert') {
$retID = wp_insert_post( $data_array );
update_post_meta($retID , '_refund_reason' , $post_excerpt);
$update_array = array();
$update_array['ID'] = $parent_order_id;
$update_array['post_status'] = 'wc-refunded';
$update_array['post_modified'] = date('Y-m-d H:i:s');
$update_array['post_modified_gmt'] = date('Y-m-d H:i:s');
wp_update_post($update_array);
if(is_wp_error($retID) || $retID == '') {
$core_instance->detailed_log[$line_number]['Message'] = "Can't insert this Refund. " . $retID->get_error_message();
$wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey'");
return array('MODE' => $mode, 'ERROR_MSG' => $retID->get_error_message());
}
$core_instance->detailed_log[$line_number]['Message'] = 'Inserted Refund ID: ' . $retID;
$wpdb->get_results("UPDATE $log_table_name SET created = $created_count WHERE $unikey_name = '$unikey'");
}
else{
if($check == 'REFUNDID'){
$refund_id = $data_array['REFUNDID'];
$update_query = "select ID from {$wpdb->prefix}posts where ID = '$refund_id' and post_type = 'shop_order_refund' order by ID DESC";
$ID_result = $wpdb->get_results($update_query);
if (is_array($ID_result) && !empty($ID_result)) {
$retID = $ID_result[0]->ID;
$data_array['ID'] = $retID;
wp_update_post($data_array);
update_post_meta($retID , '_refund_reason' , $post_excerpt);
$mode_of_affect = 'Updated';
$core_instance->detailed_log[$line_number]['Message'] = 'Updated Refund ID: ' . $retID;
$wpdb->get_results("UPDATE $log_table_name SET updated = $updated_count WHERE $unikey_name = '$unikey'");
}else{
if($mode == 'Update'){
$core_instance->detailed_log[$line_number]['Message'] = "Skipped.";
$wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey'");
return array('MODE' => $mode);
}
}
}else{
if($mode == 'Update'){
$core_instance->detailed_log[$line_number]['Message'] = "Skipped.";
$wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey'");
return array('MODE' => $mode);
}
}
}
$returnArr['ID'] = $retID;
$returnArr['MODE'] = $mode_of_affect;
return $returnArr;
}
public function woocommerce_attributes_import($data_array , $mode , $check , $unikey , $unikey_name, $line_number) {
global $wpdb;
$helpers_instance = ImportHelpers::getInstance();
$core_instance = CoreFieldsImport::getInstance();
global $core_instance;
$returnArr = array();
$name = $data_array['name'];
$slug = $data_array['slug'];
$configure_terms = $data_array['configure_terms'];
$attr = $data_array['default_sort_order'];
if($attr == 'Custom ordering'){
$attr = 'menu_order';
}
if($attr == 'Name (numeric)'){
$attr = 'name_num';
}
if($attr == 'Term ID'){
$attr = 'id';
}
if($attr == 'Name'){
$attr = 'name';
}
$attribute=$data_array['enable_archive'];
$log_table_name = $wpdb->prefix ."import_detail_log";
$updated_row_counts = $helpers_instance->update_count($unikey,$unikey_name);
$created_count = $updated_row_counts['created'];
$updated_count = $updated_row_counts['updated'];
$skipped_count = $updated_row_counts['skipped'];
if($check == 'name') {
$result = $wpdb->get_row("select attribute_id from {$wpdb->prefix}woocommerce_attribute_taxonomies where attribute_label='".$name."'");
}
if($check == 'slug') {
$result = $wpdb->get_row("select attribute_id from {$wpdb->prefix}woocommerce_attribute_taxonomies where attribute_name='".$slug."'");
}
$duplicate_check = $wpdb->get_row("select attribute_id from {$wpdb->prefix}woocommerce_attribute_taxonomies where attribute_name='".$slug."'");
if($mode == 'Insert') {
if (!empty($result) || (!empty($duplicate_check))) {
$core_instance->detailed_log[$line_number]['Message'] = 'Skipped Product attribute';
$wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey'");
$returnArr['Mode'] = $mode;
return $returnArr;
}else{
$wpdb->query("insert into {$wpdb->prefix}woocommerce_attribute_taxonomies(attribute_label,attribute_name,attribute_type,attribute_orderby,attribute_public) values('".$name."','".$slug."','select','".$attr."','".$attribute."')");
$id = $wpdb->insert_id;
$existing_attributes = array();
$existing_attributes = get_option('_transient_wc_attribute_taxonomies', true);
$at = array(
'attribute_id'=>$id,
'attribute_name'=>$slug,
'attribute_label'=>$name,
'attribute_type'=>'select',
'attribute_orderby'=>$attr,
'attribute_public'=>$attribute
);
$at=(object)$at;
array_push($existing_attributes,$at);
update_option('_transient_wc_attribute_taxonomies',$existing_attributes);
if(isset($configure_terms)){
$taxo = 'pa_'.$slug;
register_taxonomy($taxo , 'product');
$configure_exp = explode(',' , $configure_terms);
foreach($configure_exp as $config_values){
$check_term = term_exists($config_values);
if(isset($check_term)){
}else{
wp_insert_term($config_values , $taxo);
}
}
}
$core_instance->detailed_log[$line_number]['Message'] = 'Inserted Product attribute ID: '.$id;
$wpdb->get_results("UPDATE $log_table_name SET created = $created_count WHERE $unikey_name = '$unikey'");
}
}
if($mode == 'Update') {
if(!empty($result)) {
foreach($result as $res=>$value) {
$id = $value;
}
$wpdb->query("update {$wpdb->prefix}woocommerce_attribute_taxonomies set attribute_label='".$name."',attribute_name='".$slug."',attribute_type='select',attribute_orderby='".$attr."',attribute_public='".$attribute."' where attribute_id='".$id."'");
$wpdb->query("delete from ".$wpdb->prefix."options where option_name='_transient_wc_attribute_taxonomies'");
$at = array( 'attribute_id'=>$id,
'attribute_name'=>$slug,
'attribute_label'=>$name,
'attribute_type'=>'select',
'attribute_orderby'=>$attr,
'attribute_public'=>$attribute
);
$at=(object)$at;
$a=array($at);
update_option('_transient_wc_attribute_taxonomies',$a);
if(isset($configure_terms)){
$taxo = 'pa_'.$slug;
$configure_exp = explode(',' , $configure_terms);
foreach($configure_exp as $config_values){
$check_term = term_exists($config_values);
if(isset($check_term)){
}else{
if($mode == 'Import-Update'){
wp_insert_term($config_values , $taxo);
}
}
}
}
$core_instance->detailed_log[$line_number]['Message'] = 'Updated Product attribute ID: '.$id;
$wpdb->get_results("UPDATE $log_table_name SET updated = $updated_count WHERE $unikey_name = '$unikey'");
} else{
if($mode == 'Update'){
$core_instance->detailed_log[$line_number]['Message'] = 'Skipped';
$wpdb->get_results("UPDATE $log_table_name SET created = $created_count WHERE $unikey_name = '$unikey'");
return array('MODE' => $mode);
}
}
}
$returnArr['ID'] = $id;
return $returnArr;
}
public function woocommerce_tags_import($data_array , $mode , $check , $unikey , $unikey_name, $line_number) {
global $wpdb;
$helpers_instance = ImportHelpers::getInstance();
$core_instance = CoreFieldsImport::getInstance();
global $core_instance;
$returnArr = array();
$name = $data_array['name'];
$description = $data_array['description'];
$slug = $data_array['slug'];
$log_table_name = $wpdb->prefix ."import_detail_log";
$updated_row_counts = $helpers_instance->update_count($unikey,$unikey_name);
$created_count = $updated_row_counts['created'];
$updated_count = $updated_row_counts['updated'];
$skipped_count = $updated_row_counts['skipped'];
if ($check == 'TERMID') {
$term_id = $data_array['TERMID'];
$termid =$wpdb->get_row("select term_id from {$wpdb->prefix}terms where term_id = '$term_id' ");
}
if($check == 'slug') {
$termid =$wpdb->get_row("select term_id from {$wpdb->prefix}terms where slug='".$slug."'");
}
if($mode == 'Insert') {
if (!empty($termid)) {
$core_instance->detailed_log[$line_number]['Message'] = 'Skipped Product tag';
$wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey'");
$returnArr['Mode'] = $mode;
return $returnArr;
#skipped
}else{
$wpdb->query("insert into {$wpdb->prefix}terms(name,slug) values ('".$name."','".$slug."')");
$id = $wpdb->insert_id;
$wpdb->query("insert into {$wpdb->prefix}term_taxonomy(term_taxonomy_id,term_id,taxonomy,description) values('".$id."','".$id."','product_tag','".$description."')");
$core_instance->detailed_log[$line_number]['Message'] = 'Inserted Product tag ID: '.$id;
$wpdb->get_results("UPDATE $log_table_name SET created = $created_count WHERE $unikey_name = '$unikey'");
}
}
if($mode == 'Update'){
if (!empty($termid)) {
foreach($termid as $term =>$value) {
$id = $value;
}
$wpdb->query("update {$wpdb->prefix}terms set name='".$name."',slug='".$slug."' where term_id='".$id."'");
$wpdb->query("update {$wpdb->prefix}term_taxonomy set term_taxonomy_id='".$id."',term_id='".$id."',taxonomy='product_tag',description='".$description."' where term_id='".$id."'");
$core_instance->detailed_log[$line_number]['Message'] = 'Updated Product tag ID: '.$id;
$wpdb->get_results("UPDATE $log_table_name SET updated = $updated_count WHERE $unikey_name = '$unikey'");
}else{
$core_instance->detailed_log[$line_number]['Message'] = 'Skipped.';
$wpdb->get_results("UPDATE $log_table_name SET created = $created_count WHERE $unikey_name = '$unikey'");
$returnArr['Mode'] = $mode;
return $returnArr;
//return array('MODE' => $mode);
}
}
$returnArr['ID'] = $id;
return $returnArr;
}
public function woocommerce_product_import($data_array, $mode, $type, $unmatched_row , $check , $unikey , $unikey_name, $line_number , $acf,$pods, $toolset, $header_array ,$value_array, $wpml_values = null) {
global $wpdb,$core_instance,$sitepress;
$core_instance = CoreFieldsImport::getInstance();
$helpers_instance = ImportHelpers::getInstance();
$log_table_name = $wpdb->prefix ."import_detail_log";
$data_array['PRODUCTSKU']=isset($data_array['PRODUCTSKU'])?$data_array['PRODUCTSKU']:'';
$data_array['PRODUCTSKU'] = trim($data_array['PRODUCTSKU']);
$returnArr = array();
$assigned_author = '';
$mode_of_affect = 'Inserted';
$data_array['post_type'] = 'product';
$data_array = $core_instance->import_core_fields($data_array);
$post_type = $data_array['post_type'];
if($check == 'ID'){
$ID = $data_array['ID'];
$get_result = $wpdb->get_results("SELECT ID FROM {$wpdb->prefix}posts WHERE ID = '$ID' AND post_type = '$post_type' AND post_status != 'trash' order by ID DESC ");
}
if($check == 'post_title'){
$title = $data_array['post_title'];
$get_result = $wpdb->get_results("SELECT ID FROM {$wpdb->prefix}posts WHERE post_title = '$title' AND post_type = '$post_type' AND post_status != 'trash' order by ID DESC ");
}
if($check == 'post_name'){
$name = $data_array['post_name'];
if($sitepress != null) {
$language_code = $wpml_values['language_code'];
$get_result = $wpdb->get_results("SELECT DISTINCT p.ID FROM {$wpdb->prefix}posts p join {$wpdb->prefix}icl_translations pm ON p.ID = pm.element_id WHERE p.post_name = '$name' AND p.post_type = '$post_type' AND p.post_status != 'trash' AND pm.language_code = '{$language_code}'");
}
else{
$get_result = $wpdb->get_results("SELECT ID FROM {$wpdb->prefix}posts WHERE post_name = '$name' AND post_type = '$post_type' AND post_status != 'trash' order by ID DESC ");
}
}
if($check == 'PRODUCTSKU'){
$sku = $data_array['PRODUCTSKU'];
if($sitepress != null) {
$language_code = $wpml_values['language_code'];
$get_result = $wpdb->get_results("SELECT DISTINCT p.ID FROM {$wpdb->prefix}posts p join {$wpdb->prefix}postmeta pm ON p.ID = pm.post_id inner join {$wpdb->prefix}icl_translations icl ON pm.post_id = icl.element_id WHERE p.post_type = 'product' AND p.post_status != 'trash' and pm.meta_value = '$sku' and icl.language_code = '{$language_code}'");
}
else{
$get_result = $wpdb->get_results("SELECT DISTINCT p.ID FROM {$wpdb->prefix}posts p join {$wpdb->prefix}postmeta pm ON p.ID = pm.post_id WHERE p.post_type = 'product' AND p.post_status != 'trash' and pm.meta_value = '$sku' ");
}
}
$update = array('ID','post_title','post_name','PRODUCTSKU');
if(!in_array($check, $update)){
if(is_plugin_active('advanced-custom-fields-pro/acf.php')||is_plugin_active('advanced-custom-fields/acf.php')){
if(is_array($acf)){
$get_key = "";
foreach($acf as $acf_key => $acf_value){
if($acf_key == $check){
$get_key= array_search($acf_value , $header_array);
}
if($get_key && isset($value_array[$get_key])){
$csv_element = $value_array[$get_key];
$get_result = $wpdb->get_results("SELECT post_id FROM {$wpdb->prefix}postmeta as a join {$wpdb->prefix}posts as b on a.post_id = b.ID WHERE a.meta_key = '$check' AND a.meta_value = '$csv_element' AND b.post_status != 'trash' order by a.post_id DESC ");
}
}
}
if(empty($get_result)) {
$core_instance->detailed_log[$line_number]['Message'] = "Skipped, Due to existing field value is not presents.";
}
}
}
if(!in_array($check, $update)){
if(is_plugin_active('pods/init.php')){
if(is_array($pods)){
foreach($pods as $pods_key => $pods_value){
if($pods_key == $check){
$get_key= array_search($pods_value , $header_array);
}
if(isset($value_array[$get_key])){
$csv_element = $value_array[$get_key];
}
$get_result = $wpdb->get_results("SELECT post_id FROM {$wpdb->prefix}postmeta as a join {$wpdb->prefix}posts as b on a.post_id = b.ID WHERE a.meta_key = '$check' AND a.meta_value = '$csv_element' AND b.post_status != 'trash' order by a.post_id DESC ");
}
}
if(empty($get_result)) {
$core_instance->detailed_log[$line_number]['Message'] = "Skipped, Due to existing field value is not presents.";
}
}
}
if(!in_array($check, $update)){
if(is_plugin_active('types/wpcf.php')){
if(is_array($toolset)){
foreach($toolset as $tool_key => $tool_value){
if($tool_key == $check){
$get_key= array_search($tool_value , $header_array);
}
if(isset($value_array[$get_key]) && isset($get_key)){
$csv_element = $value_array[$get_key];
$key='wpcf-'.$check;
$get_result = $wpdb->get_results("SELECT post_id FROM {$wpdb->prefix}postmeta as a join {$wpdb->prefix}posts as b on a.post_id = b.ID WHERE a.meta_key = '$key' AND a.meta_value = '$csv_element' AND b.post_status != 'trash' order by a.post_id DESC ");
}
}
}
if(empty($get_result)) {
$core_instance->detailed_log[$line_number]['Message'] = "Skipped, Due to existing field value is not presents.";
}
}
}
$updated_row_counts = $helpers_instance->update_count($unikey,$unikey_name);
$created_count = $updated_row_counts['created'];
$updated_count = $updated_row_counts['updated'];
$skipped_count = $updated_row_counts['skipped'];
if ($mode == 'Insert') {
if(!isset( $data_array['post_date'] )) {
$data_array['post_date'] = current_time('Y-m-d H:i:s');
} else {
if(strtotime( $data_array['post_date'] )) {
$data_array['post_date'] = date( 'Y-m-d H:i:s', strtotime( $data_array['post_date'] ) );
} else {
$data_array['post_date'] = current_time('Y-m-d H:i:s');
}
}
if (isset($get_result) && is_array($get_result) && !empty($get_result)) {
#skipped
$core_instance->detailed_log[$line_number]['Message'] = "Skipped, Due to duplicate Product found!.";
$wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey'");
return array('MODE' => $mode);
}else{
$post_id = wp_insert_post($data_array);
$data_array['post_format']=isset($data_array['post_format'])?$data_array['post_format']:'';
set_post_format($post_id , $data_array['post_format']);
if(!empty($data_array['PRODUCTSKU'])){
update_post_meta($post_id , '_sku' , $data_array['PRODUCTSKU']);
}
if(is_wp_error($post_id) || $post_id == '') {
# skipped
$core_instance->detailed_log[$line_number]['Message'] = "Can't insert this Product. " . $post_id->get_error_message();
$wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey'");
return array('MODE' => $mode);
}
if($unmatched_row == 'true'){
global $wpdb;
$post_entries_table = $wpdb->prefix ."post_entries_table";
$file_table_name = $wpdb->prefix."smackcsv_file_events";
$get_id = $wpdb->get_results( "SELECT file_name FROM $file_table_name WHERE `$unikey_name` = '$unikey'");
$file_name = $get_id[0]->file_name;
$wpdb->get_results("INSERT INTO $post_entries_table (`ID`,`type`, `file_name`,`status`) VALUES ( '{$post_id}','{$type}', '{$file_name}','Inserted')");
}
$core_instance->detailed_log[$line_number]['Message'] = 'Inserted Product ID: ' . $post_id . ', ' . $assigned_author;
$wpdb->get_results("UPDATE $log_table_name SET created = $created_count WHERE $unikey_name = '$unikey'");
}
}
if($mode == 'Update'){
if(isset($core_instance->detailed_log[$line_number]['Message']) && preg_match("(Skipped)", $core_instance->detailed_log[$line_number]['Message']) !== 0) {
$wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey'");
$returnArr['MODE'] = $mode_of_affect;
}
else {
if (is_array($get_result) && !empty($get_result)) {
if(!in_array($check, $update)){
$post_id = $get_result[0]->post_id;
$data_array['ID'] = $post_id;
}else{
$post_id = $get_result[0]->ID;
$data_array['ID'] = $post_id;
}
wp_update_post($data_array);
$data_array['post_format']=isset($data_array['post_format'])?$data_array['post_format']:'';
set_post_format($post_id , $data_array['post_format']);
if(!empty($data_array['PRODUCTSKU'])){
update_post_meta($post_id , '_sku' , $data_array['PRODUCTSKU']);
}
if($unmatched_row == 'true'){
global $wpdb;
$post_entries_table = $wpdb->prefix ."post_entries_table";
$file_table_name = $wpdb->prefix."smackcsv_file_events";
$get_id = $wpdb->get_results( "SELECT file_name FROM $file_table_name WHERE `$unikey_name` = '$unikey'");
$file_name = $get_id[0]->file_name;
$wpdb->get_results("INSERT INTO $post_entries_table (`ID`,`type`, `file_name`,`status`) VALUES ( '{$post_id}','{$type}', '{$file_name}','Updated')");
}
$core_instance->detailed_log[$line_number]['Message'] = 'Updated Product ID: ' . $post_id . ', ' . $assigned_author;
$wpdb->get_results("UPDATE $log_table_name SET updated = $updated_count WHERE $unikey_name = '$unikey'");
}else{
$posttitle = $data_array['post_title'];
$productsku = $data_array['PRODUCTSKU'];
if(!empty($posttitle)){
$post_id = wp_insert_post($data_array);
$data_array['post_format'] = isset($data_array['post_format'])?$data_array['post_format']:'';
set_post_format($post_id , $data_array['post_format']);
if(is_wp_error($post_id) || $post_id == '') {
# skipped
$core_instance->detailed_log[$line_number]['Message'] = "Can't insert this Product. " . $post_id->get_error_message();
$wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey'");
return array('MODE' => $mode);
}
if($unmatched_row == 'true'){
global $wpdb;
$post_entries_table = $wpdb->prefix ."post_entries_table";
$file_table_name = $wpdb->prefix."smackcsv_file_events";
$get_id = $wpdb->get_results( "SELECT file_name FROM $file_table_name WHERE `$unikey_name` = '$unikey'");
$file_name = $get_id[0]->file_name;
$wpdb->get_results("INSERT INTO $post_entries_table (`ID`,`type`, `file_name`,`status`) VALUES ( '{$post_id}','{$type}', '{$file_name}','Inserted')");
}
$core_instance->detailed_log[$line_number]['Message'] = 'Inserted Product ID: ' . $post_id . ', ' . $assigned_author;
$wpdb->get_results("UPDATE $log_table_name SET created = $created_count WHERE $unikey_name = '$unikey'");
}
else{
$core_instance->detailed_log[$line_number]["Message"] = "Skipped. SKU: ".$productsku."<br>";
$wpdb->get_results("UPDATE $log_table_name SET skipped = $skipped_count WHERE $unikey_name = '$unikey'");
// return array('MODE' => $mode);
}
}
}
}
$returnArr['ID'] = $post_id;
$returnArr['MODE'] = $mode_of_affect;
if (!empty($data_array['post_author'])) {
$returnArr['AUTHOR'] = isset($assigned_author) ? $assigned_author : '';
}
return $returnArr;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,98 @@
<?php
/**
* WP Ultimate CSV Importer plugin file.
*
* Copyright (C) 2010-2020, Smackcoders Inc - info@smackcoders.com
*/
namespace Smackcoders\FCSV;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class WordpressCustomImport {
private static $wordpress_custom_instance = null,$media_instance;
public static function getInstance() {
if (WordpressCustomImport::$wordpress_custom_instance == null) {
WordpressCustomImport::$wordpress_custom_instance = new WordpressCustomImport;
WordpressCustomImport::$media_instance = MediaHandling::getInstance();
return WordpressCustomImport::$wordpress_custom_instance;
}
return WordpressCustomImport::$wordpress_custom_instance;
}
function set_wordpress_custom_values($header_array ,$value_array , $map, $post_id , $type,$hash_key,$line_number,$templatekey,$gmode){
$post_values = [];
$helpers_instance = ImportHelpers::getInstance();
$post_values = $helpers_instance->get_header_values($map , $header_array , $value_array);
$this->wordpress_custom_import_function($post_values, $post_id ,$type , 'off',$hash_key,$line_number,$templatekey,$gmode);
}
public function wordpress_custom_import_function($data_array, $pID, $importType, $core_serialize_info, $hash_key, $line_number, $templatekey, $gmode) {
global $wpdb;
$createdFields = array();
if (!empty($data_array)) {
if(!empty($data_array) && !is_plugin_active('masterstudy-lms-learning-management-system/masterstudy-lms-learning-management-system.php') ) {
foreach ($data_array as $custom_key => $custom_value) {
$createdFields[] = $custom_key;
if ($importType != 'Users') {
if ((isset($core_serialize_info[$custom_key]) && $core_serialize_info[$custom_key] == 'on') || is_plugin_active('wpml-import/plugin.php')) {
// Check if value is serialized,
if (is_serialized($custom_value)) {
$custom_value = maybe_unerialize($custom_value);
}
$get_meta_info = $wpdb->get_results($wpdb->prepare("SELECT meta_key, meta_value FROM {$wpdb->prefix}postmeta WHERE post_id=%d AND meta_key=%s", $pID, $custom_key), ARRAY_A);
if (!empty($get_meta_info)) {
$wpdb->update($wpdb->prefix . 'postmeta', array('meta_value' => $custom_value), array('meta_key' => $custom_key, 'post_id' => $pID));
} else {
$wpdb->insert($wpdb->prefix . 'postmeta', array('meta_key' => $custom_key, 'meta_value' => $custom_value, 'post_id' => $pID));
}
} else {
if (is_serialized($custom_value)) {
$custom_value = maybe_unerialize($custom_value);
}
if (is_array($custom_value) || is_object($custom_value)) {
// Convert to JSON format
$custom_value = json_encode($custom_value);
}
update_post_meta($pID, $custom_key, $custom_value);
}
} else {
if (isset($core_serialize_info[$custom_key]) && $core_serialize_info[$custom_key] == 'on') {
// Check if value is serialized,
if (!is_serialized($custom_value)) {
$custom_value = maybe_serialize($custom_value);
}
$get_meta_info = $wpdb->get_results($wpdb->prepare("SELECT meta_key, meta_value FROM {$wpdb->prefix}usermeta WHERE user_id=%d AND meta_key=%s", $pID, $custom_key), ARRAY_A);
if (!empty($get_meta_info)) {
$wpdb->update($wpdb->prefix . 'usermeta', array('meta_value' => $custom_value), array('meta_key' => $custom_key, 'user_id' => $pID));
} else {
$wpdb->insert($wpdb->prefix . 'usermeta', array('meta_key' => $custom_key, 'meta_value' => $custom_value, 'user_id' => $pID));
}
} else {
// Prevent double serialization for non-serialized user fields
if (is_serialized($custom_value)) {
$custom_value = maybe_unerialize($custom_value);
}
update_user_meta($pID, $custom_key, $custom_value);
}
}
}
}
}
return $createdFields;
}
}

View File

@@ -0,0 +1,248 @@
<?php
/******************************************************************************************
* Copyright (C) Smackcoders. - All Rights Reserved under Smackcoders Proprietary License
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* You can contact Smackcoders at email address info@smackcoders.com.
*******************************************************************************************/
namespace Smackcoders\FCSV;
if ( ! defined( 'ABSPATH' ) )
exit; // Exit if accessed directly
class YoastSeoImport {
private static $yoast_instance = null;
public static function getInstance() {
if (YoastSeoImport::$yoast_instance == null) {
YoastSeoImport::$yoast_instance = new YoastSeoImport;
return YoastSeoImport::$yoast_instance;
}
return YoastSeoImport::$yoast_instance;
}
function set_yoast_values($line_number,$header_array ,$value_array , $map, $post_id , $type, $hash_key,$gmode,$templatekey){
$post_values = [];
$helpers_instance = ImportHelpers::getInstance();
$post_values = $helpers_instance->get_header_values($map , $header_array , $value_array);
$this->yoast_import_function($line_number,$post_values,$type, $post_id, $header_array , $value_array, $hash_key,$gmode,$templatekey);
}
function yoast_import_function($line_number,$data_array, $importas, $pID, $header_array , $value_array, $hash_key,$gmode,$templatekey) {
$createdFields = $yoastData = array();
$media_instance = MediaHandling::getInstance();
foreach ($data_array as $dkey => $dvalue) {
$createdFields[] = $dkey;
}
// Import WP Yoast SEO information for Terms & Taxonomies
foreach (get_taxonomies() as $item => $taxonomy_name) {
if($taxonomy_name == $importas) {
if(isset($data_array['title'])) {
$yoastData['wpseo_title']= $data_array['title'];
}
if(isset($data_array['meta_desc'])) {
$yoastData['wpseo_desc'] = $data_array['meta_desc'];
}
if(isset($data_array['meta-robots-noindex'])) {
if($data_array['meta-robots-noindex'] == 1){
$yoastData['wpseo_noindex'] = 'noindex';
}
if($data_array['meta-robots-noindex'] == 2){
$yoastData['wpseo_noindex'] = 'index';
}
}
if(isset($data_array['meta-robots-nofollow'])) {
$yoastData['wpseo_nofollow'] = $data_array['meta-robots-nofollow'];
}
if(isset($data_array['meta-robots-adv'])) {
$yoastData['wpseo_adv'] = $data_array['meta-robots-adv'];
}
if(isset($data_array['bctitle'])) {
$yoastData['wpseo_bctitle'] = $data_array['bctitle'];
}
// if(isset($data_array['sitemap-include'])) {
// $yoastData['wpseo_sitemap_include'] = $data_array['sitemap-include'];
// }
// if(isset($data_array['sitemap-prio'])) {
// $yoastData['wpseo_sitemap_prio'] = $data_array['sitemap-prio'];
// }
if(isset($data_array['canonical'])) {
$yoastData['wpseo_canonical'] = $data_array['canonical'];
}
if(isset($data_array['redirect'])) {
$yoastData['wpseo_redirect'] = $data_array['redirect'];
}
if(isset($data_array['opengraph-title'])) {
$yoastData['wpseo_opengraph-title'] = $data_array['opengraph-title'];
}
if(isset($data_array['opengraph-description'])) {
$yoastData['wpseo_opengraph-description'] = $data_array['opengraph-description'];
}
if(isset($data_array['opengraph-image'])) {
$yoastData['wpseo_opengraph-image'] = urldecode($data_array['opengraph-image']);
$media_instance->store_image_ids($i=1);
$image_id = $media_instance->image_meta_table_entry($line_number,'', $pID, 'opengraph-image', $data_array['opengraph-image'], $hash_key, 'yoast_opengraph','post',$templatekey,$gmode);
$yoastData['wpseo_opengraph-image-id'] = $image_id;
}
if(isset($data_array['twitter-title'])) {
$yoastData['wpseo_twitter-title'] = $data_array['twitter-title'];
}
if(isset($data_array['twitter-description'])) {
$yoastData['wpseo_twitter-description'] = $data_array['twitter-description'];
}
if(isset($data_array['twitter-image'])) {
$yoastData['wpseo_twitter-image'] = urldecode($data_array['twitter-image']);
$media_instance->store_image_ids($i=1);
$imageid = $media_instance->image_meta_table_entry($line_number,'', $pID, 'twitter-image', $data_array['twitter-image'], $hash_key, 'twitter-image','post',$templatekey,$gmode);
$yoastData['wpseo_twitter-image-id'] = $imageid;
}
if(isset($data_array['google-plus-title'])) {
$yoastData['wpseo_google-plus-title'] = $data_array['google-plus-title'];
}
if(isset($data_array['google-plus-description'])) {
$yoastData['wpseo_google-plus-description'] = $data_array['google-plus-description'];
}
if(isset($data_array['google-plus-image'])) {
$yoastData['wpseo_google-plus-image'] = $data_array['google-plus-image'];
}
if(isset($data_array['cornerstone-content'])) {
$yoastData['wpseo_is_cornerstone'] = $data_array['cornerstone-content'];
}
if(isset($data_array['focus_keyword'])) {
$yoastData['wpseo_focuskw'] = $data_array['focus_keyword'];
}
if(isset($data_array['focuskeywords'])) {
$yoastData['wpseo_focuskeywords'] = $this->seo_keyphrase_entry($data_array['focuskeywords']);
}
if(isset($data_array['keywordsynonyms'])) {
$yoastData['wpseo_keywordsynonyms'] = $this->seo_synonym_entry($data_array['keywordsynonyms']);
}
$seo_yoast_cat = get_option('wpseo_taxonomy_meta');
$seo_yoast_cat[$importas][$pID] = $yoastData;
update_option('wpseo_taxonomy_meta', $seo_yoast_cat);
break;
}
}
// Import WP Yoast SEO information for Post types
if (isset($data_array['focus_keyword'])) {
$custom_array['_yoast_wpseo_focuskw'] = $data_array['focus_keyword'];
$custom_array['_yoast_wpseo_focuskw_text_input'] = $data_array['focuskeywords']; //yoast seo pro works
}
if (isset($data_array['title'])) {
$custom_array['_yoast_wpseo_title'] = $data_array['title'];
}
if (isset($data_array['meta_desc'])) {
$custom_array['_yoast_wpseo_metadesc'] = $data_array['meta_desc'];
}
if (isset($data_array['meta_keywords'])) {
$custom_array['_yoast_wpseo_metakeywords'] = $data_array['meta_keywords'];
}
if (isset($data_array['meta-robots-noindex'])) {
$custom_array['_yoast_wpseo_meta-robots-noindex'] = $data_array['meta-robots-noindex'];
}
if (isset($data_array['meta-robots-nofollow'])) {
$custom_array['_yoast_wpseo_meta-robots-nofollow'] = $data_array['meta-robots-nofollow'];
}
if (isset($data_array['meta-robots-adv'])) {
$custom_array['_yoast_wpseo_meta-robots-adv'] = $data_array['meta-robots-adv'];
}
if (isset($data_array['bctitle'])) {
$custom_array['_yoast_wpseo_bctitle'] = $data_array['bctitle'];
}
// if (isset($data_array['sitemap-include'])) {
// $custom_array['_yoast_wpseo_sitemap-include'] = $data_array['sitemap-include'];
// }
// if (isset($data_array['sitemap-prio'])) {
// $custom_array['_yoast_wpseo_sitemap-prio'] = $data_array['sitemap-prio'];
// }
if (isset($data_array['canonical'])) {
$custom_array['_yoast_wpseo_canonical'] = $data_array['canonical'];
}
if (isset($data_array['redirect'])) {
$custom_array['_yoast_wpseo_redirect'] = $data_array['redirect'];
}
if (isset($data_array['opengraph-title'])) {
$custom_array['_yoast_wpseo_opengraph-title'] = $data_array['opengraph-title'];
}
if (isset($data_array['opengraph-description'])) {
$custom_array['_yoast_wpseo_opengraph-description'] = $data_array['opengraph-description'];
}
if (isset($data_array['opengraph-image'])) {
$custom_array['_yoast_wpseo_opengraph-image'] = urldecode($data_array['opengraph-image']);
$media_instance->store_image_ids($i=1);
$image_id = $media_instance->image_meta_table_entry($line_number,'', $pID, 'opengraph-image', $data_array['opengraph-image'], $hash_key, 'yoast_opengraph','post',$templatekey,$gmode);
$custom_array['_yoast_wpseo_opengraph-image-id'] = $image_id;
}
if (isset($data_array['twitter-title'])) {
$custom_array['_yoast_wpseo_twitter-title'] = $data_array['twitter-title'];
}
if (isset($data_array['twitter-description'])) {
$custom_array['_yoast_wpseo_twitter-description'] = $data_array['twitter-description'];
}
if (isset($data_array['twitter-image'])) {
$custom_array['_yoast_wpseo_twitter-image'] = urldecode($data_array['twitter-image']);
$media_instance->store_image_ids($i=1);
$imageid = $media_instance->image_meta_table_entry($line_number,'', $pID, 'twitter-image', $data_array['twitter-image'], $hash_key, 'twitter-image','post',$templatekey,$gmode);
$custom_array['_yoast_wpseo_twitter-image-id'] = $imageid;
}
if (isset($data_array['google-plus-title'])) {
$custom_array['_yoast_wpseo_google-plus-title'] = $data_array['google-plus-title'];
}
if (isset($data_array['google-plus-description'])) {
$custom_array['_yoast_wpseo_google-plus-description'] = $data_array['google-plus-description'];
}
if (isset($data_array['google-plus-image'])) {
$custom_array['_yoast_wpseo_google-plus-image'] = $data_array['google-plus-image'];
}
if (isset($data_array['schema_page_type']) && !empty($data_array['schema_page_type'])) {
$custom_array['_yoast_wpseo_schema_page_type'] = $data_array['schema_page_type'];
}
if (isset($data_array['schema_article_type']) && !empty($data_array['schema_article_type'])) {
$custom_array['_yoast_wpseo_schema_article_type'] = $data_array['schema_article_type'];
}
if(isset($data_array['cornerstone-content']) && $data_array['cornerstone-content'] == '1') {
$custom_array['_yoast_wpseo_is_cornerstone'] = $data_array['cornerstone-content'];
}
if(isset($data_array['focuskeywords'])) {
$custom_array['_yoast_wpseo_focuskeywords'] = $this->seo_keyphrase_entry($data_array['focuskeywords']);
}
if(isset($data_array['keywordsynonyms'])) {
$custom_array['_yoast_wpseo_keywordsynonyms'] = $this->seo_synonym_entry($data_array['keywordsynonyms']);
}
if (!empty ($custom_array)) {
foreach ($custom_array as $custom_key => $custom_value) {
update_post_meta($pID, $custom_key, $custom_value);
}
}
return $createdFields;
}
public function seo_keyphrase_entry($keyphrase_value){
$exp_keywords = explode('|', $keyphrase_value);
$keyword_arr = [];
$temp = 0;
foreach($exp_keywords as $keywords){
$keyword_arr[$temp]['keyword'] = $keywords;
$keyword_arr[$temp]['score'] = "ok";
$temp++;
}
$keyword_value = json_encode($keyword_arr);
return $keyword_value;
}
public function seo_synonym_entry($synonym_value){
$exp_synonym = explode('|', $synonym_value);
array_unshift($exp_synonym,"");
$synonyms_value = json_encode($exp_synonym);
return $synonyms_value;
}
}

View File

@@ -0,0 +1,252 @@
<?php
namespace Smackcoders\FCSV;
if (!defined('ABSPATH')) exit; // Exit if accessed directly
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
class ToolsetImporter {
private static $ToolsetImporter = NULL;
static function getInstance() {
if (self::$ToolsetImporter == NULL) {
self::$ToolsetImporter = new WPToolsetImporter();
//self::$mediaInstance = new MediaHandling();
}
return self::$ToolsetImporter;
}
public function format($Parent_Group,$postTypeValue) {
if(!empty($Parent_Group)) {
return $this->separateElements($Parent_Group,$postTypeValue);
}else {
return 0;
}
}
public function separateElements($parentGroupName,$postTypeValue) {
$explodedParent=$this->explodeFunction('|',$parentGroupName);
global $wpdb;
for ($i = 0; $i < count($explodedParent); $i++)
{
$post_title = $wpdb->_real_escape($explodedParent[$i]);
$result = $wpdb->get_results("SELECT id FROM ".$wpdb->prefix."posts WHERE post_title='{$post_title}' and post_type='{$postTypeValue}'");
if (!empty($result[0]->id)) {
$post_id = $result[0]->id;
$result = $wpdb->get_results("SELECT meta_value FROM ".$wpdb->prefix."postmeta WHERE post_id ='{$post_id}' and meta_key ='_wp_types_group_fields'");
$elementString=$result[0]->meta_value;
$elementArray[]=$this->explodeFunction(',',$elementString);
}
else {
return 0;
}
}
return $elementArray;
}
public function getRelationshipId($groupName)
{
global $wpdb;
$relation_id = $wpdb->get_results("SELECT id FROM ".$wpdb->prefix."toolset_relationships WHERE slug = '{$groupName}'");
$relation_id=$relation_id[0]->id;
return $relation_id;
}
public function insertPost($groupName,$title)
{
global $wpdb;
$post_id = wp_insert_post( array(
'post_status' => 'publish',
'post_title' => $title,
'post_type' => $groupName
));
return $post_id;
}
public function insertRelationship($groupRelationId,$postId,$childPostId)
{
global $wpdb;
//include_once( 'wp-admin/includes/plugin.php' );
$plugins = get_plugins();
$plugin_version = $plugins['types/wpcf.php']['Version'];
if($plugin_version < '3.4.1'){
$wpdb->insert($wpdb->prefix.'toolset_associations', array(
'relationship_id' => $groupRelationId,
'parent_id' => $postId,
'child_id' => $childPostId,
'intermediary_id' => '0'
));
}
else{
// $wpdb->insert($wpdb->prefix.'toolset_associations_old', array(
// 'relationship_id' => $groupRelationId,
// 'parent_id' => $postId,
// 'child_id' => $childPostId,
// 'intermediary_id' => '0'
// ));
$pq = "select id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$postId}'";
$pqres = $wpdb->get_results($pq);
$parent_id = $pqres[0]->id;
if($parent_id){
$parent_id =$parent_id;
}
else{
$get_trid = $wpdb->get_results("select trid from {$wpdb->prefix}icl_translations Where element_id ='$postId'");
if (class_exists('SitePress')) {
$trid = $get_trid[0]->trid;
if(empty($trid)){
$trid = 0;
}
}
else{
$trid = 0;
}
$wpdb->insert($wpdb->prefix . 'toolset_connected_elements', array(
'element_id' => $postId,
'domain' => 'posts',
'wpml_trid' => $trid
));
}
$get_trid = $wpdb->get_results("select trid from {$wpdb->prefix}icl_translations where element_id ='$childPostId'");
if (class_exists('SitePress')) {
$trid = $get_trid[0]->trid;
if(empty($trid)){
$trid = 0;
}
}
else{
$trid = 0;
}
$pq1 = "select id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$postId}'";
$pqres1 = $wpdb->get_results($pq1);
$parent_id = $pqres1[0]->id;
$wpdb->update( $wpdb->prefix . 'toolset_connected_elements' , array( 'group_id' => $parent_id) , array( 'id' => $parent_id ));
$wpdb->insert($wpdb->prefix . 'toolset_connected_elements', array(
'element_id' => $childPostId,
'domain' => 'posts',
'wpml_trid' => $trid
));
$pq2 = "select id from {$wpdb->prefix}toolset_connected_elements where element_id ='{$childPostId}'";
$pqres2 = $wpdb->get_results($pq2);
$child_id = $pqres2[0]->id;
$wpdb->update( $wpdb->prefix . 'toolset_connected_elements' , array( 'group_id' => $child_id) , array( 'id' => $child_id ));
$wpdb->insert($wpdb->prefix.'toolset_associations', array(
'relationship_id' => $groupRelationId,
'parent_id' => $parent_id,
'child_id' => $child_id,
'intermediary_id' => '0'
));
}
}
public function getRepeatableMetaValue($value)
{
global $wpdb;
$meta = $wpdb->get_results("SELECT meta_value FROM ".$wpdb->prefix."postmeta WHERE post_id = {$value} and meta_key = '_wp_types_group_fields'");
return $meta[0]->meta_value;
}
public function getRepeatableName($value)
{
global $wpdb;
$meta = $wpdb->get_results("SELECT post_name FROM ".$wpdb->prefix."posts WHERE id = {$value}");
return $meta[0]->post_name;
}
public function explodeFunction($symbol,$value)
{
$explode = explode($symbol,$value);
foreach($explode as $key => $value)
{
if(is_null($value) || $value == '')
unset($explode[$key]);
}
return $explode;
}
public function getMetaKeys($postId,$postType)
{
global $wpdb;
if ($postType == 'Users') {
return $wpdb->get_results("SELECT umeta_id,meta_key FROM ".$wpdb->prefix."usermeta WHERE user_id = {$postId}",ARRAY_A);
}else{
return $wpdb->get_results("SELECT meta_id,meta_key FROM ".$wpdb->prefix."postmeta WHERE post_id = {$postId}",ARRAY_A);
}
}
public function checkTermKeys($postId,$postType)
{
global $wpdb;
$result=$wpdb->get_results("SELECT term_id FROM ".$wpdb->prefix."term_taxonomy WHERE taxonomy = '{$postType}' ",ARRAY_A);
if (!empty($result)){
return 1;
}
}
public function getTermKeys($postId,$postType)
{
global $wpdb;
return $wpdb->get_results("SELECT meta_id,meta_key FROM ".$wpdb->prefix."termmeta WHERE term_id = {$postId}",ARRAY_A);
}
public function deleteMetaKeys($metaId,$postType)
{
global $wpdb;
if ($postType == 'Users') {
$wpdb->delete( $wpdb->prefix.'usermeta', array( 'umeta_id' => $metaId));
}else{
$wpdb->delete( $wpdb->prefix.'postmeta', array( 'meta_id' => $metaId));
}
}
public function deleteTermMetaKeys($postId,$postType)
{
global $wpdb;
$wpdb->delete( $wpdb->prefix.'termmeta', array( 'term_id' => $postId));
}
public function getMetaKeyId($postId,$metaKeyname,$postType)
{
global $wpdb;
if ($postType == 'Users') {
return $wpdb->get_results("SELECT umeta_id,meta_value FROM ".$wpdb->prefix."usermeta WHERE user_id = {$postId} and meta_key = '{$metaKeyname}'",ARRAY_A);
}else{
return $wpdb->get_results("SELECT meta_id,meta_value FROM ".$wpdb->prefix."postmeta WHERE post_id = {$postId} and meta_key = '{$metaKeyname}'",ARRAY_A);
}
}
public function findRelationship($postId)
{
global $wpdb;
//include_once( 'wp-admin/includes/plugin.php' );
$plugins = get_plugins();
$plugin_version = $plugins['types/wpcf.php']['Version'];
if($plugin_version < '3.4.1'){
return $wpdb->get_results("SELECT id,child_id FROM ".$wpdb->prefix."toolset_associations WHERE parent_id = {$postId}",ARRAY_A);
}
else{
$n=$wpdb->get_results("SELECT group_id FROM ".$wpdb->prefix."toolset_connected_elements WHERE element_id = {$postId}",ARRAY_A);
$pg = $n[0]['group_id'];
return $wpdb->get_results("SELECT id,child_id FROM ".$wpdb->prefix."toolset_associations WHERE parent_id = {$pg}",ARRAY_A);
}
}
}

View File

@@ -0,0 +1,438 @@
<?php
namespace Smackcoders\FCSV;
if (!defined('ABSPATH')) exit; // Exit if accessed directly
/**
*
*/
require_once "ToolsetImporter.php";
class WPToolsetImporter extends ToolsetImporter
{
private static $wpToolsetImporter = NULL,$mediaInstance;
private $dataArray;
private $metaData;
private $fieldType;
private $postType;
private $wpTypesFields;
static function getInstance() {
if (self::$wpToolsetImporter == NULL) {
self::$wpToolsetImporter = new WPToolsetImporter();
self::$mediaInstance = new MediaHandling();
}
return self::$wpToolsetImporter;
}
function set($dataArray, $metaData, $field_Type,$wpTypesFields,$postType) {
$this->dataArray = $dataArray;
$this->metaData = $metaData;
$this->fieldType = $field_Type;
$this->wpTypesFields = $wpTypesFields;
$this->postType = $postType;
}
function import($postId,$post_val,$hash_key,$line_number,$gmode,$templatekey) {
$ToolsetImport = ToolsetImporter::getInstance();
//get fields and groups of homegroup post
if ($this->postType == 'Users') {
$postTypeValue = 'wp-types-user-group';
}else{
$postTypeValue = 'wp-types-group';
}
// $fieldsAndGroups = $this->format($this->dataArray['Parent_Group'],$postTypeValue);
if(isset($this->dataArray['Parent_Group'])){
$fieldsAndGroups = $ToolsetImport->format($this->dataArray['Parent_Group'],$postTypeValue);
}else{
$fieldsAndGroups= 0;
}
if ($fieldsAndGroups == 0) {
$this->insertCustomFields($postId,$this->postType,$post_val, $hash_key,$line_number,$gmode,$templatekey);
}else{
$this->loopAndInsertField($postId,$fieldsAndGroups,0,true,$post_val,$hash_key,$line_number,$gmode,$templatekey);
}
return;
}
function loopAndInsertField($postId,$fieldsAndGroups,$index,$isParent,$post_val,$hash_key,$line_number,$gmode,$templatekey) {
foreach ($fieldsAndGroups as $fieldkey => $fieldvalue) {
foreach ($fieldvalue as $key => $value) {
$data=$this->explodeFunction('_',$value);
if (isset($data[1]) && isset($data[2]) && $data[1]=='repeatable' && $data[2]=='group') {
//send repeatable group id.
$groupName=$this->getRepeatableName($data[3]);
$groupRelationId=$this->getRelationshipId($groupName);
$groups=$this->dataArray[$groupName];
// csv directs to create 2 repetable group
$csvGroupsArray =$this->explodeFunction('|',$groups);
$elementString=$this->getRepeatableMetaValue($data[3]);
//from user created toolset group , don't change the symbol
$elementArray =$this->explodeFunction(',',$elementString);
if ($index < count($csvGroupsArray)) {
for ($i=0; $i < count($csvGroupsArray) ; $i++) {
//create post , post_type = $groupName->ram-house $csvGroupsArray[i]
$childPostId=$this->insertPost($groupName,$csvGroupsArray[$i]);
$this->insertRelationship($groupRelationId,$postId,$childPostId);
$this->loopAndInsertField($childPostId, array($elementArray), $i,false,$post_val,$hash_key,$line_number,$gmode,$templatekey);
update_post_meta($childPostId, 'toolset-post-sortorder', $i+1);
}
}
} else { // simply make entry for homefroup fields.
$fieldValues=$this->dataArray[$value];
$fieldsArray =explode('|',$fieldValues);
$metaKey=$this->metaData[$value];
$fieldType=$this->fieldType[$value];
if (!$isParent) {
if ($index < count($fieldsArray)) {
$fieldValue=$fieldsArray[$index];
$this->checkFieldType($postId,$fieldValue,$fieldType,$metaKey,$post_val,$hash_key,$line_number,$gmode,$templatekey);
}
} else {
$this->checkFieldType($postId,$fieldValues,$fieldType,$metaKey,$post_val,$hash_key,$line_number,$gmode,$templatekey);
}
}
}
}
}
function insertCustomFields($postId,$postType,$post_val, $hash_key,$line_number,$gmode,$templatekey){
foreach ($this->dataArray as $key => $value) {
if(isset($this->fieldType[$key]) && isset($this->metaData[$key])){
$fieldType=$this->fieldType[$key];
$metaKey=$this->metaData[$key];
$listTaxonomy = get_taxonomies();
if(!empty($fieldType) && !empty($metaKey)) {
if ( in_array( $postType, $listTaxonomy ) ) {
$values = explode( '|', $value );
foreach ( $values as $keys => $value1 ) {
$this->insertTermFields( $postId, $value1, $fieldType, $metaKey,$line_number );
}
} else {
$this->checkFieldType( $postId, $value, $fieldType, $metaKey,$post_val,$hash_key,$line_number,$gmode,$templatekey );
}
}
}
}
}
function insertTermFields($postId,$fieldValue,$field_Types,$metaKey,$line_number)
{
if($field_Types=='checkboxes'){
$fieldTypeArray=array_flip($this->metaData);
$fieldTypeValue=$fieldTypeArray[$metaKey];
$term_fields = get_option('wpcf-termmeta');
$wpTypes = $term_fields[$fieldTypeValue]['data']['options'];
//$wpTypes=$this->wpTypesFields[$fieldTypeValue]['data']['options'];
$checkbox_array = array();
$fieldValueArrays =$this->explodeFunction(',',$fieldValue);
foreach ($fieldValueArrays as $keys => $values) {
$values = trim($values);
foreach ($wpTypes as $key1 => $value1) {
if ($values == $value1['title']) {
$term_value = $value1['set_value'];
$checkbox_array[$key1] = array($term_value);
}
}
}
add_term_meta($postId,$metaKey,$checkbox_array);
}
else
{
$this->InsertUpdateTerm($postId,$metaKey,$field_Types,$fieldValue,$line_number);
}
}
function checkFieldType($postId,$fieldValue,$fields_Type,$metaKey,$post_val,$hash_key,$line_number,$gmode,$templatekey){
global $wpdb;
if ($fields_Type == 'checkboxes') {
$fieldValueArray =$this->explodeFunction(',',$fieldValue);
$fieldValueArray=array_flip($fieldValueArray);
$fieldTypeArray=array_flip($this->metaData);
$fieldTypeValue=$fieldTypeArray[$metaKey];
$wpTypes=$this->wpTypesFields[$fieldTypeValue]['data']['options'];
$checkbox_array = array();
foreach ($fieldValueArray as $key => $value) {
$key = trim($key);
foreach ($wpTypes as $key1 => $value1) {
if ($key == $value1['set_value']) {
$checkbox_array[$key1] = array($value1['set_value']);
}
}
}
//update_post_meta($postId, $metaKey, $checkbox_array);
if ($this->postType == 'Users') {
update_user_meta($postId,$metaKey,$checkbox_array);
}else{
update_post_meta($postId,$metaKey,$checkbox_array);
}
}elseif ($fields_Type == 'post') {
$fieldValueArray=array_flip($this->metaData);
$relationshipSlug=$fieldValueArray[$metaKey];
$groupRelationId=$this->getRelationshipId($relationshipSlug);
if (is_numeric($fieldValue)) {
$field_Value=$fieldValue;
}elseif(is_string($fieldValue)){
$query = "SELECT id FROM {$wpdb->prefix}posts WHERE post_title ='{$fieldValue}' AND post_status='publish'";
$name = $wpdb->get_results($query);
if (!empty($name)) {
$field_Value=$name[0]->id;
}else{
return;
}
}
if(!empty($field_Value) && !empty($metaKey)) {
$this->insertRelationship( $groupRelationId, $field_Value, $postId );
update_post_meta( $postId, $metaKey, $field_Value );
}
}else{
//add_post_meta($postId,$metaKey,$fieldValue);add_user_meta
$this->InsertUpdateData($postId,$metaKey,$fields_Type,$fieldValue,$post_val, $hash_key,$line_number,$gmode,$templatekey);
}
}
function InsertUpdateTerm($postId,$metaKey,$fields_Types,$fieldValue,$line_number)
{
$helpers_instance = ImportHelpers::getInstance();
$fieldTypeArray=array_flip($this->metaData);
$fieldTypeValue=$fieldTypeArray[$metaKey];
settype($isRepetitive, "integer");
$isRepetitive=$this->wpTypesFields[$fieldTypeValue]['data']['repetitive'];
if (!empty($isRepetitive) && $isRepetitive == 1) {
$valuesArray =$this->explodeFunction('|',$fieldValue);
foreach ($valuesArray as $values) {
$values=trim($values);
if ($fields_Types == 'date') {
if(!empty($values)) {
$values = trim($values);
//$dateformat = "Y-m-d";
$checkformat = $this->wpTypesFields[$fieldTypeValue]['data']['date_and_time'];
$dateformat =$checkformat == 'date'?"Y-m-d" : "Y-m-d H:i:s";
$fieldnm = substr($metaKey,strpos($metaKey,'-')+1);
$values = $helpers_instance->validate_datefield($values,$fieldnm,$dateformat,$line_number);
$values = strtotime($values);
}
else {
$values = $values;
}
}elseif ($fields_Types == 'skype') {
$values = array(
'skypename' => $values,
'action' => 'chat',
'color' => 'blue',
'size' => '32'
);
}
add_term_meta($postId,$metaKey,$values);
}
}else{
if($isRepetitive == 0){
if ($fields_Types == 'date') {
if(!empty($fieldValue)) {
$fieldValue = trim($fieldValue);
//$dateformat = "Y-m-d";
$checkformat = $this->wpTypesFields[$fieldTypeValue]['data']['date_and_time'];
$dateformat =$checkformat == 'date'?"Y-m-d" : "Y-m-d H:i:s";
$fieldnm = substr($metaKey,strpos($metaKey,'-')+1);
$fieldValue = $helpers_instance->validate_datefield($fieldValue,$fieldnm,$dateformat,$line_number);
$fieldValue = strtotime($fieldValue);
}
else {
$fieldValue = $fieldValue;
}
}elseif ($fields_Types == 'skype') {
$fieldValue = array(
'skypename' => $fieldValue,
'action' => 'chat',
'color' => 'blue',
'size' => '32'
);
}
add_term_meta($postId,$metaKey,$fieldValue);
}
}
}
function InsertUpdateData($postId,$metaKey,$fields_Types,$fieldValue,$post_val,$hash_key,$line_number,$gmode,$templatekey)
{
global $wpdb;
$helpers_instance = ImportHelpers::getInstance();
settype($isRepetitive, "integer");
$fieldTypeArray=array_flip($this->metaData);
$fieldTypeArray[$metaKey] = isset($fieldTypeArray[$metaKey]) ? $fieldTypeArray[$metaKey] : '';
$fieldTypeValue=$fieldTypeArray[$metaKey];
if(isset($this->wpTypesFields[$fieldTypeValue]['data']['repetitive'])){
$isRepetitive=$this->wpTypesFields[$fieldTypeValue]['data']['repetitive'];
}
if (!empty($isRepetitive) && $isRepetitive == 1 && $fields_Types!='image' && $fields_Types != 'file') {
$valuesArray =$this->explodeFunction('|',$fieldValue);
foreach ($valuesArray as $values) {
$values=trim($values);
if ($fields_Types == 'date') {
if(!empty($values)){
$checkformat = $this->wpTypesFields[$fieldTypeValue]['data']['date_and_time'];
$dateformat =$checkformat == 'date'?"Y-m-d" : "Y-m-d H:i:s";
$fieldnm = substr($metaKey,strpos($metaKey,'-')+1);
$values = $helpers_instance->validate_datefield($values,$fieldnm,$dateformat,$line_number);
if(!empty($values))
$values = strtotime($values);
}
else {
$values = $values;
}
}elseif ($fields_Types == 'skype') {
$values = array(
'skypename' => $values,
'action' => 'chat',
'color' => 'blue',
'size' => '32'
);
}
elseif ($fields_Types == 'google_address'){
$values =$values;
}
if ($this->postType == 'Users') {
add_user_meta($postId,$metaKey,$values);
}else{
if($fields_Types == 'google_address'){
add_post_meta($postId,$metaKey,$values);
$meta_id = $wpdb->get_results( $wpdb->prepare( "select meta_id from {$wpdb->prefix}postmeta where meta_key = %s AND post_id = %d", $metaKey,$postId ) );
$array=json_decode(json_encode($meta_id),true);
foreach($array as $key=>$keyval ){
foreach($keyval as $keys => $keysval){
$metadata[$key] = $keysval;
}
}
$meta_key = '_'.$metaKey.'-sort-order';
update_post_meta($postId,$meta_key,$metadata);
}
else{
add_post_meta($postId,$metaKey,$values);
}
}
}
}
if($fields_Types == 'image' || $fields_Types == 'file') {
$plugin = 'types';
$valuesArray =$this->explodeFunction('|',$fieldValue);
foreach($valuesArray as $value) {
$ext = pathinfo($value, PATHINFO_EXTENSION );
if ($ext) {
if ($this->postType == 'Users') {
$get_import_type = 'user';
}
else{
$get_import_type = 'post';
}
if($fields_Types == 'image'){
self::$mediaInstance->store_image_ids($i=1);
$attachid = self::$mediaInstance->image_meta_table_entry($post_val, $postId, $metaKey, $value, $hash_key, 'types', $get_import_type,$templatekey,$gmode);
}else{
$attachid = self::$mediaInstance->media_handling($value, $postId);
}
$attachids[] =$attachid;
if(empty($attachid)){
if ($this->postType == 'Users') {
add_user_meta($postId,$metaKey,$value);
}else{
add_post_meta($postId,$metaKey,$value);
}
}
else{
$guid=$wpdb->get_row("select guid from ".$wpdb->prefix."posts where ID='$attachid'");
$values=$guid->guid;
if ($this->postType == 'Users') {
add_user_meta($postId,$metaKey,$value);
}else{
add_post_meta($postId,$metaKey,$values);
}
}
}
//update_image_meta
$get_existing_image_option = get_option('smack_schedule_image_exists_types_'.$postId);
if($get_existing_image_option){
self::$mediaInstance->acfimageMetaImports($attachids, $post_val, $plugin);
delete_option('smack_schedule_image_exists_types_'.$postId);
}
//self::$mediaInstance->acfimageMetaImports($attachids,$post_val,$plugin);
}
}
else{
if($isRepetitive == 0){
if ($fields_Types == 'date') {
if(!empty($fieldValue)){
$fieldValue = trim($fieldValue);
//$dateformat = "Y-m-d";
$checkformat = $this->wpTypesFields[$fieldTypeValue]['data']['date_and_time'];
$dateformat =$checkformat == 'date'?"Y-m-d" : "Y-m-d H:i:s";
$fieldnm = substr($metaKey,strpos($metaKey,'-')+1);
$fieldValue = $helpers_instance->validate_datefield($fieldValue,$fieldnm,$dateformat,$line_number);
if(!empty($fieldValue))
$fieldValue = strtotime($fieldValue);
}
else {
$fieldValue = $fieldValue;
}
}elseif ($fields_Types == 'skype') {
$fieldValue = array(
'skypename' => $fieldValue,
'action' => 'chat',
'color' => 'blue',
'size' => '32'
);
}elseif($fields_Types == 'google_address'){
$fieldValue = $fieldValue;
}
if ($this->postType == 'Users') {
add_user_meta($postId,$metaKey,$fieldValue);
}else{
if($fields_Types == 'google_address'){
add_post_meta($postId,$metaKey,$fieldValue);
}
else{
add_post_meta($postId,$metaKey,$fieldValue);
}
}
}
}
}
}

View File

@@ -0,0 +1,173 @@
<?php
namespace Smackcoders\FCSV;
if (!defined('ABSPATH')) exit; // Exit if accessed directly
/**
*
*/
require_once "ToolsetImporter.php";
/**
*
*/
class WPToolsetUpdater extends ToolsetImporter
{
private static $WPToolsetUpdater = NULL;
private $dataArray;
private $metadata;
private $fieldType;
private $meta_id;
private $updatedFieldinfo = array();
static function getInstance() {
if (self::$WPToolsetUpdater == NULL) {
self::$WPToolsetUpdater = new WPToolsetUpdater();
}
return self::$WPToolsetUpdater;
}
function set($dataArray, $metaData, $fieldType,$wpTypesFields,$postType) {
$this->dataArray = $dataArray;
$this->metaData = $metaData;
$this->fieldType = $fieldType;
$this->wpTypesFields = $wpTypesFields;
$this->postType = $postType;
if ($this->postType =='Users') {
$this->meta_id ='umeta_id';
}else{
$this->meta_id ='meta_id';
}
}
function update($postId,$post_val,$hash_key,$line_number,$gmode,$templatekey) {
$this->updatedFieldinfo=array();
if (isset($this->dataArray['Parent_Group'])) {
$this->loopAndUpdate($postId);
require_once "WPToolsetImporter.php";
$wpToolsetImporter = WPToolsetImporter::getInstance();
$wpToolsetImporter->set($this->dataArray, $this->metaData, $this->fieldType,$this->wpTypesFields,$this->postType);
$wpToolsetImporter->import($postId,$post_val,$hash_key,$line_number,$gmode,$templatekey);
}else{
$checkTermKeys = $this->checkTermKeys($postId,$this->postType);
if($checkTermKeys==1){
$getTermData = $this->getTermKeys($postId,$this->postType);
$this->deleteTermMetaKeys($postId,$this->postType);
}
else{
$getMetaData = $this->getMetaKeys($postId,$this->postType);
}
$this->deleteCustomFields($getMetaData);
require_once "WPToolsetImporter.php";
$wpToolsetImporter = WPToolsetImporter::getInstance();
$wpToolsetImporter->set($this->dataArray, $this->metaData, $this->fieldType,$this->wpTypesFields,$this->postType);
$wpToolsetImporter->import($postId,$post_val,$hash_key,$line_number,$gmode,$templatekey);
}
}
function loopAndUpdate($postId){
global $wpdb;
$getMetaData = $this->getMetaKeys($postId,$this->postType);
$this->deleteCustomFields($getMetaData);
$allRelationship=$this->findRelationship($postId);
$plugins = get_plugins();
$plugin_version = $plugins['types/wpcf.php']['Version'];
if (!empty($allRelationship)) {
foreach ($allRelationship as $key => $value) {
$this->loopAndUpdate($value['child_id']);
if($plugin_version < '3.4.1'){
$wpdb->delete( $wpdb->prefix.'toolset_associations', array( 'id' => $value['id']));
$wpdb->delete( $wpdb->prefix.'posts', array( 'id' => $value['child_id']));
}
else{
$pquery = "select element_id from {$wpdb->prefix}toolset_connected_elements where id ='{$value['child_id']}'";
$pqueryres1 = $wpdb->get_results($pquery);
$p_id = $pqueryres1[0]->element_id;
$wpdb->delete( $wpdb->prefix.'toolset_associations', array( 'id' => $value['id']));
//$wpdb->delete( $wpdb->prefix.'toolset_associations', array( 'id' => $p_id));
$wpdb->delete( $wpdb->prefix.'posts', array( 'id' => $p_id));
}
}
}
}
function deleteCustomFields($getMetaData){
if (!empty($getMetaData)) {
foreach ($getMetaData as $key => $value) {
$metaKey=$value['meta_key'];
$fieldTypeArray=array_flip($this->metaData);
if (array_key_exists($metaKey, $fieldTypeArray)) {
$getFieldType=$fieldTypeArray[$metaKey];
$fieldType=$this->fieldType[$getFieldType];
$metaId=$value[$this->meta_id];
if ($fieldType == 'post') {
$this->checkFieldType($metaId,$fieldType,$metaKey);
}else{
$this->deleteMetaKeys($metaId,$this->postType);
}
}
}
}
}
function checkFieldType($postId,$fieldType,$metaKey){
global $wpdb;
if ($fieldType == 'post') {
$metaKeyIds=$this->getMetaKeyId($postId,$metaKey,$this->postType);
$metaId=$metaKeyIds[0][$this->meta_id];
$parent_id=$metaKeyIds[0]['meta_value'];
// include_once( 'wp-admin/includes/plugin.php' );
$plugins = get_plugins();
$plugin_version = $plugins['types/wpcf.php']['Version'];
if($plugin_version < '3.4.1'){
$par_con = $wpdb->get_results("SELECT group_id FROM ".$wpdb->prefix."toolset_connected_elements WHERE element_id = {$parent_id} ",ARRAY_A);
$parconid=$par_con[0]['group_id'];
$child_con = $wpdb->get_results("SELECT group_id FROM ".$wpdb->prefix."toolset_connected_elements WHERE element_id = {$postId} ",ARRAY_A);
$childconid = $child_con[0]['group_id'];
$result=$wpdb->get_results("SELECT id,relationship_id FROM ".$wpdb->prefix."toolset_associations WHERE child_id = {$childconid} and parent_id = {$parconid} ",ARRAY_A);
$id=$result[0]['id'];
$relationship_id=$result[0]['relationship_id'];
}
else{
$result=$wpdb->get_results("SELECT id,relationship_id FROM ".$wpdb->prefix."toolset_associations WHERE child_id = {$postId} and parent_id = {$parent_id} ",ARRAY_A);
$id=$result[0]['id'];
$relationship_id=$result[0]['relationship_id'];
}
$wpdb->delete( $wpdb->prefix.'toolset_associations', array( 'id' => $id));
$this->deleteMetaKeys($metaId,$this->postType);
}
}
}