[ Index ]

PHP Cross Reference of Wordpress 2.7.1

title

Body

[close]

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

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


Generated: Mon Mar 23 16:23:02 2009 Cross-referenced by PHPXref 0.7