From e660ed3a4393da08e3175947482eb3e66d75bd41 Mon Sep 17 00:00:00 2001 From: CaMer0n Date: Mon, 6 Aug 2012 08:55:51 +0000 Subject: [PATCH] e_TEMP added for system temp folder. Import options added for LiveJournal and html (non-CMS) pages. (work in progress) --- e107_admin/plugin.php | 10 +- e107_admin/update_routines.php | 5 +- e107_files/jslib/core/all.jquery.js | 4 +- e107_handlers/e107_class.php | 3 +- e107_handlers/file_class.php | 6 +- e107_plugins/import/admin_import.php | 61 +- e107_plugins/import/images/html.png | Bin 0 -> 1829 bytes e107_plugins/import/images/livejournal.png | Bin 0 -> 4738 bytes .../import/providers/blogger_import_class.php | 2 +- .../import/providers/html_import_class.php | 519 ++++++++++++++++++ .../providers/livejournal_import_class.php | 96 ++++ .../import/providers/rss_import_class.php | 5 +- 12 files changed, 680 insertions(+), 31 deletions(-) create mode 100644 e107_plugins/import/images/html.png create mode 100644 e107_plugins/import/images/livejournal.png create mode 100644 e107_plugins/import/providers/html_import_class.php create mode 100644 e107_plugins/import/providers/livejournal_import_class.php diff --git a/e107_admin/plugin.php b/e107_admin/plugin.php index 32c8e71b0..521b49515 100644 --- a/e107_admin/plugin.php +++ b/e107_admin/plugin.php @@ -30,18 +30,18 @@ if(e_AJAX_REQUEST && isset($_GET['src'])) // Ajax $localfile = md5($remotefile.time()).".zip"; $status = "Downloading..."; - e107::getFile()->getRemoteFile($remotefile,"temp/".$localfile); + e107::getFile()->getRemoteFile($remotefile,$localfile); - if(!file_exists(e_UPLOAD.$localfile)) + if(!file_exists(e_TEMP.$localfile)) { echo 'There was a problem retrieving the file'; exit; } // chmod(e_PLUGIN,0777); - chmod(e_UPLOAD.$localfile,0755); + chmod(e_TEMP.$localfile,0755); require_once(e_HANDLER."pclzip.lib.php"); - $archive = new PclZip(e_UPLOAD.$localfile); + $archive = new PclZip(e_TEMP.$localfile); $unarc = ($fileList = $archive -> extract(PCLZIP_OPT_PATH, e_PLUGIN, PCLZIP_OPT_SET_CHMOD, 0755)); // chmod(e_PLUGIN,0755); $dir = basename($unarc[0]['filename']); @@ -83,7 +83,7 @@ if(e_AJAX_REQUEST && isset($_GET['src'])) // Ajax } echo $status; - @unlink(e_UPLOAD.$localfile); +// @unlink(e_TEMP.$localfile); // echo "file=".$file; exit; diff --git a/e107_admin/update_routines.php b/e107_admin/update_routines.php index 8e5033fbb..72fe70494 100644 --- a/e107_admin/update_routines.php +++ b/e107_admin/update_routines.php @@ -1052,7 +1052,10 @@ function update_706_to_800($type='') { mkdir(e_CACHE_URL,0755); } - + if(!is_dir(e_TEMP)) + { + mkdir(e_TEMP,0755); + } $root_media = str_replace(basename(e_MEDIA)."/","",e_MEDIA); $user_media_dirs = array("images","avatars","files","temp","videos","icons"); diff --git a/e107_files/jslib/core/all.jquery.js b/e107_files/jslib/core/all.jquery.js index ae36edc0c..be66d4b38 100644 --- a/e107_files/jslib/core/all.jquery.js +++ b/e107_files/jslib/core/all.jquery.js @@ -453,8 +453,8 @@ $(document).ready(function() var target = $(this).attr("data-target"); // support for input buttons etc. var loading = $(this).attr('data-loading'); // image to show loading. var nav = $(this).attr('data-nav-inc'); - - if(nav !== null) + + if(nav != null) { eNav(this,'.e-ajax'); //modify data-src value for next/prev. 'from=' } diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index 77f483a9e..ec99d092f 100644 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -448,7 +448,7 @@ class e107 $ret['LOGS_DIRECTORY'] = $ret['SYSTEM_DIRECTORY'].'logs/'; $ret['BACKUP_DIRECTORY'] = $ret['SYSTEM_DIRECTORY'].'backup/'; - + $ret['TEMP_DIRECTORY'] = $ret['SYSTEM_DIRECTORY'].'temp/'; //TODO create directories which don't exist. return $ret; @@ -2578,6 +2578,7 @@ class e107 define('e_LOG', $this->get_override_rel('LOGS')); define('e_BACKUP', $this->get_override_rel('BACKUP')); + define('e_TEMP', $this->get_override_rel('TEMP')); // // HTTP absolute paths diff --git a/e107_handlers/file_class.php b/e107_handlers/file_class.php index c7c2e8a9b..08a26d7dc 100644 --- a/e107_handlers/file_class.php +++ b/e107_handlers/file_class.php @@ -290,9 +290,11 @@ class e_file } // Grab a remote file and save it in the /temp directory. requires CURL - function getRemoteFile($remote_url, $local_file) + function getRemoteFile($remote_url, $local_file, $type='temp') { - $fp = fopen(e_MEDIA.$local_file, 'w'); // media-directory is the root. + $path = ($type == 'media') ? e_MEDIA : e_TEMP; + + $fp = fopen($path.$local_file, 'w'); // media-directory is the root. $cp = curl_init($remote_url); curl_setopt($cp, CURLOPT_FILE, $fp); diff --git a/e107_plugins/import/admin_import.php b/e107_plugins/import/admin_import.php index 38d72dae1..7f24971c6 100644 --- a/e107_plugins/import/admin_import.php +++ b/e107_plugins/import/admin_import.php @@ -319,7 +319,7 @@ function dbImport($mode='db') } else { - $mes->addError(LAN_CONVERT_42); + $mes->addError(LAN_CONVERT_42. "[".$current_db_type."]"); return false; } @@ -339,6 +339,13 @@ function dbImport($mode='db') } } + if(!is_array($db_import_blocks)) + { + $mes->addError("No areas selected for import"); // db connect failed + return false; + } + + foreach ($db_import_blocks as $k => $v) { @@ -408,6 +415,16 @@ function dbImport($mode='db') array($loopCounter,$loopCounter-$errorCounter,$errorCounter, $k),LAN_CONVERT_47); $mes->addSuccess($msg); // couldn't set query } + else + { + $mes->addDebug("Error: _POST['import_block_{$k}'] = ".$_POST['import_block_{$k}']); // cou + + } + } + else + { + $mes->addDebug("\$db_blocks_to_import doesn't contain key: ".$k); // cou + } } @@ -534,13 +551,17 @@ function showImportOptions($mode='csv') { $mes->addDebug("Class Available: ".$mode); $proObj = new $mode; + if($proObj->init()===FALSE) + { + return; + } } $message = LAN_CONVERT_02."
".LAN_CONVERT_05.""; $emessage->add($message, E_MESSAGE_WARNING); $text = " -
+ @@ -608,15 +629,15 @@ function showImportOptions($mode='csv') - + - + - + @@ -648,16 +669,22 @@ function showImportOptions($mode='csv') $text .= " - - - - -
$importType ".LAN_CONVERT_20."
$importType ".LAN_CONVERT_21."
$importType ".LAN_CONVERT_22."
$importType ".LAN_CONVERT_23."
".LAN_CONVERT_38." + ".LAN_CONVERT_39."
".LAN_CONVERT_16.""; - $text .= $e_userclass->vetted_tree('classes_select',array($e_userclass,'checkbox'), $checked_class_list,'main,admin,classes,matchclass'); - - $text .= "
-
".$frm->admin_button('do_conversion',LAN_CONTINUE, 'execute'). + "; + + if(varset($proObj->defaultClass) !== false) + { + $text .= " + ".LAN_CONVERT_16." + "; + $text .= $e_userclass->vetted_tree('classes_select',array($e_userclass,'checkbox'), varset($_POST['classes_select']),'main,admin,classes,matchclass'); + $text .= ""; + } + + $action = varset($proObj->action,'do_conversion'); + $text .= " +
".$frm->admin_button($action,LAN_CONTINUE, 'execute'). $frm->admin_button('back',LAN_CANCEL, 'cancel')." @@ -667,9 +694,9 @@ function showImportOptions($mode='csv') // Now a little bit of JS to initialise some of the display divs etc $temp = ''; - if ($import_source) $temp .= "disp('{$import_source}');"; - if ($current_db_type) $temp .= " flagbits('{$current_db_type}');"; - if ($temp) $text .= ""; + if(varset($import_source)) { $temp .= "disp('{$import_source}');"; } + if (varset($current_db_type)) $temp .= " flagbits('{$current_db_type}');"; + if (varset($temp)) $text .= ""; $ns -> tablerender(LAN_CONVERT_01." :: ".$importType, $emessage->render().$text); diff --git a/e107_plugins/import/images/html.png b/e107_plugins/import/images/html.png new file mode 100644 index 0000000000000000000000000000000000000000..7c650be41886bb08097554ee030bd9ef76f16015 GIT binary patch literal 1829 zcmV+=2io|FP)F8i5d=XlFE2kx z&-uEp<53Ff0O=?%E-qe7O|7pn*1Ei6Hc~4pDvbZCG&MCD`}XZCBfU~G08Hc_eRgZ- zzn{MVK@=g-XRyU!ADaKd^HZ>Q?_MlhwhTo@Ma2Z-$dV;X<|bo8?8%%}QB)PGqCi!L zAT*xM<4Os<&*z87GiJ;fNlsq>APBinT4*;S_W`p_6@}UkMZ~VNetdq`hkJhV7eQp(#fUT+%O^Qe z;&t=!<8pIBw&zSRM`OOle1ghjBu)}vzW~^7MUzhUt4IQ3v|hoU>kv~fVb}YIk?Xk$ zU&w~qz-81nrr?L;8&UDC7nSe1F(p5rOOnu22WCJ@08nWAE>*Rx$xP-Ttp%nxEHQQSUif<^!3Qenv8JNgQ{Dlc-319&Hfv{{38gbYJ)0MWJofX zWF?6YNMv_`KmayX!j97oSWq+-Db#Kbr$Ck3U~{cSu(K0^=pEc?eFL>k^AU*!F=y&7 z>^$nlD(^5v1%sPTx3b<~8IVl|BvGctWHk69$aJTop#!+nuA(jCN4r)_&lrVf4C6_w+q=ooA&Qz98vQTQTn+66PG%GeMk4PImI2ENxg#<$BuswlO;k2&xalV#Z3P69 zfKqtgX2^ zgsR({AkwC;-d#nRun~6UJObe~bVTjw40T{khRRj5`Ee7-|AGN#2DU}|zB4@wN6&iD zNqmQ*A>3`9fNzesP#zeL*5K1vJUt&P=O|b)GXrfce!Mkp6hB(nd`s7$09dxN(yvIF zPNS|(^Kvmtjo?b{Ed;uv1SE(+2sm}E1a9XAo)C2cdho;sj88MLZgvi02KanSSFbz3 zfDEuyOhy(+46YqGzt)R%Er9APf1}wKARu9cA^{w#-iFE=FFxG!6M`*EQMD!?s!b+9 zBA?InFnxoH0?|zVD)TTHJ+C+rC>k!TpN+3i-^A7<*HP0N;*p~13K}!Eqoi;YHoTl2 zKhzDKB0zfRq!)z&065k72tiD4vlRuSx%7W0V`2Pox1~QRfNhm7?C-dYD^+#oK__q` zdS)`##rj37(Zhdq1HG8DZdB~Q@sqQ0{i3UX0Jr=S(gZiIb+z!bpCzIgO%6wOez33w zm@?5!QjAiOepHDayP#ZPaIow@)>dQzvJju+kS5E)sxxtuvN=_rp@-4)R9z6SP08f_KVE6W zf(aSWOr~^t8miQ9rX))c T00000NkvXXu0mjfF*q_c^U_PE literal 0 HcmV?d00001 diff --git a/e107_plugins/import/images/livejournal.png b/e107_plugins/import/images/livejournal.png new file mode 100644 index 0000000000000000000000000000000000000000..dacb4407b004666416d582411e1f4d21a06c76cd GIT binary patch literal 4738 zcmV-|5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5`Rmv^Jz06a3)*n|STbA)eiRnC@5KWpH!~FPflGEOIjA6H%6BNyY0U1={L8 z0vuXPW$>x)1Ag@>DE9&d)cSDztRwKiS%YyO0QHpO>PyM0iu`*1!KUvg@;OGO6*d} zC=n$LPg(lU!bQ!3Cypxed^p#<8khsXL48#5-lRt^wD=yla}3Z*fpwOXImK{Rv8GXo zdonM%h~RnN!T`z-$^a}-AA!INcwOr^wbEz8B z<`v;Q3xJ4%4GqGc(@}Ph2CS~vq@oUQ7RZe8I8%&}Gm1qumZeDx!h*6_1E?nK&$8C} zd_GhC!mJC#BbHAtvK+|-96S@C6hxJvJfX%D(osWOoh23#j8*^gC!{=#XsrpuaJm8@ z48y6uzP>{nHf&g{ltRx|c-e|TIo8)3v{M)XnN=t1Nkxs&{QJKk=Nv&0Fg`vW9z1yP zP<1CPba!`mpFDXo*Vx!N?{*BeDfM)x@kJAeMmdevhJrTe58b2-g|(J=JWe8!VCT-A z&kYO=ybYj41XZHj*4f$ljRzih;Op(}?R8-oRwVnVODRPV1Q=uJ?(Tm5kw+eRuuv%U zh)Avs03ZgeTD*Aiwk=z>d}iIcb<0z!R8lGBeH0K%DT>8nI668y(c9a*Z_l1RPXn(3 z<02x}005%EVxSdh@qIs0ePR8#%Q+W1=gtDdvoTewNhw+Iajt(306?@FQAn}cr2qf` Q07*qoM6N<$f;2ZXG!|ys+W-In literal 0 HcmV?d00001 diff --git a/e107_plugins/import/providers/blogger_import_class.php b/e107_plugins/import/providers/blogger_import_class.php index 2c2a4cd1d..511a88e85 100644 --- a/e107_plugins/import/providers/blogger_import_class.php +++ b/e107_plugins/import/providers/blogger_import_class.php @@ -34,7 +34,7 @@ $import_default_prefix['blogger_import'] = ''; class blogger_import extends rss_import { var $cleanupHtml = false; - + var $defaultClass = false; /* If the first 500 posts of your blog feed are here: diff --git a/e107_plugins/import/providers/html_import_class.php b/e107_plugins/import/providers/html_import_class.php new file mode 100644 index 000000000..dd16adca9 --- /dev/null +++ b/e107_plugins/import/providers/html_import_class.php @@ -0,0 +1,519 @@ +feedUrl = vartrue($_POST['siteUrl'],false); + $this->feedUrl = "http://drboylan.com/"; + $this->feedUrl = rtrim($this->feedUrl,"/"); + + if($_POST['preview']) + { + $this->previewContent(); + return false; + } + } + + function config() + { + $var[0]['caption'] = "Website Home-page URL"; + $var[0]['html'] = ""; + + return $var; + } + + + // Set up a query for the specified task. + // Returns TRUE on success. FALSE on error + function setupQuery($task, $blank_user=FALSE) + { + $this->arrayData = array(); + + print_a($_POST); + + + + $file = $this->feedUrl; + + switch ($task) + { + case 'news' : + case 'page' : + case 'links' : + + // $rawData = $xml->getRemoteFile($file); + // print_a($rawData); + //$content = $this->getAll(); + + if ($array === FALSE || $file === FALSE) return FALSE; + + foreach($array['channel']['item'] as $val) + { + $this->arrayData[] = $val; + } + + $this->arrayData = array_reverse($this->arrayData); // most recent last. + reset($this->arrayData); + + break; + + default : + return FALSE; + } + + $this->copyUserInfo = !$blank_user; + $this->currentTask = $task; + return TRUE; + } + + private function getAll() + { + $html = $this->getRawHtml(); + $pages = $this->findLinks($html); + $c = 0; + foreach($pages as $url=>$p) + { + // echo "url=".$url; + $html = $this->getRawHtml($url); + + $html = str_replace("\n","",$html); // strip line-breaks. + $html = preg_replace("/([^<]*)<\/title>/i","",$html); + $html = trim($html,"\n"); + + $body = trim(strip_tags($html,"<b><i><u><strong><br><img><object><embed>")); + + $content[$url] = array( + 'title' => str_replace("\n","",$p['title']), + // 'raw' => $html, + 'body' => $body + ); + + $c++; + + if($c == 15) + { + break; + } + + } + + return $content; + + } + + private function previewContent() + { + $frm = e107::getForm(); + $ns = e107::getRender(); + $tp = e107::getParser(); + + $content = $this->getAll(); + + + $text = "<form method='post' action='".e_SELF."?import_type=html_import' id='core-import-form'> + <fieldset id='core-import-select-type'> + <legend class='e-hideme'>".DBLAN_10."</legend> + <table class='adminlist'> + <colgroup> + <col style='width:40%' /> + <col /> + <col /> + <col /> + </colgroup> + <thead> + <tr> + <th>".LAN_TITLE."</th> + <th>Sample</th> + <th>".LAN_URL."</th> + <th class='center'>".LAN_OPTIONS."</th> + + </tr> + </thead> + <tbody>\n"; + + + foreach ($content as $key=>$data) + { + + $text .= "<tr> + + <td>".$data['title']."</td>\n + <td>".$tp->text_truncate($data['body'],150)."</td>\n + <td class='center middle'> + ".$key." + </td> + + "; + + $text .= " + <td class='center middle'> + ".$frm->selectbox('import_'.$key,array('news'=>'News','page'=>'Page','0'=>'Ignore'))." + </td> + </tr>"; + } + + + $text .= " + </tbody> + </table> + <div class='buttons-bar center'> + ".$frm->admin_button('do_conversion',LAN_CONTINUE, 'execute'). + $frm->admin_button('back',LAN_CANCEL, 'cancel')." + <input type='hidden' name='db_import_type' value='html_import' /> + <input type='hidden' name='import_type' value='html_import' /> + <input type='hidden' name='import_source' value='".$this->sourceType."' /> + <input type='hidden' name='import_block_news' value='1' /> + <input type='hidden' name='siteUrl' value='".$this->feedUrl."' /> + </div> + </fieldset> + </form>"; + + $ns->tablerender(LAN_CONVERT_01,$text); + + + + } + + + private function getRawHtml($file='') + { + $url = $this->feedUrl."/".$file; + + if($file == '') { $file = "index.html"; } // just for local file, not url. + + $path = md5($this->feedUrl); + $local_file = $path."/".$file; + + if(!is_dir(e_TEMP.$path)) + { + mkdir(e_TEMP.$path,0755); + } + + if(!file_exists(e_TEMP.$local_file)) + { + e107::getFile()->getRemoteFile($url, $local_file); // downloads to e107_system/.../temp + } + + if($this->useTidy) + { + $tidy = new tidy(); + $options = array("output-xhtml" => true, "clean" => true); + $parsed = tidy_parse_file(e_TEMP.$local_file,$options); + return $parsed->value; + } + elseif(!$html = file_get_contents(e_TEMP.$local_file)) + { + return "Couldn't read file"; + } + + return $html; + } + + + + + + + private function findLinks($content,$type='html') + { + $doc = new DOMDocument(); + $doc->loadHTML($content); + + $urls = $doc->getElementsByTagName('a'); + $pages = array(); + + foreach ($urls as $u) + { + $title = str_replace("\n","",$u->nodeValue); + $href = $u->attributes->getNamedItem('href')->value; + $href = ltrim(str_replace($this->feedUrl,"",$href),"/"); + + if($type == 'html' && (substr($href,-5,5)=='.html' || substr($href,-4,4)=='.htm')) + { + $pages[$href] = array('title'=>$title, 'href'=>$href); + } + } + + return $pages; + + } + + + + + //------------------------------------ + // Internal functions below here + //------------------------------------ + + /** + * Align source data to e107 User Table + * @param $target array - default e107 target values for e107_user table. + * @param $source array - WordPress table data + */ + function copyUserData(&$target, &$source) + { + + } + + /** + * Align source data with e107 News Table + * @param $target array - default e107 target values for e107_news table. + * @param $source array - RSS data + */ + function copyNewsData(&$target, &$source) + { + + if(!$content = $this->process('content_encoded',$source)) + { + $body = $this->process('description',$source); + } + else + { + $body = $content; + } + + $body = $this->saveImages($body,'news'); + $keywords = $this->process('category',$source); + + + if(!vartrue($source['title'][0])) + { + list($title,$newbody) = explode("<br />",$body,2); + $title = strip_tags($title); + if(trim($newbody)!='') + { + $body = $newbody; + } + } + else + { + $title = $source['title'][0]; + } + + $target['news_title'] = $title; + // $target['news_sef'] = $source['post_name']; + $target['news_body'] = "[html]".$body."[/html]"; + // $target['news_extended'] = ''; + $target['news_meta_keywords'] = implode(",",$keywords); + // $target['news_meta_description'] = ''; + $target['news_datestamp'] = strtotime($source['pubDate'][0]); + // $target['news_author'] = $source['post_author']; + // $target['news_category'] = ''; + // $target['news_allow_comments'] = ($source['comment_status']=='open') ? 1 : 0; + // $target['news_start'] = ''; + // $target['news_end'] = ''; + /// $target['news_class'] = ''; + // $target['news_render_type'] = ''; + // $target['news_comment_total'] = $source['comment_count']; + // $target['news_summary'] = $source['post_excerpt']; + // $target['news_thumbnail'] = ''; + // $target['news_sticky'] = ''; + + + + return $target; // comment out to debug + + $this->renderDebug($source,$target); + + // DEBUG INFO BELOW. + + } + + + function process($type='description',$source) + { + switch ($type) + { + case 'category': + $keywords = array(); + if(is_array(varset($source['category'][0]))) + { + foreach($source['category'] as $val) + { + if(varset($val['@value'])) + { + $keywords[] = $val['@value']; + } + } + return $keywords; + } + elseif(is_array(varset($source['category']))) + { + foreach($source['category'] as $val) + { + if(varset($val) && is_string($val)) + { + $keywords[] = $val; + } + } + return $keywords; + } + break; + + default: + return varset($source[$type][0]); + break; + } + } + + /** + * Align source data to e107 Page Table + * @param $target array - default e107 target values for e107_page table. + * @param $source array - WordPress table data + */ + function copyPageData(&$target, &$source) + { + $body = $this->saveImages($source['description'][0],'page'); + // $target['page_id'] = $source['ID']; // auto increment + $target['page_title'] = $source['title'][0]; + // $target['page_sef'] = $source['post_name']; + $target['page_text'] = "[html]".$body."[/html]"; + // $target['page_metakeys'] = ''; + // $target['page_metadscr'] = ''; + $target['page_datestamp'] = strtotime($source['pubDate'][0]); + // $target['page_author'] = $source['post_author']; + // $target['page_category'] = '', + // $target['page_comment_flag'] = ($source['comment_status']=='open') ? 1 : 0; + // $target['page_password'] = $source['post_password']; + + return $target; // comment out to debug + + // DEBUG INFO BELOW. + $this->renderDebug($source,$target); + + } + + + /** + * Align source data to e107 Links Table + * @param $target array - default e107 target values for e107_links table. + * @param $source array - WordPress table data + */ + function copyLinksData(&$target, &$source) + { + $tp = e107::getParser(); + + // $target['page_id'] = $source['ID']; // auto increment + $target['link_name'] = $source['title'][0]; + $target['link_url'] = $source['link'][0]; + // $target['link_description'] = "[html]".$source['post_content']."[/html]"; + // $target['link_button'] = ''; + // $target['link_category'] = ''; + // $target['link_order'] = strtotime($source['post_date']); + // $target['link_parent'] = $source['post_author']; + // $target['link_open'] = ''; + // $target['link_class'] = ''; + // $target['link_sefurl'] = $source['post_password']; + + + + return $target; // comment out to debug + + $this->renderDebug($source,$target); + + } + + + /** Download and Import remote images and update body text with local relative-links. eg. {e_MEDIA} + * @param returns text-body with remote links replaced with local ones for the images downloaded. + */ + function saveImages($body,$cat='news') + { + $mes = e107::getMessage(); + $med = e107::getMedia(); + $tp = e107::getParser(); + $search = array(); + $replace = array(); + + + // echo htmlentities($body); + preg_match_all("/(((http:\/\/www)|(http:\/\/)|(www))[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)\.(jpg|jpeg|gif|png|svg)/im",$body,$matches); + $fl = e107::getFile(); + + if(is_array($matches[0])) + { + $relPath = 'images/'.md5($this->feedUrl); + + if(!is_dir(e_MEDIA.$relPath)) + { + mkdir(e_MEDIA.$relPath,'0755'); + } + + foreach($matches[0] as $link) + { + if(file_exists($relPath."/".$filename)) + { + continue; + } + + $filename = basename($link); + $fl->getRemoteFile($link,$relPath."/".$filename); + $search[] = $link; + $replace[] = $tp->createConstants(e_MEDIA.$relPath."/".$filename,1); + } + } + + if(count($search)) + { + $med->import($cat,e_MEDIA.$relPath); + } + + return str_replace($search,$replace,$body); + + } + + + + + + + + function renderDebug($source,$target) + { + + // echo print_a($target); + // return; + + echo " + <div style='width:1000px'> + <table style='width:100%'> + <tr> + <td style='width:500px;padding:10px'>".print_a($source,TRUE)."</td> + <td style='border-left:1px solid black;padding:10px'>".print_a($target,TRUE)."</td> + </tr> + </table> + </div>"; + } + +} + + +?> \ No newline at end of file diff --git a/e107_plugins/import/providers/livejournal_import_class.php b/e107_plugins/import/providers/livejournal_import_class.php new file mode 100644 index 000000000..3be4134cb --- /dev/null +++ b/e107_plugins/import/providers/livejournal_import_class.php @@ -0,0 +1,96 @@ +<?php +/* + * e107 website system + * + * Copyright (C) 2008-2012 e107 Inc (e107.org) + * Released under the terms and conditions of the + * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) + * + * $Source: /cvs_backup/e107_0.8/e107_plugins/import/wordpress_import_class.php,v $ + * $Revision: 11315 $ + * $Date: 2010-02-10 10:18:01 -0800 (Wed, 10 Feb 2010) $ + * $Author: secretr $ + */ + +// require_once('import_classes.php'); +require_once('rss_import_class.php'); + +$import_class_names['livejournal_import'] = 'LiveJournal'; +$import_class_comment['livejournal_import'] = 'Import up to 500 items from yourblog.livejournal.com'; +$import_class_support['livejournal_import'] = array('news'); +$import_default_prefix['livejournal_import'] = ''; + +class livejournal_import extends rss_import +{ + var $cleanupHtml = false; + var $defaultClass = false; + /* + + */ + function init() + { + $mes = e107::getMessage(); + + if(vartrue($_POST['siteUrl'])) + { + $domain = preg_replace("/https?:\/\//i",'',$_POST['siteUrl']); + list($site,$dom,$tld) = explode(".",$domain); + + $this->feedUrl = "http://".$site.".livejournal.com/data/rss"; + } + + if(vartrue($_POST['siteCleanup'])) + { + $this->cleanupHtml = true; + } + + $mes->addDebug("LiveJournal Feed:".$this->feedUrl); + } + + + function config() + { + $var[0]['caption'] = "Your LiveJournal URL"; + $var[0]['html'] = "<input class='tbox' type='text' name='siteUrl' size='80' value='{$_POST['bloggerUrl']}' maxlength='250' />"; + $var[0]['help'] = "eg. http://blogname.livejournal.com"; + + $var[1]['caption'] = "Cleanup HTML in content"; + $var[1]['html'] = "<input class='tbox' type='checkbox' name='siteCleanup' size='80' value='1' />"; + $var[1]['help'] = "Tick to enable"; + + return $var; + } + + function process($type,$source) + { + + switch ($type) + { + case 'description': + $body = $source[$type][0]; + if($this->cleanupHtml == TRUE) + { + $body = preg_replace("/font-family: [\w]*;/i","", $body); + $body = preg_replace('/class="[\w]*" /i',"", $body); + $body = str_replace("<br>","<br />",$body); + return $body; + } + else + { + return $body; + } + break; + + default: + return $source[$type][0]; + break; + } + + + } + + //TODO Comment Import: +} + + +?> \ No newline at end of file diff --git a/e107_plugins/import/providers/rss_import_class.php b/e107_plugins/import/providers/rss_import_class.php index 9365f8dd7..793f78b7d 100644 --- a/e107_plugins/import/providers/rss_import_class.php +++ b/e107_plugins/import/providers/rss_import_class.php @@ -32,6 +32,7 @@ class rss_import extends base_import_class { var $sourceType = 'rss'; var $feedUrl = null; + var $defaultClass = false; function init() { @@ -104,7 +105,7 @@ class rss_import extends base_import_class /** * Align source data with e107 News Table * @param $target array - default e107 target values for e107_news table. - * @param $source array - WordPress table data + * @param $source array - RSS data */ function copyNewsData(&$target, &$source) { @@ -293,7 +294,7 @@ class rss_import extends base_import_class } $filename = basename($link); - $fl->getRemoteFile($link,$relPath."/".$filename); + $fl->getRemoteFile($link,$relPath."/".$filename,'media'); $search[] = $link; $replace[] = $tp->createConstants(e_MEDIA.$relPath."/".$filename,1); }