Ticket #1944: textpattern.php.2.diff

File textpattern.php.2.diff, 8.3 KB (added by technosailor, 6 years ago)

Fixes post/comment association and post counts. Reorganizes

  • textpattern.php

     
    22/** 
    33        Add These Functions to make our lives easier 
    44**/ 
    5 if(!function_exists('get_cat_nicename')) 
     5if(!function_exists('get_catbynicename')) 
    66{ 
    77        function get_catbynicename($category_nicename)  
    88        { 
     
    6060                _e('</form>'); 
    6161        } 
    6262 
    63         function get_txp_links() 
    64         { 
    65                 //General Housekeeping 
    66                 $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost')); 
    67                 set_magic_quotes_runtime(0); 
    68                 $prefix = get_option('tpre'); 
    69                  
    70                 return $txpdb->get_results('SELECT  
    71                                                                                 id, 
    72                                                                                 date, 
    73                                                                                 category, 
    74                                                                                 url, 
    75                                                                                 linkname, 
    76                                                                                 description 
    77                                                                           FROM '.$prefix.'txp_link',  
    78                                                                           ARRAY_A);                                                
    79         } 
    80          
    8163        function get_txp_cats()  
    8264        { 
    8365                global $wpdb; 
     
    153135                return $txpdb->get_results('SELECT * FROM '.$prefix.'txp_discuss', ARRAY_A); 
    154136        } 
    155137         
     138                function get_txp_links() 
     139        { 
     140                //General Housekeeping 
     141                $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost')); 
     142                set_magic_quotes_runtime(0); 
     143                $prefix = get_option('tpre'); 
     144                 
     145                return $txpdb->get_results('SELECT  
     146                                                                                id, 
     147                                                                                date, 
     148                                                                                category, 
     149                                                                                url, 
     150                                                                                linkname, 
     151                                                                                description 
     152                                                                          FROM '.$prefix.'txp_link',  
     153                                                                          ARRAY_A);                                                
     154        } 
    156155         
    157         function links2wp($links='') 
     156        function cat2wp($categories='')  
    158157        { 
    159158                // General Housekeeping 
    160159                global $wpdb; 
    161160                $count = 0; 
    162                  
    163                 // Deal with the links 
    164                 if(is_array($links)) 
     161                $txpcat2wpcat = array(); 
     162                // Do the Magic 
     163                if(is_array($categories)) 
    165164                { 
    166                         echo __('<p>Importing Links...<br /><br /></p>'); 
    167                         foreach($links as $link) 
     165                        echo __('<p>Importing Categories...<br /><br /></p>'); 
     166                        foreach ($categories as $category)  
    168167                        { 
    169168                                $count++; 
    170                                 extract($link); 
     169                                extract($category); 
    171170                                 
    172                                 // Make nice vars 
    173                                 $category = $wpdb->escape($category); 
    174                                 $linkname = $wpdb->escape($linkname); 
    175                                 $description = $wpdb->escape($description); 
    176171                                 
    177                                 if($linfo = link_exists($linkname)) 
     172                                // Make Nice Variables 
     173                                $name = $wpdb->escape($name); 
     174                                $title = $wpdb->escape($title); 
     175                                 
     176                                if($cinfo = category_exists($name)) 
    178177                                { 
    179                                         $ret_id = wp_insert_link(array( 
    180                                                                 'link_id'                       => $linfo, 
    181                                                                 'link_url'                      => $url, 
    182                                                                 'link_name'                     => $linkname, 
    183                                                                 'link_category'         => $category, 
    184                                                                 'link_description'      => $description, 
    185                                                                 'link_updated'          => $date) 
    186                                                                 ); 
     178                                        $ret_id = wp_insert_category(array('cat_ID' => $cinfo, 'category_nicename' => $name, 'cat_name' => $title)); 
    187179                                } 
    188                                 else  
     180                                else 
    189181                                { 
    190                                         $ret_id = wp_insert_link(array( 
    191                                                                 'link_url'                      => $url, 
    192                                                                 'link_name'                     => $linkname, 
    193                                                                 'link_category'         => $category, 
    194                                                                 'link_description'      => $description, 
    195                                                                 'link_updated'          => $date) 
    196                                                                 ); 
     182                                        $ret_id = wp_insert_category(array('category_nicename' => $name, 'cat_name' => $title)); 
    197183                                } 
    198                                 $txplinks2wplinks[$link_id] = $ret_id; 
     184                                $txpcat2wpcat[$id] = $ret_id; 
    199185                        } 
    200                         add_option('txplinks2wplinks',$txplinks2wplinks); 
    201                         echo __('<p>Done! <strong>'.$count.'</strong> Links imported.<br /><br /></p>'); 
     186                         
     187                        // Store category translation for future use 
     188                        add_option('txpcat2wpcat',$txpcat2wpcat); 
     189                        echo __('<p>Done! <strong>'.$count.'</strong> categories imported.<br /><br /></p>'); 
    202190                        return true; 
    203191                } 
    204                 echo __('No Links to Import!'); 
     192                echo __('No Categories to Import!'); 
    205193                return false; 
    206194        } 
    207195         
     
    279267                 
    280268        }// End function user2wp() 
    281269         
    282         function cat2wp($categories='')  
    283         { 
    284                 // General Housekeeping 
    285                 global $wpdb; 
    286                 $count = 0; 
    287                 $txpcat2wpcat = array(); 
    288                 // Do the Magic 
    289                 if(is_array($categories)) 
    290                 { 
    291                         echo __('<p>Importing Categories...<br /><br /></p>'); 
    292                         foreach ($categories as $category)  
    293                         { 
    294                                 $count++; 
    295                                 extract($category); 
    296                                  
    297                                  
    298                                 // Make Nice Variables 
    299                                 $name = $wpdb->escape($name); 
    300                                 $title = $wpdb->escape($title); 
    301                                  
    302                                 if($cinfo = category_exists($name)) 
    303                                 { 
    304                                         $ret_id = wp_insert_category(array('cat_ID' => $cinfo, 'category_nicename' => $name, 'cat_name' => $title)); 
    305                                 } 
    306                                 else 
    307                                 { 
    308                                         $ret_id = wp_insert_category(array('category_nicename' => $name, 'cat_name' => $title)); 
    309                                 } 
    310                                 $txpcat2wpcat[$id] = $ret_id; 
    311                         } 
    312                          
    313                         // Store category translation for future use 
    314                         add_option('txpcat2wpcat',$txpcat2wpcat); 
    315                         echo __('<p>Done! <strong>'.$count.'</strong> categories imported.<br /><br /></p>'); 
    316                         return true; 
    317                 } 
    318                 echo __('No Categories to Import!'); 
    319                 return false; 
    320                  
    321         } 
    322          
    323270        function posts2wp($posts='') 
    324271        { 
    325272                // General Housekeeping 
     
    420367                                 
    421368                                // WordPressify Data 
    422369                                $comment_ID = ltrim($discussid, '0'); 
     370                                $comment_post_ID = $postarr[$parentid]; 
    423371                                $comment_approved = (1 == $visible) ? 1 : 0; 
    424372                                $name = $wpdb->escape($name); 
    425373                                $email = $wpdb->escape($email); 
     
    431379                                        // Update comments 
    432380                                        $ret_id = wp_update_comment(array( 
    433381                                                        'comment_ID'                    => $cinfo, 
     382                                                        'comment_post_ID'               => $comment_post_ID, 
    434383                                                        'comment_author'                => $name, 
    435384                                                        'comment_author_email'  => $email, 
    436385                                                        'comment_author_url'    => $web, 
     
    443392                                { 
    444393                                        // Insert comments 
    445394                                        $ret_id = wp_insert_comment(array( 
    446                                                         'comment_post_ID'               => $postarr[$parentid], 
     395                                                        'comment_post_ID'               => $comment_post_ID, 
    447396                                                        'comment_author'                => $name, 
    448397                                                        'comment_author_email'  => $email, 
    449398                                                        'comment_author_url'    => $web, 
     
    468417                echo __('No Comments to Import!'); 
    469418                return false; 
    470419        } 
     420         
     421        function links2wp($links='') 
     422        { 
     423                // General Housekeeping 
     424                global $wpdb; 
     425                $count = 0; 
    471426                 
     427                // Deal with the links 
     428                if(is_array($links)) 
     429                { 
     430                        echo __('<p>Importing Links...<br /><br /></p>'); 
     431                        foreach($links as $link) 
     432                        { 
     433                                $count++; 
     434                                extract($link); 
     435                                 
     436                                // Make nice vars 
     437                                $category = $wpdb->escape($category); 
     438                                $linkname = $wpdb->escape($linkname); 
     439                                $description = $wpdb->escape($description); 
     440                                 
     441                                if($linfo = link_exists($linkname)) 
     442                                { 
     443                                        $ret_id = wp_insert_link(array( 
     444                                                                'link_id'                       => $linfo, 
     445                                                                'link_url'                      => $url, 
     446                                                                'link_name'                     => $linkname, 
     447                                                                'link_category'         => $category, 
     448                                                                'link_description'      => $description, 
     449                                                                'link_updated'          => $date) 
     450                                                                ); 
     451                                } 
     452                                else  
     453                                { 
     454                                        $ret_id = wp_insert_link(array( 
     455                                                                'link_url'                      => $url, 
     456                                                                'link_name'                     => $linkname, 
     457                                                                'link_category'         => $category, 
     458                                                                'link_description'      => $description, 
     459                                                                'link_updated'          => $date) 
     460                                                                ); 
     461                                } 
     462                                $txplinks2wplinks[$link_id] = $ret_id; 
     463                        } 
     464                        add_option('txplinks2wplinks',$txplinks2wplinks); 
     465                        echo __('<p>Done! <strong>'.$count.'</strong> Links imported.<br /><br /></p>'); 
     466                        return true; 
     467                } 
     468                echo __('No Links to Import!'); 
     469                return false; 
     470        } 
     471                 
    472472        function import_categories()  
    473473        {        
    474474                // Category Import       
     
    584584                        $step = (int) $_GET['step']; 
    585585                $this->header(); 
    586586                 
    587                 if ( $step == 1 )  
     587                if ( $step > 0 )  
    588588                { 
    589                         if(false !== get_option('txpuser')) {add_option('txpuser',$_POST['dbuser']); } 
    590                         if(false !== get_option('txppass')) {add_option('txppass',$_POST['dbpass']); } 
    591                         if(false !== get_option('txpname')) {add_option('txpname',$_POST['dbname']); } 
    592                         if(false !== get_option('txphost')) {add_option('txphost',$_POST['dbhost']); } 
    593                         if(false !== get_option('tpre')) { add_option('tpre', $tpre); } 
     589                        if($_POST['dbuser']) 
     590                        { 
     591                                if(get_option('txpuser')) 
     592                                        delete_option('txpuser');        
     593                                add_option('txpuser',$_POST['dbuser']); 
     594                        } 
     595                        if($_POST['dbpass']) 
     596                        { 
     597                                if(get_option('txppass')) 
     598                                        delete_option('txppass');        
     599                                add_option('txppass',$_POST['dbpass']); 
     600                        } 
     601                         
     602                        if($_POST['dbname']) 
     603                        { 
     604                                if(get_option('txpname')) 
     605                                        delete_option('txpname');        
     606                                add_option('txpname',$_POST['dbname']); 
     607                        } 
     608                        if($_POST['dbhost']) 
     609                        { 
     610                                if(get_option('txphost')) 
     611                                        delete_option('txphost'); 
     612                                add_option('txphost',$_POST['dbhost']);  
     613                        } 
     614                        if($_POST['dbprefix']) 
     615                        { 
     616                                if(get_option('tpre')) 
     617                                        delete_option('tpre'); 
     618                                add_option('tpre',$_POST['dbprefix']);  
     619                        }                        
    594620 
     621 
    595622                } 
    596623 
    597624                switch ($step)