[ Root ] [ Search ] [ Index ]

PHP Cross Reference of WordPress Trunk

Provided by Yoast

title

Body

[close]

/wp-admin/import/ -> opml.php (source)

   1  <?php
   2  /**
   3   * Links Import Administration Panel.
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   */
   8  
   9  /** Load WordPress Administration Bootstrap */
  10  $parent_file = 'tools.php';
  11  $submenu_file = 'import.php';
  12  $title = __('Import Blogroll');
  13  
  14  class OPML_Import {
  15  
  16  	function dispatch() {
  17          global $wpdb, $user_ID;
  18  $step = isset( $_POST['step'] ) ? $_POST['step'] : 0;
  19  
  20  switch ($step) {
  21      case 0: {
  22          include_once ( ABSPATH . 'wp-admin/admin-header.php' );
  23          if ( !current_user_can('manage_links') )
  24              wp_die(__('Cheatin&#8217; uh?'));
  25  
  26          $opmltype = 'blogrolling'; // default.
  27  ?>
  28  
  29  <div class="wrap">
  30  <?php screen_icon(); ?>
  31  <h2><?php _e('Import your blogroll from another system') ?> </h2>
  32  <form enctype="multipart/form-data" action="admin.php?import=opml" method="post" name="blogroll">
  33  <?php wp_nonce_field('import-bookmarks') ?>
  34  
  35  <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>
  36  <div style="width: 70%; margin: auto; height: 8em;">
  37  <input type="hidden" name="step" value="1" />
  38  <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo wp_max_upload_size(); ?>" />
  39  <div style="width: 48%;" class="alignleft">
  40  <h3><label for="opml_url"><?php _e('Specify an OPML URL:'); ?></label></h3>
  41  <input type="text" name="opml_url" id="opml_url" size="50" class="code" style="width: 90%;" value="http://" />
  42  </div>
  43  
  44  <div style="width: 48%;" class="alignleft">
  45  <h3><label for="userfile"><?php _e('Or choose from your local disk:'); ?></label></h3>
  46  <input id="userfile" name="userfile" type="file" size="30" />
  47  </div>
  48  
  49  </div>
  50  
  51  <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 />
  52  <?php _e('Category:') ?> <select name="cat_id" id="cat_id">
  53  <?php
  54  $categories = get_terms('link_category', array('get' => 'all'));
  55  foreach ($categories as $category) {
  56  ?>
  57  <option value="<?php echo $category->term_id; ?>"><?php echo esc_html(apply_filters('link_category', $category->name)); ?></option>
  58  <?php
  59  } // end foreach
  60  ?>
  61  </select></p>
  62  
  63  <p class="submit"><input type="submit" name="submit" value="<?php esc_attr_e('Import OPML File') ?>" /></p>
  64  </form>
  65  
  66  </div>
  67  <?php
  68          break;
  69      } // end case 0
  70  
  71      case 1: {
  72          check_admin_referer('import-bookmarks');
  73  
  74          include_once ( ABSPATH . 'wp-admin/admin-header.php' );
  75          if ( !current_user_can('manage_links') )
  76              wp_die(__('Cheatin&#8217; uh?'));
  77  ?>
  78  <div class="wrap">
  79  
  80  <h2><?php _e('Importing...') ?></h2>
  81  <?php
  82          $cat_id = abs( (int) $_POST['cat_id'] );
  83          if ( $cat_id < 1 )
  84              $cat_id  = 1;
  85  
  86          $opml_url = $_POST['opml_url'];
  87          if ( isset($opml_url) && $opml_url != '' && $opml_url != 'http://' ) {
  88              $blogrolling = true;
  89          } else { // try to get the upload file.
  90              $overrides = array('test_form' => false, 'test_type' => false);
  91              $_FILES['userfile']['name'] .= '.txt';
  92              $file = wp_handle_upload($_FILES['userfile'], $overrides);
  93  
  94              if ( isset($file['error']) )
  95                  wp_die($file['error']);
  96  
  97              $url = $file['url'];
  98              $opml_url = $file['file'];
  99              $blogrolling = false;
 100          }
 101  
 102          global $opml, $updated_timestamp, $all_links, $map, $names, $urls, $targets, $descriptions, $feeds;
 103          if ( isset($opml_url) && $opml_url != '' ) {
 104              if ( $blogrolling === true ) {
 105                  $opml = wp_remote_fopen($opml_url);
 106              } else {
 107                  $opml = file_get_contents($opml_url);
 108              }
 109  
 110              /** Load OPML Parser */
 111              include_once ( ABSPATH . 'wp-admin/link-parse-opml.php' );
 112  
 113              $link_count = count($names);
 114              for ( $i = 0; $i < $link_count; $i++ ) {
 115                  if ('Last' == substr($titles[$i], 0, 4))
 116                      $titles[$i] = '';
 117                  if ( 'http' == substr($titles[$i], 0, 4) )
 118                      $titles[$i] = '';
 119                  $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]);
 120                  wp_insert_link($link);
 121                  echo sprintf('<p>'.__('Inserted <strong>%s</strong>').'</p>', $names[$i]);
 122              }
 123  ?>
 124  
 125  <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>
 126  
 127  <?php
 128  } // end if got url
 129  else
 130  {
 131      echo "<p>" . __("You need to supply your OPML url. Press back on your browser and try again") . "</p>\n";
 132  } // end else
 133  
 134  if ( ! $blogrolling )
 135      do_action( 'wp_delete_file', $opml_url);
 136      @unlink($opml_url);
 137  ?>
 138  </div>
 139  <?php
 140          break;
 141      } // end case 1
 142  } // end switch
 143      }
 144  
 145  	function OPML_Import() {}
 146  }
 147  
 148  $opml_importer = new OPML_Import();
 149  
 150  register_importer('opml', __('Blogroll'), __('Import links in OPML format.'), array(&$opml_importer, 'dispatch'));
 151  
 152  ?>


Generated: Thu May 20 22:30:08 2010 Cross-referenced by PHPXref 0.7