From acf872a3103cd6e3c8d3cead624fa0d9270e79fc Mon Sep 17 00:00:00 2001 From: Cameron Date: Wed, 6 Mar 2013 01:23:30 -0800 Subject: [PATCH] More import work --- e107_plugins/import/admin_import.php | 2 +- e107_plugins/import/import_classes.php | 2 +- .../import/providers/rss_import_class.php | 67 +++++++++++++++++-- 3 files changed, 63 insertions(+), 8 deletions(-) diff --git a/e107_plugins/import/admin_import.php b/e107_plugins/import/admin_import.php index 2b1a95d18..d0679a385 100644 --- a/e107_plugins/import/admin_import.php +++ b/e107_plugins/import/admin_import.php @@ -493,7 +493,7 @@ class import_main_ui extends e_admin_ui $importType ".LAN_CONVERT_24." "; - $defCheck = (count($proObj->supported==1)) ? true : false; + $defCheck = (count($proObj->supported)==1) ? true : false; foreach ($this->importTables as $k => $v) { if(in_array($k, $proObj->supported)) // display only the options supported. diff --git a/e107_plugins/import/import_classes.php b/e107_plugins/import/import_classes.php index a11360780..a03246f3a 100644 --- a/e107_plugins/import/import_classes.php +++ b/e107_plugins/import/import_classes.php @@ -24,7 +24,7 @@ class base_import_class var $DBPrefix = ''; var $currentTask = ''; var $copyUserInfo = TRUE; - var $arrayData = array(); + protected $arrayData = array(); /** * Connect to the external DB if not already connected diff --git a/e107_plugins/import/providers/rss_import_class.php b/e107_plugins/import/providers/rss_import_class.php index 7263bcad7..2ffc786ff 100644 --- a/e107_plugins/import/providers/rss_import_class.php +++ b/e107_plugins/import/providers/rss_import_class.php @@ -39,19 +39,26 @@ class rss_import extends base_import_class var $feedUrl = null; var $defaultClass = false; - - - + function init() { - $this->feedUrl = vartrue($_POST['rss_feed'],false); + $this->feedUrl = vartrue($_POST['rss_feed'],false); + $this->saveImages = vartrue($_POST['rss_saveimages'],false); } + + function config() { + $frm = e107::getForm(); + $var[0]['caption'] = "Feed URL"; $var[0]['html'] = ""; + $var[1]['caption'] = "Save Images Locally"; + $var[1]['html'] = $frm->checkbox('rss_saveimages',1); + + return $var; } @@ -291,6 +298,54 @@ class rss_import extends base_import_class $tp = e107::getParser(); $search = array(); $replace = array(); + $fl = e107::getFile(); + + + $result = $tp->getTags($body, 'img'); + + if($result) + { + $relPath = 'images/'. substr(md5($this->feedUrl),0,10); + + if(!is_dir(e_MEDIA.$relPath)) + { + mkdir(e_MEDIA.$relPath,'0755'); + } + + foreach($result['img'] as $att) + { + $filename = basename($att['src']); + + if(file_exists(e_MEDIA.$relPath."/".$filename)) + { + continue; + } + + $fl->getRemoteFile($att['src'], $relPath."/".$filename, 'media'); + + if(filesize(e_MEDIA.$relPath."/".$filename) > 0) + { + $search[] = $att['src']; + $replace[] = $tp->createConstants(e_MEDIA.$relPath."/".$filename,1); + } + } + + } + else + { + $mes->addDebug("No Images Found: ".print_a($result,true)); + } + + if(count($search)) + { + $mes->addDebug("Found: ".print_a($search,true)); + $mes->addDebug("Replaced: ".print_a($replace,true)); + $med->import($cat,e_MEDIA.$relPath); + } + + return str_replace($search,$replace,$body); + + // echo htmlentities($body); @@ -299,7 +354,7 @@ class rss_import extends base_import_class if(is_array($matches[0])) { - $relPath = 'images/'.md5($this->feedUrl); + $relPath = 'images/'. substr(md5($this->feedUrl),0,10); if(!is_dir(e_MEDIA.$relPath)) { @@ -315,7 +370,7 @@ class rss_import extends base_import_class continue; } - $fl->getRemoteFile($link,$relPath."/".$filename,'media'); + $fl->getRemoteFile($link,$relPath."/".$filename, 'media'); $search[] = $link; $replace[] = $tp->createConstants(e_MEDIA.$relPath."/".$filename,1);