From e74df0b3dd4d5e2b05bf7ed1b846204a4f6f8436 Mon Sep 17 00:00:00 2001 From: med-men Date: Sun, 24 Nov 2019 23:42:00 +0100 Subject: [PATCH 1/2] this feature update will allow you to import images within RSS streams. For legal reasons only images from same URL as RSS stream will be imported --- system/admin/admin.php | 63 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/system/admin/admin.php b/system/admin/admin.php index 00cc08d..859d7fe 100644 --- a/system/admin/admin.php +++ b/system/admin/admin.php @@ -616,6 +616,7 @@ function migrate($title, $time, $tags, $content, $url, $user, $source) } else { $post_content = '' . "\n" . '' . "\n\n" . $content; } + if (!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) { if (get_magic_quotes_gpc()) { $post_content = stripslashes($post_content); @@ -629,8 +630,31 @@ function migrate($title, $time, $tags, $content, $url, $user, $source) file_put_contents($dir . $filename, print_r($post_content, true)); } 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 "
\n".$errors['message']; + } else { + echo "$imagefile copied from remote!
\n"; + // $images_imported++; + } + } + } + $redirect = site_url() . 'admin/clear-cache'; header("Location: $redirect"); + } else { + echo "

Found empty Fields:

\r\n"; + echo "post title: $post_title
\n"; + echo "post tag: $post_tag
\n"; + echo "post url: $post_url
\n"; + echo "post content: ".substr($post_content, 0, 50)."
\n"; + echo "

I WILL NOT IMPORT THIS !!!

\r\n
\r\n"; } } @@ -663,7 +687,44 @@ function get_feed($feed_url, $credit) } else { $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 "

IMAGES and bent content

"; + echo var_export($images, true); + echo "
" . htmlspecialchars($html) . "
"; + } + */ + + migrate($title, $time, $tags, $html, $url, $user, $images, $source); } } else { return $str = '
  • Unsupported feed.
  • '; From 775586324c531c96563e1569f48fb273e5308b33 Mon Sep 17 00:00:00 2001 From: med-men Date: Sun, 24 Nov 2019 23:46:32 +0100 Subject: [PATCH 2/2] this feature update will allow you to import images within RSS streams. For legal reasons only images from same URL as RSS stream will be imported --- composer.json | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 87e47f8..113feaa 100644 --- a/composer.json +++ b/composer.json @@ -1,4 +1,11 @@ { + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/Youpie/simple-html-dom" + } + ], + "config": { "vendor-dir": "system/vendor/", "optimize-autoloader": true, @@ -11,7 +18,8 @@ "michelf/php-markdown": "1.*", "suin/php-rss-writer": "1.*", "kanti/hub-updater": "0.*", - "jbroadway/urlify": "^1.0" + "jbroadway/urlify": "^1.0", + "simple-html-dom/simple-html-dom": "*" }, "autoload": { "files": [