Browse Source

Merge pull request #622 from medmen/RSS_import_pics

Rss import pics BY @medmen
pull/558/merge
Dan 2 years ago
committed by GitHub
parent
commit
39629232b2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 71 additions and 2 deletions
  1. +9
    -1
      composer.json
  2. +62
    -1
      system/admin/admin.php

+ 9
- 1
composer.json View File

@ -1,4 +1,11 @@
{ {
"repositories": [
{
"type": "vcs",
"url": "https://github.com/Youpie/simple-html-dom"
}
],
"config": { "config": {
"vendor-dir": "system/vendor/", "vendor-dir": "system/vendor/",
"optimize-autoloader": true, "optimize-autoloader": true,
@ -11,7 +18,8 @@
"michelf/php-markdown": "1.*", "michelf/php-markdown": "1.*",
"suin/php-rss-writer": "1.*", "suin/php-rss-writer": "1.*",
"kanti/hub-updater": "0.*", "kanti/hub-updater": "0.*",
"jbroadway/urlify": "^1.0"
"jbroadway/urlify": "^1.0",
"simple-html-dom/simple-html-dom": "*"
}, },
"autoload": { "autoload": {
"files": [ "files": [


+ 62
- 1
system/admin/admin.php View File

@ -775,6 +775,7 @@ function migrate($title, $time, $tags, $content, $url, $user, $source)
} else { } else {
$post_content = '<!--t ' . $post_title . ' t-->' . "\n" . '<!--tag' . $post_tagmd . 'tag-->' . "\n\n" . $content; $post_content = '<!--t ' . $post_title . ' t-->' . "\n" . '<!--tag' . $post_tagmd . 'tag-->' . "\n\n" . $content;
} }
if (!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) { if (!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) {
$post_content = stripslashes($post_content); $post_content = stripslashes($post_content);
@ -788,8 +789,31 @@ function migrate($title, $time, $tags, $content, $url, $user, $source)
file_put_contents($dir . $filename, print_r($post_content, true)); file_put_contents($dir . $filename, print_r($post_content, true));
} }
save_tag_i18n($post_tag, $post_tagmd); save_tag_i18n($post_tag, $post_tagmd);
// import images
if(count($images) > 0) {
foreach ($images as $image_url) {
$imagefile = basename($image_url);
if(!@copy($image_url,'content/images/'.$imagefile))
{
$errors= error_get_last();
echo "COPY ERROR: ".$errors['type'];
echo "<br />\n".$errors['message'];
} else {
echo "$imagefile copied from remote!<br>\n";
// $images_imported++;
}
}
}
$redirect = site_url() . 'admin/clear-cache'; $redirect = site_url() . 'admin/clear-cache';
header("Location: $redirect"); header("Location: $redirect");
} else {
echo "<h1>Found empty Fields:</h1>\r\n";
echo "post title: $post_title <br>\n";
echo "post tag: $post_tag <br>\n";
echo "post url: $post_url <br>\n";
echo "post content: ".substr($post_content, 0, 50)."<br>\n";
echo "<h2>I WILL NOT IMPORT THIS !!!</h2>\r\n<hr>\r\n";
} }
} }
@ -822,7 +846,44 @@ function get_feed($feed_url, $credit)
} else { } else {
$source = null; $source = null;
} }
migrate($title, $time, $tags, $content, $url, $user, $source);
$images = array();
// identify the host-name of the rss feed we are parsing
$source_host = parse_url($feed_url);
if(empty($source_host['host'])) {
$source_host['host'] = $_SERVER['SERVER_NAME']; // seems like we are parsing a local feed
}
$cnt_images = 0;
$html = new \SimpleHtmlDom\simple_html_dom($content);
foreach ($html->find('img') as $img) {
$src = $img->src;
// identify host of img url
$img_host = parse_url($src, PHP_URL_HOST);
$img_path = parse_url($src, PHP_URL_PATH);
if(empty($img_host)) {
$img_host = $source_host['host'];
}
// we only import images if they match the host of the rss feed,
// otherwise legal consequences (copyright breach) may occur
if($img_host == $source_host['host']) {
$cnt_images ++;
$images[] = $source_host['scheme'].'://'.$img_host.$img_path;
// alter the path of the image, point to local src after import
$img->src = '/content/images/'.basename($src);
}
}
// debug
/**
if($cnt_images > 0) {
echo "<h2>IMAGES and bent content</h2>";
echo var_export($images, true);
echo "<hr>" . htmlspecialchars($html) . "<hr>";
}
*/
migrate($title, $time, $tags, $html, $url, $user, $images, $source);
} }
} else { } else {
return $str = '<li>Unsupported feed.</li>'; return $str = '<li>Unsupported feed.</li>';


Loading…
Cancel
Save