Make WordPress Core


Ignore:
Timestamp:
05/12/2004 07:42:42 AM (21 years ago)
Author:
saxmatt
Message:

New RSS import functionality.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/import-rss.php

    r1134 r1264  
    99$timezone_offset = 0; // GMT offset of posts your importing
    1010
     11function unhtmlentities($string) { // From php.net for < 4.3 compat
     12   $trans_tbl = get_html_translation_table(HTML_ENTITIES);
     13   $trans_tbl = array_flip($trans_tbl);
     14   return strtr($string, $trans_tbl);
     15}
    1116
    1217$add_hours = intval($timezone_offset);
     
    5863<p>You want to define where the RSS file we'll be working with is, for example: </p>
    5964<p><code>define('RSSFILE', 'rss.xml');</code></p>
    60 <p>You have to do this manually for security reasons.</p>
    61 <p>If you've done that and you&#8217;re all ready, <a href="import-rss.php?step=1">let's go</a>!</p>
     65<p>You have to do this manually for security reasons. When you're done reload this page and we'll take you to the next step.</p>
     66<?php if ('' != RSSFILE) : ?>
     67<h2 style="text-align: right;"><a href="import-rss.php?step=1">Begin RSS Import &raquo;</a></h2>
     68<?php endif; ?>
    6269<?php
    6370    break;
    64    
     71
    6572    case 1:
    66 if ('' != RSSFILE && !file_exists(RSSFILE)) die("The file you specified does not seem to exist. Please check the path you've given.");
    67 if ('' == RSSFILE) die("You must edit the RSSFILE line as described on the <a href='import-rss.php'>previous page</a> to continue.");
    6873
    6974// Bring in the data
     
    9499endif;
    95100
    96 $post_date = date('Y-m-d H:i:s', $date);
     101$post_date = gmdate('Y-m-d H:i:s', $date);
    97102
    98103preg_match_all('|<category>(.*?)</category>|is', $post, $categories);
     
    109114if (!$content) : // This is for feeds that put content in description
    110115    preg_match('|<description>(.*?)</description>|is', $post, $content);
    111     $content = addslashes( trim($content[1]) );
     116    $content = $wpdb->escape( unhtmlentities( trim($content[1]) ) );
     117endif;
     118
     119// Clean up content
     120$content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $content);
     121$content = str_replace('<br>', '<br />', $content);
     122$content = str_replace('<hr>', '<hr />', $content);
     123
     124// This can mess up on posts with no titles, but checking content is much slower
     125// So we do it as a last resort
     126if ('' == $title) :
     127    $dupe = $wpdb->get_var("SELECT ID FROM $tableposts WHERE post_content = '$content' AND post_date = '$post_date'");
     128else :
     129    $dupe = $wpdb->get_var("SELECT ID FROM $tableposts WHERE post_title = '$title' AND post_date = '$post_date'");
    112130endif;
    113131
    114132// Now lets put it in the DB
    115 if ($wpdb->get_var("SELECT ID FROM $tableposts WHERE post_title = '$title' AND post_date = '$post_date'")) :
     133if ($dupe) :
    116134    echo 'Post already imported';
    117135else :
     
    125143    if (0 != count($categories)) :
    126144        foreach ($categories as $post_category) :
     145        $post_category = unhtmlentities($post_category);
    127146        // See if the category exists yet
    128147        $cat_id = $wpdb->get_var("SELECT cat_ID from $tablecategories WHERE cat_name = '$post_category'");
Note: See TracChangeset for help on using the changeset viewer.