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,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);
}
}
}