Plugin Directory

Changeset 3200916


Ignore:
Timestamp:
12/02/2024 01:08:36 PM (15 months ago)
Author:
matthewrubin
Message:

admin setting update

Location:
local-magic
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • local-magic/tags/2.5.0/activate.php

    r3200897 r3200916  
    361361    }
    362362}
     363
     364
     365
     366// OK
     367function create_lm_page_new($lm_setting, $lm_city, $lm_page_url, $lm_post_ID = NULL){
     368   
     369    global $wpdb;
     370       
     371       // now we will create page for each city 
     372        $lm_parent_post_id = url_to_postid($lm_page_url);
     373       
     374        $lm_post_id = $lm_post_ID > 0 ? $lm_post_ID : url_to_postid($lm_page_url.$lm_city->lm_url_slug);
     375
     376        if($lm_city->lm_parent_id > 0){               
     377            $lm_sql = "SELECT * FROM {$wpdb->prefix}mrylm_cities  WHERE lm_city_id = '$lm_city->lm_parent_id'";
     378            $lm_city_2 = $wpdb->get_row($lm_sql);
     379            $lm_parent_post_id = url_to_postid($lm_page_url.$lm_city_2->lm_url_slug);
     380        }
     381
     382        // If there are no sub page then we hv to parent post id 0
     383        if ($lm_setting->lm_page_type == 'base_page') {
     384            $lm_parent_post_id = 0;
     385        }
     386 
     387        $mrylm_post = array(
     388          'ID'=>  $lm_post_id,
     389          'post_title'    => $lm_city->lm_city,
     390          'post_name'    => $lm_city->lm_slug,
     391          'post_content'  => '',
     392          'post_status'   => 'publish',
     393          'post_type'   => 'page',
     394          'post_parent'   => $lm_parent_post_id,
     395          'post_author'   => 1, 
     396          'post_category' => array()
     397        );
     398       
     399
     400        //Insert the post into the database           
     401        $lm_insert_id =  $lm_post_id > 0 ? wp_update_post($mrylm_post) : wp_insert_post( $mrylm_post );
     402
     403        // to set template for the page
     404        if ( ! add_post_meta( $lm_insert_id, '_wp_page_template', 'local-magic.php', true )) {
     405            update_post_meta( $lm_insert_id, '_wp_page_template', 'local-magic.php' );
     406        }
     407       
     408        return $lm_insert_id;
     409}
     410
     411// OK
     412function create_lm_topic_pages_new($lm_parent_post_id, $lm_setting, $lm_city_obj){
     413     
     414   
     415    if($lm_setting->lm_is_topic && $lm_city_obj->lm_topics != ''){
     416         
     417        $topic_arr = explode('=',$lm_city_obj->lm_topics);
     418               
     419        if(is_array($topic_arr)){
     420            foreach($topic_arr AS $topic){
     421               
     422                $data_arr = explode('|', $topic);
     423                if(is_array($data_arr)){
     424                   
     425                    // $lm_setting->lm_page_url  == same as org_url + url type
     426                     $lm_post_id = url_to_postid($lm_setting->lm_page_url.$lm_city_obj->lm_url_slug.'/'.$data_arr[0]);
     427                                         
     428                    $mrylm_post = array(
     429                        'ID'=>  $lm_post_id,
     430                        'post_title'    => $data_arr[1],
     431                        'post_name'    => $data_arr[0],
     432                        'post_content'  => '',
     433                        'post_status'   => 'publish',
     434                        'post_type'   => 'page',
     435                        'post_parent'   => $lm_parent_post_id,
     436                        'post_author'   => 1,
     437                        'post_category' => array()
     438                      );   
     439
     440                   // $lm_insert_id = wp_insert_post( $mrylm_post );
     441                    $lm_insert_id =  $lm_post_id > 0 ? wp_update_post($mrylm_post) : wp_insert_post( $mrylm_post );
     442                    // to set template for the page
     443                    if ( ! add_post_meta( $lm_insert_id, '_wp_page_template', 'local-magic.php', true )) {
     444                        update_post_meta( $lm_insert_id, '_wp_page_template', 'local-magic.php' );
     445                    }               
     446                }               
     447            }
     448        }
     449    }   
     450}
     451
  • local-magic/tags/2.5.0/admin/setting.php

    r3200723 r3200916  
    88$mrylm_msg = "";
    99
     10
     11function get_multi_type_formatted_data($multi_type_data = null){
     12   
     13    $array_data = array();
     14    $text_data = json_decode($multi_type_data, true);
     15    $array = explode('|', $text_data);
     16    foreach($array as $value){
     17
     18        $arr = explode('=>', $value);
     19        $array_data[$arr[0]] = $arr[1];
     20    }
     21   
     22    return $array_data;
     23}
     24
    1025function mrylm_check_key_format($mrylm_key){
    1126   
     
    2136}
    2237
    23 function get_multi_type_formatted_data($multi_type_data = null){
    24    
    25     $array_data = array();
    26     $text_data = json_decode($multi_type_data, true);
    27     $array = explode('|', $text_data);
    28     foreach($array as $value){
    29 
    30         $arr = explode('=>', $value);
    31         $array_data[$arr[0]] = $arr[1];
    32     }
    33    
    34     return $array_data;
    35 }
    36 
    37 function create_lm_pages($lm_setting, $lm_city, $lm_page_url){
    38    
    39     global $wpdb;
    40    
    41        // now we will create page for each city
    42         $lm_parent_post_id = url_to_postid($lm_page_url); 
    43         $lm_post_id = url_to_postid($lm_page_url.$lm_city->lm_url_slug);
    44 
    45         if($lm_city->lm_parent_id > 0){               
    46             $lm_sql = "SELECT * FROM {$wpdb->prefix}mrylm_cities  WHERE lm_city_id = '$lm_city->lm_parent_id'";
    47             $lm_city_2 = $wpdb->get_row($lm_sql);
    48             $lm_parent_post_id = url_to_postid($lm_page_url.$lm_city_2->lm_url_slug);
    49         }   
    50 
    51         // If there are no sub page then we hv to parent post id 0
    52         if ($lm_setting->lm_page_type == 'base_page') {
    53             $lm_parent_post_id = 0;
    54         }
    55 
    56         $mrylm_post = array(
    57           'ID'=>  $lm_post_id,
    58           'post_title'    => $lm_city->lm_city,
    59           'post_content'  => '',
    60           'post_status'   => 'publish',
    61           'post_type'   => 'page',
    62           'post_parent'   => $lm_parent_post_id,
    63           'post_category' => array()
    64         );
    65 
    66         //Insert the post into the database           
    67         $lm_insert_id = wp_insert_post( $mrylm_post );
    68 
    69         // to set template for the page
    70         if ( ! add_post_meta( $lm_insert_id, '_wp_page_template', 'local-magic.php', true )) {
    71             update_post_meta( $lm_insert_id, '_wp_page_template', 'local-magic.php' );
    72         }
    73 }
    74 
    75 
    7638function mrylm_process_pages(){
    7739   
     
    8345    if($lm_setting->lm_url_type == 'wp_remote_get'){       
    8446        $mrylm_response   = wp_remote_get('https://localmagic.reviewmanager.app/plugin/cities/' . $lm_setting->lm_unique_id);
    85         $mrylm_cities  = json_decode($mrylm_response['body']);
    86        
     47        $mrylm_cities  = json_decode($mrylm_response['body']);       
    8748    }else{                 
    8849        $mrylm_response = file_get_contents('https://localmagic.reviewmanager.app/plugin/cities/' . $lm_setting->lm_unique_id);
     
    9051    }
    9152     
    92        if(!empty($mrylm_cities)){           
     53    if(!empty($mrylm_cities)){           
    9354         
    9455         // Trancating existing Cities table
     
    12586                'lm_historic_landmark' => $obj->historic_landmark,
    12687                'lm_assisted_living' => $obj->assisted_living,
    127                 'lm_restaurant' => $obj->restaurant
     88                'lm_restaurant' => $obj->restaurant,
     89                'lm_topics' => $obj->topics,
     90                'lm_type' => $obj->lm_type,
     91                'lm_is_default' => $obj->is_default,
     92                'lm_other_info' => $obj->other_info,   
     93                'lm_neighbour_id' => $obj->neighbour_id
    12894            );
    12995
     
    13399            $lm_city = array();
    134100            $lm_city['lm_parent_id'] = $obj->parent_id;
     101            $lm_city['lm_type'] = $obj->lm_type;
     102            $lm_city['lm_slug'] = $obj->slug;
    135103            $lm_city['lm_url_slug'] = $obj->url_slug;
    136104            $lm_city['lm_city'] = $obj->city;
     105            $lm_city['lm_topics'] = $obj->topics;
    137106            $lm_obj_city = (object) $lm_city;
    138107           
    139108            // need to process multi type
    140              if($lm_setting->lm_is_multi_type && $lm_setting->lm_multi_title != ''){
     109             if($lm_setting->lm_is_multi_type && $lm_setting->lm_multi_title != '' && $lm_setting->lm_types == 'multi-type'){
    141110
    142111                $lm_multi_titles = get_multi_type_formatted_data($lm_setting->lm_multi_title);
     
    144113
    145114                    $lm_page_url = $lm_setting->lm_org_url.$key.'/';
    146                     create_lm_pages($lm_setting, $lm_obj_city, $lm_page_url);   
     115                    $insert_id = create_lm_page_new($lm_setting, $lm_obj_city, $lm_page_url);
     116                    $lm_setting->lm_page_url = $lm_page_url;
     117                    create_lm_topic_pages_new($insert_id, $lm_setting, $lm_obj_city);
    147118                }
    148119
    149             }else{
    150                 create_lm_pages($lm_setting, $lm_obj_city, $lm_setting->lm_page_url);
     120            }else if($lm_setting->lm_types == 'type-wise'){
     121               
     122                if($lm_obj_city->lm_type){
     123                    $lm_page_url = $lm_setting->lm_org_url.$lm_obj_city->lm_type.'/';
     124                    $insert_id =  create_lm_page_new($lm_setting, $lm_obj_city, $lm_page_url);
     125                    $lm_setting->lm_page_url = $lm_page_url;
     126                    create_lm_topic_pages_new($insert_id, $lm_setting, $lm_obj_city);
     127                }
     128               
     129            }else{ // single type city
     130               
     131                $insert_id =  create_lm_page_new($lm_setting, $lm_obj_city, $lm_setting->lm_page_url);
     132                create_lm_topic_pages_new($insert_id, $lm_setting, $lm_obj_city);             
    151133            }           
    152134        }
     
    158140    }   
    159141}
    160 
    161142
    162143if (isset($_POST['submit']) && is_user_logged_in()) {
     
    245226                    'lm_multi_keyword' => $lm_setting->multi_keyword,
    246227                    'lm_multi_head' => $lm_setting->multi_head,
    247                     'lm_multi_near_me' => $lm_setting->multi_near_me
     228                    'lm_multi_near_me' => $lm_setting->multi_near_me,
     229                    'lm_is_topic' => $lm_setting->is_topic,
     230                    'lm_types' => $lm_setting->lm_types
    248231                );
    249232
  • local-magic/trunk/activate.php

    r3200897 r3200916  
    361361    }
    362362}
     363
     364
     365
     366// OK
     367function create_lm_page_new($lm_setting, $lm_city, $lm_page_url, $lm_post_ID = NULL){
     368   
     369    global $wpdb;
     370       
     371       // now we will create page for each city 
     372        $lm_parent_post_id = url_to_postid($lm_page_url);
     373       
     374        $lm_post_id = $lm_post_ID > 0 ? $lm_post_ID : url_to_postid($lm_page_url.$lm_city->lm_url_slug);
     375
     376        if($lm_city->lm_parent_id > 0){               
     377            $lm_sql = "SELECT * FROM {$wpdb->prefix}mrylm_cities  WHERE lm_city_id = '$lm_city->lm_parent_id'";
     378            $lm_city_2 = $wpdb->get_row($lm_sql);
     379            $lm_parent_post_id = url_to_postid($lm_page_url.$lm_city_2->lm_url_slug);
     380        }
     381
     382        // If there are no sub page then we hv to parent post id 0
     383        if ($lm_setting->lm_page_type == 'base_page') {
     384            $lm_parent_post_id = 0;
     385        }
     386 
     387        $mrylm_post = array(
     388          'ID'=>  $lm_post_id,
     389          'post_title'    => $lm_city->lm_city,
     390          'post_name'    => $lm_city->lm_slug,
     391          'post_content'  => '',
     392          'post_status'   => 'publish',
     393          'post_type'   => 'page',
     394          'post_parent'   => $lm_parent_post_id,
     395          'post_author'   => 1, 
     396          'post_category' => array()
     397        );
     398       
     399
     400        //Insert the post into the database           
     401        $lm_insert_id =  $lm_post_id > 0 ? wp_update_post($mrylm_post) : wp_insert_post( $mrylm_post );
     402
     403        // to set template for the page
     404        if ( ! add_post_meta( $lm_insert_id, '_wp_page_template', 'local-magic.php', true )) {
     405            update_post_meta( $lm_insert_id, '_wp_page_template', 'local-magic.php' );
     406        }
     407       
     408        return $lm_insert_id;
     409}
     410
     411// OK
     412function create_lm_topic_pages_new($lm_parent_post_id, $lm_setting, $lm_city_obj){
     413     
     414   
     415    if($lm_setting->lm_is_topic && $lm_city_obj->lm_topics != ''){
     416         
     417        $topic_arr = explode('=',$lm_city_obj->lm_topics);
     418               
     419        if(is_array($topic_arr)){
     420            foreach($topic_arr AS $topic){
     421               
     422                $data_arr = explode('|', $topic);
     423                if(is_array($data_arr)){
     424                   
     425                    // $lm_setting->lm_page_url  == same as org_url + url type
     426                     $lm_post_id = url_to_postid($lm_setting->lm_page_url.$lm_city_obj->lm_url_slug.'/'.$data_arr[0]);
     427                                         
     428                    $mrylm_post = array(
     429                        'ID'=>  $lm_post_id,
     430                        'post_title'    => $data_arr[1],
     431                        'post_name'    => $data_arr[0],
     432                        'post_content'  => '',
     433                        'post_status'   => 'publish',
     434                        'post_type'   => 'page',
     435                        'post_parent'   => $lm_parent_post_id,
     436                        'post_author'   => 1,
     437                        'post_category' => array()
     438                      );   
     439
     440                   // $lm_insert_id = wp_insert_post( $mrylm_post );
     441                    $lm_insert_id =  $lm_post_id > 0 ? wp_update_post($mrylm_post) : wp_insert_post( $mrylm_post );
     442                    // to set template for the page
     443                    if ( ! add_post_meta( $lm_insert_id, '_wp_page_template', 'local-magic.php', true )) {
     444                        update_post_meta( $lm_insert_id, '_wp_page_template', 'local-magic.php' );
     445                    }               
     446                }               
     447            }
     448        }
     449    }   
     450}
     451
  • local-magic/trunk/admin/setting.php

    r3200723 r3200916  
    88$mrylm_msg = "";
    99
     10
     11function get_multi_type_formatted_data($multi_type_data = null){
     12   
     13    $array_data = array();
     14    $text_data = json_decode($multi_type_data, true);
     15    $array = explode('|', $text_data);
     16    foreach($array as $value){
     17
     18        $arr = explode('=>', $value);
     19        $array_data[$arr[0]] = $arr[1];
     20    }
     21   
     22    return $array_data;
     23}
     24
    1025function mrylm_check_key_format($mrylm_key){
    1126   
     
    2136}
    2237
    23 function get_multi_type_formatted_data($multi_type_data = null){
    24    
    25     $array_data = array();
    26     $text_data = json_decode($multi_type_data, true);
    27     $array = explode('|', $text_data);
    28     foreach($array as $value){
    29 
    30         $arr = explode('=>', $value);
    31         $array_data[$arr[0]] = $arr[1];
    32     }
    33    
    34     return $array_data;
    35 }
    36 
    37 function create_lm_pages($lm_setting, $lm_city, $lm_page_url){
    38    
    39     global $wpdb;
    40    
    41        // now we will create page for each city
    42         $lm_parent_post_id = url_to_postid($lm_page_url); 
    43         $lm_post_id = url_to_postid($lm_page_url.$lm_city->lm_url_slug);
    44 
    45         if($lm_city->lm_parent_id > 0){               
    46             $lm_sql = "SELECT * FROM {$wpdb->prefix}mrylm_cities  WHERE lm_city_id = '$lm_city->lm_parent_id'";
    47             $lm_city_2 = $wpdb->get_row($lm_sql);
    48             $lm_parent_post_id = url_to_postid($lm_page_url.$lm_city_2->lm_url_slug);
    49         }   
    50 
    51         // If there are no sub page then we hv to parent post id 0
    52         if ($lm_setting->lm_page_type == 'base_page') {
    53             $lm_parent_post_id = 0;
    54         }
    55 
    56         $mrylm_post = array(
    57           'ID'=>  $lm_post_id,
    58           'post_title'    => $lm_city->lm_city,
    59           'post_content'  => '',
    60           'post_status'   => 'publish',
    61           'post_type'   => 'page',
    62           'post_parent'   => $lm_parent_post_id,
    63           'post_category' => array()
    64         );
    65 
    66         //Insert the post into the database           
    67         $lm_insert_id = wp_insert_post( $mrylm_post );
    68 
    69         // to set template for the page
    70         if ( ! add_post_meta( $lm_insert_id, '_wp_page_template', 'local-magic.php', true )) {
    71             update_post_meta( $lm_insert_id, '_wp_page_template', 'local-magic.php' );
    72         }
    73 }
    74 
    75 
    7638function mrylm_process_pages(){
    7739   
     
    8345    if($lm_setting->lm_url_type == 'wp_remote_get'){       
    8446        $mrylm_response   = wp_remote_get('https://localmagic.reviewmanager.app/plugin/cities/' . $lm_setting->lm_unique_id);
    85         $mrylm_cities  = json_decode($mrylm_response['body']);
    86        
     47        $mrylm_cities  = json_decode($mrylm_response['body']);       
    8748    }else{                 
    8849        $mrylm_response = file_get_contents('https://localmagic.reviewmanager.app/plugin/cities/' . $lm_setting->lm_unique_id);
     
    9051    }
    9152     
    92        if(!empty($mrylm_cities)){           
     53    if(!empty($mrylm_cities)){           
    9354         
    9455         // Trancating existing Cities table
     
    12586                'lm_historic_landmark' => $obj->historic_landmark,
    12687                'lm_assisted_living' => $obj->assisted_living,
    127                 'lm_restaurant' => $obj->restaurant
     88                'lm_restaurant' => $obj->restaurant,
     89                'lm_topics' => $obj->topics,
     90                'lm_type' => $obj->lm_type,
     91                'lm_is_default' => $obj->is_default,
     92                'lm_other_info' => $obj->other_info,   
     93                'lm_neighbour_id' => $obj->neighbour_id
    12894            );
    12995
     
    13399            $lm_city = array();
    134100            $lm_city['lm_parent_id'] = $obj->parent_id;
     101            $lm_city['lm_type'] = $obj->lm_type;
     102            $lm_city['lm_slug'] = $obj->slug;
    135103            $lm_city['lm_url_slug'] = $obj->url_slug;
    136104            $lm_city['lm_city'] = $obj->city;
     105            $lm_city['lm_topics'] = $obj->topics;
    137106            $lm_obj_city = (object) $lm_city;
    138107           
    139108            // need to process multi type
    140              if($lm_setting->lm_is_multi_type && $lm_setting->lm_multi_title != ''){
     109             if($lm_setting->lm_is_multi_type && $lm_setting->lm_multi_title != '' && $lm_setting->lm_types == 'multi-type'){
    141110
    142111                $lm_multi_titles = get_multi_type_formatted_data($lm_setting->lm_multi_title);
     
    144113
    145114                    $lm_page_url = $lm_setting->lm_org_url.$key.'/';
    146                     create_lm_pages($lm_setting, $lm_obj_city, $lm_page_url);   
     115                    $insert_id = create_lm_page_new($lm_setting, $lm_obj_city, $lm_page_url);
     116                    $lm_setting->lm_page_url = $lm_page_url;
     117                    create_lm_topic_pages_new($insert_id, $lm_setting, $lm_obj_city);
    147118                }
    148119
    149             }else{
    150                 create_lm_pages($lm_setting, $lm_obj_city, $lm_setting->lm_page_url);
     120            }else if($lm_setting->lm_types == 'type-wise'){
     121               
     122                if($lm_obj_city->lm_type){
     123                    $lm_page_url = $lm_setting->lm_org_url.$lm_obj_city->lm_type.'/';
     124                    $insert_id =  create_lm_page_new($lm_setting, $lm_obj_city, $lm_page_url);
     125                    $lm_setting->lm_page_url = $lm_page_url;
     126                    create_lm_topic_pages_new($insert_id, $lm_setting, $lm_obj_city);
     127                }
     128               
     129            }else{ // single type city
     130               
     131                $insert_id =  create_lm_page_new($lm_setting, $lm_obj_city, $lm_setting->lm_page_url);
     132                create_lm_topic_pages_new($insert_id, $lm_setting, $lm_obj_city);             
    151133            }           
    152134        }
     
    158140    }   
    159141}
    160 
    161142
    162143if (isset($_POST['submit']) && is_user_logged_in()) {
     
    245226                    'lm_multi_keyword' => $lm_setting->multi_keyword,
    246227                    'lm_multi_head' => $lm_setting->multi_head,
    247                     'lm_multi_near_me' => $lm_setting->multi_near_me
     228                    'lm_multi_near_me' => $lm_setting->multi_near_me,
     229                    'lm_is_topic' => $lm_setting->is_topic,
     230                    'lm_types' => $lm_setting->lm_types
    248231                );
    249232
Note: See TracChangeset for help on using the changeset viewer.