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 000000000..7c650be41 Binary files /dev/null and b/e107_plugins/import/images/html.png differ diff --git a/e107_plugins/import/images/livejournal.png b/e107_plugins/import/images/livejournal.png new file mode 100644 index 000000000..dacb4407b Binary files /dev/null and b/e107_plugins/import/images/livejournal.png differ 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); }