Ticket #1944: textpattern.php.2.diff
| File textpattern.php.2.diff, 8.3 KB (added by technosailor, 6 years ago) |
|---|
-
textpattern.php
2 2 /** 3 3 Add These Functions to make our lives easier 4 4 **/ 5 if(!function_exists('get_cat _nicename'))5 if(!function_exists('get_catbynicename')) 6 6 { 7 7 function get_catbynicename($category_nicename) 8 8 { … … 60 60 _e('</form>'); 61 61 } 62 62 63 function get_txp_links()64 {65 //General Housekeeping66 $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('SELECT71 id,72 date,73 category,74 url,75 linkname,76 description77 FROM '.$prefix.'txp_link',78 ARRAY_A);79 }80 81 63 function get_txp_cats() 82 64 { 83 65 global $wpdb; … … 153 135 return $txpdb->get_results('SELECT * FROM '.$prefix.'txp_discuss', ARRAY_A); 154 136 } 155 137 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 } 156 155 157 function links2wp($links='')156 function cat2wp($categories='') 158 157 { 159 158 // General Housekeeping 160 159 global $wpdb; 161 160 $count = 0; 162 163 // D eal with the links164 if(is_array($ links))161 $txpcat2wpcat = array(); 162 // Do the Magic 163 if(is_array($categories)) 165 164 { 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) 168 167 { 169 168 $count++; 170 extract($ link);169 extract($category); 171 170 172 // Make nice vars173 $category = $wpdb->escape($category);174 $linkname = $wpdb->escape($linkname);175 $description = $wpdb->escape($description);176 171 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)) 178 177 { 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)); 187 179 } 188 else 180 else 189 181 { 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)); 197 183 } 198 $txp links2wplinks[$link_id] = $ret_id;184 $txpcat2wpcat[$id] = $ret_id; 199 185 } 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>'); 202 190 return true; 203 191 } 204 echo __('No Links to Import!');192 echo __('No Categories to Import!'); 205 193 return false; 206 194 } 207 195 … … 279 267 280 268 }// End function user2wp() 281 269 282 function cat2wp($categories='')283 {284 // General Housekeeping285 global $wpdb;286 $count = 0;287 $txpcat2wpcat = array();288 // Do the Magic289 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 Variables299 $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 else307 {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 use314 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 323 270 function posts2wp($posts='') 324 271 { 325 272 // General Housekeeping … … 420 367 421 368 // WordPressify Data 422 369 $comment_ID = ltrim($discussid, '0'); 370 $comment_post_ID = $postarr[$parentid]; 423 371 $comment_approved = (1 == $visible) ? 1 : 0; 424 372 $name = $wpdb->escape($name); 425 373 $email = $wpdb->escape($email); … … 431 379 // Update comments 432 380 $ret_id = wp_update_comment(array( 433 381 'comment_ID' => $cinfo, 382 'comment_post_ID' => $comment_post_ID, 434 383 'comment_author' => $name, 435 384 'comment_author_email' => $email, 436 385 'comment_author_url' => $web, … … 443 392 { 444 393 // Insert comments 445 394 $ret_id = wp_insert_comment(array( 446 'comment_post_ID' => $ postarr[$parentid],395 'comment_post_ID' => $comment_post_ID, 447 396 'comment_author' => $name, 448 397 'comment_author_email' => $email, 449 398 'comment_author_url' => $web, … … 468 417 echo __('No Comments to Import!'); 469 418 return false; 470 419 } 420 421 function links2wp($links='') 422 { 423 // General Housekeeping 424 global $wpdb; 425 $count = 0; 471 426 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 472 472 function import_categories() 473 473 { 474 474 // Category Import … … 584 584 $step = (int) $_GET['step']; 585 585 $this->header(); 586 586 587 if ( $step == 1)587 if ( $step > 0 ) 588 588 { 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 } 594 620 621 595 622 } 596 623 597 624 switch ($step)
