home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Blogs / wordpress2.6.exe / wordpress2.6 / wp-admin / link-import.php < prev    next >
Encoding:
PHP Script  |  2008-05-04  |  3.9 KB  |  136 lines

  1. <?php
  2. // Links
  3. // Copyright (C) 2002 Mike Little -- mike@zed1.com
  4.  
  5. require_once('admin.php');
  6. $parent_file = 'edit.php';
  7. $title = __('Import Blogroll');
  8.  
  9. $step = $_POST['step'];
  10. if (!$step) $step = 0;
  11. ?>
  12. <?php
  13. switch ($step) {
  14.     case 0: {
  15.         include_once('admin-header.php');
  16.         if ( !current_user_can('manage_links') )
  17.             wp_die(__('Cheatin’ uh?'));
  18.  
  19.         $opmltype = 'blogrolling'; // default.
  20. ?>
  21.  
  22. <div class="wrap">
  23.  
  24. <h2><?php _e('Import your blogroll from another system') ?> </h2>
  25. <form enctype="multipart/form-data" action="link-import.php" method="post" name="blogroll">
  26. <?php wp_nonce_field('import-bookmarks') ?>
  27.  
  28. <p><?php _e('If a program or website you use allows you to export your links or subscriptions as OPML you may import them here.'); ?></p>
  29. <div style="width: 70%; margin: auto; height: 8em;">
  30. <input type="hidden" name="step" value="1" />
  31. <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
  32. <div style="width: 48%;" class="alignleft">
  33. <h3><label for="opml_url"><?php _e('Specify an OPML URL:'); ?></label></h3>
  34. <input type="text" name="opml_url" id="opml_url" size="50" style="width: 90%;" value="http://" />
  35. </div>
  36.  
  37. <div style="width: 48%;" class="alignleft">
  38. <h3><label for="userfile"><?php _e('Or choose from your local disk:'); ?></label></h3>
  39. <input id="userfile" name="userfile" type="file" size="30" />
  40. </div>
  41.  
  42. </div>
  43.  
  44. <p style="clear: both; margin-top: 1em;"><label for="cat_id"><?php _e('Now select a category you want to put these links in.') ?></label><br />
  45. <?php _e('Category:') ?> <select name="cat_id" id="cat_id">
  46. <?php
  47. $categories = get_terms('link_category', 'get=all');
  48. foreach ($categories as $category) {
  49. ?>
  50. <option value="<?php echo $category->term_id; ?>"><?php echo wp_specialchars(apply_filters('link_category', $category->name)); ?></option>
  51. <?php
  52. } // end foreach
  53. ?>
  54. </select></p>
  55.  
  56. <p class="submit"><input type="submit" name="submit" value="<?php _e('Import OPML File') ?>" /></p>
  57. </form>
  58.  
  59. </div>
  60. <?php
  61.         break;
  62.     } // end case 0
  63.  
  64.     case 1: {
  65.         check_admin_referer('import-bookmarks');
  66.  
  67.         include_once('admin-header.php');
  68.         if ( !current_user_can('manage_links') )
  69.             wp_die(__('Cheatin’ uh?'));
  70. ?>
  71. <div class="wrap">
  72.  
  73. <h2><?php _e('Importing...') ?></h2>
  74. <?php
  75.         $cat_id = abs( (int) $_POST['cat_id'] );
  76.         if ( $cat_id < 1 )
  77.             $cat_id  = 1;
  78.  
  79.         $opml_url = $_POST['opml_url'];
  80.         if ( isset($opml_url) && $opml_url != '' && $opml_url != 'http://' ) {
  81.             $blogrolling = true;
  82.         } else { // try to get the upload file.
  83.             $overrides = array('test_form' => false, 'test_type' => false);
  84.             $file = wp_handle_upload($_FILES['userfile'], $overrides);
  85.  
  86.             if ( isset($file['error']) )
  87.                 wp_die($file['error']);
  88.  
  89.             $url = $file['url'];
  90.             $opml_url = $file['file'];
  91.             $blogrolling = false;
  92.         }
  93.  
  94.         if ( isset($opml_url) && $opml_url != '' ) {
  95.             if ( $blogrolling === true ) {
  96.                 $opml = wp_remote_fopen($opml_url);
  97.             } else {
  98.                 $opml = file_get_contents($opml_url);
  99.             }
  100.  
  101.             include_once('link-parse-opml.php');
  102.  
  103.             $link_count = count($names);
  104.             for ( $i = 0; $i < $link_count; $i++ ) {
  105.                 if ('Last' == substr($titles[$i], 0, 4))
  106.                     $titles[$i] = '';
  107.                 if ( 'http' == substr($titles[$i], 0, 4) )
  108.                     $titles[$i] = '';
  109.                 $link = array( 'link_url' => $urls[$i], 'link_name' => $wpdb->escape($names[$i]), 'link_category' => array($cat_id), 'link_description' => $wpdb->escape($descriptions[$i]), 'link_owner' => $user_ID, 'link_rss' => $feeds[$i]);
  110.                 wp_insert_link($link);
  111.                 echo sprintf('<p>'.__('Inserted <strong>%s</strong>').'</p>', $names[$i]);
  112.             }
  113. ?>
  114.  
  115. <p><?php printf(__('Inserted %1$d links into category %2$s. All done! Go <a href="%3$s">manage those links</a>.'), $link_count, $cat_id, 'link-manager.php') ?></p>
  116.  
  117. <?php
  118. } // end if got url
  119. else
  120. {
  121.     echo "<p>" . __("You need to supply your OPML url. Press back on your browser and try again") . "</p>\n";
  122. } // end else
  123.  
  124. if ( ! $blogrolling )
  125.     do_action( 'wp_delete_file', $opml_url);
  126.     @unlink($opml_url);
  127. ?>
  128. </div>
  129. <?php
  130.         break;
  131.     } // end case 1
  132. } // end switch
  133.  
  134. include('admin-footer.php');
  135.  
  136. ?>