1
0
mirror of https://github.com/e107inc/e107.git synced 2025-03-14 01:19:44 +01:00

Blogger Import added. TinyMce Image fixes. Custom-pages fixes. Moved Upload-js out of admin header and into media-manager page only. Parser fixes for [html] bbcode. XML parser fix for <content:encoded> rss tags.

This commit is contained in:
CaMer0n 2012-07-23 02:25:17 +00:00
parent 384b123475
commit d5a3b29340
18 changed files with 475 additions and 133 deletions

View File

@ -299,7 +299,9 @@ class page_admin_ui extends e_admin_ui
echo $text;
exit;
// return $text;
/*
<div class='bbcode large' >
*/
}
@ -717,7 +719,7 @@ class page_admin_ui extends e_admin_ui
$newData = "";
foreach($_POST as $k=>$v)
{
if(substr($k,0,4)=='data')
if(substr($k,0,4)=='data' && trim($v)!='')
{
list($tm,$key) = explode("_",$k);
@ -728,7 +730,7 @@ class page_admin_ui extends e_admin_ui
// return;
}
// echo $newData;
// echo nl2br($newData);
$page_text = $tp->toDB($newData);
$pauthor = ($_POST['page_display_authordate_flag'] ? USERID : 0); // Ideally, this check should be done in the front-end.

View File

@ -29,15 +29,12 @@ e107::getDb()->db_Mark_Time('(Header Top)');
e107::js('core', 'colorbox/jquery.colorbox-min.js', 'jquery', 2);
e107::css('core', 'colorbox/colorbox.css', 'jquery');
// e107::js('core', 'fancybox/jquery.fancybox-1.3.4.js', 'jquery', 2);
// e107::css('core', 'fancybox/jquery.fancybox-1.3.4.css', 'jquery');
e107::js('core', 'jquery.elastic.js', 'jquery', 2);
e107::js('core', 'jquery-ui-timepicker-addon.js', 'jquery', 2);
e107::js('core', 'plupload/plupload.full.js', 'jquery', 2);
e107::css('core', 'plupload/jquery.plupload.queue/css/jquery.plupload.queue.css', 'jquery');
e107::js('core', 'plupload/jquery.plupload.queue/jquery.plupload.queue.js', 'jquery', 2);
//e107::js('core', 'plupload/plupload.full.js', 'jquery', 2);
//e107::css('core', 'plupload/jquery.plupload.queue/css/jquery.plupload.queue.css', 'jquery');
//e107::js('core', 'plupload/jquery.plupload.queue/jquery.plupload.queue.js', 'jquery', 2);
e107::css('core', 'chosen/chosen.css', 'jquery');
e107::js('core', 'chosen/chosen.jquery.min.js', 'jquery', 2);
@ -46,13 +43,12 @@ e107::css('core', 'password/style.css', 'jquery');
e107::js('core', 'password/jquery.pwdMeter.js', 'jquery', 2);
e107::js("core", "core/mediaManager.js","jquery",3);
// e107::js("core", "core/mediaManager.js","jquery",3);
e107::js("core", "tooltip/jquery.tipsy.js","jquery",3);
e107::css('core', 'tooltip/tipsy.css', 'jquery');
e107::js("core", "tags/jquery.tagit.js","jquery",3);
e107::css('core', 'tags/jquery.tagit.css', 'jquery');
// e107::js("core", "tooltip/jquery.qtip-1.0.0-rc3.min.js","jquery",3);
e107::css('core', 'core/admin.jquery.css', 'jquery');

View File

@ -24,6 +24,10 @@ if (!getperms("A") && ($_GET['action'] != 'dialog'))
exit;
}
e107::js('core', 'plupload/plupload.full.js', 'jquery', 2);
e107::css('core', 'plupload/jquery.plupload.queue/css/jquery.plupload.queue.css', 'jquery');
e107::js('core', 'plupload/jquery.plupload.queue/jquery.plupload.queue.js', 'jquery', 2);
e107::js("core", "core/mediaManager.js","jquery",3);
/*
* CLOSE - GO TO MAIN SCREEN
@ -670,7 +674,7 @@ class media_admin_ui extends e_admin_ui
{
$frm = e107::getForm();
$bbcodeMode = ($this->getQuery('bbcode')=='img') ? 'bbcode=img' : FALSE;
$text = "
<div class='admintabs' id='tab-container'>
<ul class='e-tabs' id='core-emote-tabs'>

View File

@ -30,7 +30,7 @@ if(e_AJAX_REQUEST && isset($_GET['src'])) // Ajax
$localfile = md5($remotefile.time()).".zip";
$status = "Downloading...";
e107::getFile()->getRemoteFile($remotefile,$localfile);
e107::getFile()->getRemoteFile($remotefile,"temp/".$localfile);
if(!file_exists(e_UPLOAD.$localfile))
{

View File

@ -1,3 +1,5 @@
//<?
// no longer used - see e_parse_class.
$code_text = str_replace("\r\n", " ", $code_text);
$code_text = html_entity_decode($code_text, ENT_QUOTES, CHARSET);
return $code_text;
//return "<!-- bbcode-html -->".$code_text."<!-- bbcode-html-end -->";

View File

@ -392,65 +392,7 @@ $(document).ready(function()
// ----------------- Upload --------------------------------------
var upath = $("#uploader").attr("rel");
$("#uploader").pluploadQueue({
// General settings
runtimes : "html5,html4",
url : upath,
max_file_size : "10mb",
chunk_size : "1mb",
unique_names : false,
// Resize images on clientside if we can
// resize : {width : 320, height : 240, quality : 90},
// Specify what files to browse for
filters : [
{title : "Image files", extensions : "jpg,gif,png,jpeg"},
{title : "Zip files", extensions : "zip,gz"}
],
preinit : {
Init: function(up, info) {
//log('[Init]', 'Info:', info, 'Features:', up.features);
}
},
init : {
FilesAdded: function(up, files) {
},
FileUploaded: function(up, file, info) { // Called when a file has finished uploading
//log('[FileUploaded] File:', file, "Info:", info);
},
UploadProgress: function(up, file) { // Called while a file is being uploaded
// console.log(up.total);
// console.log('[UploadProgress]', 'File:', file, "Total:", up.total);
},
UploadComplete: function(up, files){
document.location.reload(); // refresh the page.
},
ChunkUploaded: function(up, file, info) { // Called when a file chunk has finished uploading
//log('[ChunkUploaded] File:', file, "Info:", info);
// console.log(info);
},
Error: function(up, args) { // Called when a error has occured
alert('There was an error');
// console.log(args);
}
}
});
// -----------------------------------------------------------------

View File

@ -31,7 +31,7 @@ $(document).ready(function()
{
var style = '';
var bb = '';
var target = $(e).attr('data-target');
// var path = $(e).attr('data-path');
// var preview = $(e).attr('data-preview');
@ -129,8 +129,14 @@ $(document).ready(function()
// $('textarea#' + target, window.top.document).attr('value',bbpath);
}
// if(bbcode == 'wysiwyg')
{
//alert('hello');
}
if(bbcode == "img")
{
// bbpath = '['+bbcode+']'+ path + '[/' + bbcode + ']';
//alert(bbpath);
}
@ -144,17 +150,86 @@ $(document).ready(function()
$('img#' + target + "_prev", window.top.document).attr('src',preview); // set new value
$('div#' + target + "_prev", window.top.document).html(preview); // set new value
$('span#' + target + "_prev", window.top.document).html(preview); // set new value
// see $frm->filepicker()
$('input#' + target , window.top.document).attr('value',path); // set new value
eMediaAttribute(this);
if(target !='')
{
$('input#' + target , window.top.document).attr('value',path); // set new value
}
eMediaAttribute(this);
// $(this).parent('#src').attr('value',preview); // set new value
// $(this).parent('#preview').attr('src',preview); // set new value
return false;
});
});
// ----------------- Upload --------------------------------------
var upath = $("#uploader").attr("rel");
$("#uploader").pluploadQueue({
// General settings
runtimes : "html5,html4",
url : upath,
max_file_size : "10mb",
chunk_size : "1mb",
unique_names : false,
// Resize images on clientside if we can
// resize : {width : 320, height : 240, quality : 90},
// Specify what files to browse for
filters : [
{title : "Image files", extensions : "jpg,gif,png,jpeg"},
{title : "Zip files", extensions : "zip,gz"}
],
preinit : {
Init: function(up, info) {
//log('[Init]', 'Info:', info, 'Features:', up.features);
}
},
init : {
FilesAdded: function(up, files) {
},
FileUploaded: function(up, file, info) { // Called when a file has finished uploading
//log('[FileUploaded] File:', file, "Info:", info);
},
UploadProgress: function(up, file) { // Called while a file is being uploaded
// console.log(up.total);
// console.log('[UploadProgress]', 'File:', file, "Total:", up.total);
},
UploadComplete: function(up, files){
document.location.reload(); // refresh the page.
},
ChunkUploaded: function(up, file, info) { // Called when a file chunk has finished uploading
//log('[ChunkUploaded] File:', file, "Info:", info);
// console.log(info);
},
Error: function(up, args) { // Called when a error has occured
alert('There was an error');
// console.log(args);
}
}
});
// -----------------------------------------------------------------
});

View File

@ -111,7 +111,7 @@ class e_bbcode
$strip_array = explode(',',$bbStrip);
if ($strip_array[0] == 'PRE')
{
$this->preProcess = TRUE;
$this->preProcess = "toDB";
unset($strip_array[0]);
if (count($strip_array) == 0)
{
@ -124,6 +124,9 @@ class e_bbcode
}
}
$pattern = '#^\[(/?)([A-Za-z_]+)(\d*)([=:]?)(.*?)]$#i'; // Pattern to split up bbcodes
// $matches[0] - same as the input text
// $matches[1] - '/' for a closing tag. Otherwise empty string
@ -352,14 +355,18 @@ class e_bbcode
if (is_object($this->bbList[$code]))
{
if ($this->preProcess)
if ($this->preProcess == 'toDB')
{
//echo "Preprocess: ".htmlspecialchars($code_text).", params: {$param1}<br />";
return $this->bbList[$code]->bbPreSave($code_text, $param1);
}
if($this->preProcess == 'toWYSIWYG')//XXX FixMe NOT working - messes with default toHTML behavior.
{
// return $this->bbList[$code]->bbWYSIWYG($code_text, $param1);
}
return $this->bbList[$code]->bbPreDisplay($code_text, $param1);
}
if ($this->preProcess) return $full_text; // No change
if ($this->preProcess == 'toDB') return $full_text; // No change
/**
* @todo - capturing output deprecated
@ -536,7 +543,13 @@ class e_bbcode
*/
function htmltoBBcode($text)
{
$text = str_replace("<!-- bbcode-html-start -->","[html]",$text);
$text = str_replace("<!-- bbcode-html-end -->","[/html]",$text);
if(substr($text,0,6)=='[html]')
{
return $text;
}
$text = preg_replace("/<a.*?href=\"(.*?)?request.php\?file=([\d]*)\".*?>(.*?)<\/a>/i","[file=$2]$3[/file]",$text);
@ -678,6 +691,23 @@ class e_bb_base
// Could add logging, security in here
return $this->toHTML($code_text, $parm);
}
/**
* Process bbcode prior to display in WYSIWYG
* Functionally this routine does exactly the same as the existing bbcodes
* Parameters passed by reference to minimise memory use
*
* @param string $code_text - text between the bbcode tags
* @param string $parm - any parameters specified for the bbcode
*
* @return string with $code_text transformed into displayable XHTML as necessary
*/
final public function bbWYSIWYG(&$code_text, &$parm)
{
// Could add logging, security in here
return $this->toWYSIWYG($code_text, $parm);
}
}
?>

View File

@ -1407,10 +1407,16 @@ class e_parse
}
break;
case 'html' :
case 'html' : // This overrides and deprecates html.bb
$proc_funcs = TRUE;
$convertNL = FALSE;
$full_text = str_replace(array("[html]","[/html]"),"",$code_text); // quick fix.. security issue?
$code_text = str_replace("\r\n", " ", $code_text);
$code_text = html_entity_decode($code_text, ENT_QUOTES, CHARSET);
$html_start = "<!-- bbcode-html-start -->"; // markers for html-to-bbcode replacement.
$html_end = "<!-- bbcode-html-end -->";
$full_text = str_replace(array("[html]","[/html]"), "",$code_text); // quick fix.. security issue?
$full_text =$this->replaceConstants($full_text,'abs');
$full_text = $html_start.$full_text.$html_end;
break;
case 'table' : // strip <br /> from end of <table>
@ -1439,7 +1445,7 @@ class e_parse
if ($className)
{
$tempCode = new $className();
$full_text = $tempCode->bbPreDisplay($matches[4], $parm);
$full_text = $tempCode->bbPreDisplay($matches[4], $parm);
}
elseif ($bbcode)
{ // Execute the file

View File

@ -20,6 +20,11 @@
*/
if (!defined('e107_INIT')) { exit; }
@set_time_limit(10 * 60);
@session_write_close();
@e107_ini_set("max_execution_time", 10 * 60);
while (@ob_end_clean()); // kill all output buffering else it eats server resources
@ob_implicit_flush(TRUE);
/*
@ -287,7 +292,7 @@ class e_file
// Grab a remote file and save it in the /temp directory. requires CURL
function getRemoteFile($remote_url, $local_file)
{
$fp = fopen(e_UPLOAD.$local_file, 'w'); // always download to temp directory.
$fp = fopen(e_MEDIA.$local_file, 'w'); // media-directory is the root.
$cp = curl_init($remote_url);
curl_setopt($cp, CURLOPT_FILE, $fp);
@ -297,7 +302,7 @@ class e_file
curl_close($cp);
fclose($fp);
return true;
return ($buffer) ? true : false;
}

View File

@ -40,7 +40,7 @@ class e_media
* Import files from specified path into media database.
* @param string $cat Category nickname
* @param string $epath path to file.
* @param string $fmask [optional] filetypes eg. .jpg|.gif
* @param string $fmask [optional] filetypes eg. .jpg|.gif IMAGES is the default mask.
* @return e_media
*/
public function import($cat='',$epath,$fmask='')

View File

@ -367,6 +367,9 @@ class xmlClass
{
return FALSE;
}
$xmlData = str_replace('content:encoded', 'content_encoded', $xmlData);
if(!$xml = simplexml_load_string($xmlData))
{
$this->errors = $this->getErrors($xmlData);
@ -388,9 +391,12 @@ class xmlClass
*/
function xml2array($xml, $rec_parent = '')
{
$ret = array();
$tags = get_object_vars($xml);
//remove comments
if($this->stripComments && isset($tags['comment']))
{
@ -465,6 +471,7 @@ class xmlClass
//more cases?
default:
$count = count($xml->{$tag});
if($count >= 1) //array of elements - loop
{
@ -596,7 +603,7 @@ class xmlClass
$vars[$vl] = array($vars[$vl]);
}
}
return $vars;
}

View File

@ -84,6 +84,7 @@ foreach($importClassList as $file)
}
unset($importClassList);
unset($fl);
asort($import_class_names);
@ -253,14 +254,14 @@ if(isset($_POST['do_conversion']))
if(dbImport() == false)
{
$abandon = true;
};
}
break;
case 'rss' :
if(rssImport() == false)
{
$abandon = true;
};
}
break;
}
@ -274,13 +275,11 @@ if(isset($_POST['do_conversion']))
{
// unset($_POST['do_conversion']);
$text = "
<form method='post' action='".e_SELF."'>
<table style='width: 98%;' class='fborder'>
<tr><td class='forumheader3' style='text-align:center'>
<input class='button' type='submit' name='dummy_continue' value='".LAN_CONTINUE."' />
</td>
</tr>
</table></form>";
<form method='get' action='".e_SELF."'>
<div class='center'>
".$frm->admin_button('dummy_continue',LAN_CONTINUE, 'execute')."
</div>
</form>";
$ns -> tablerender(LAN_CONVERT_30,$emessage->render(). $text);
require_once(e_ADMIN."footer.php");
exit;
@ -291,10 +290,14 @@ if(isset($_POST['do_conversion']))
function rssImport()
{
global $current_db_type, $db_import_blocks, $import_delete_existing_data,$db_blocks_to_import;
$mes = e107::getMessage();
$mes->addDebug("Loading: RSS");
$mes->addWarning("Under Construction");
$mes->addDebug("Loading: RSS");
if(!varset($_POST['do_conversion']))
{
$mes->addWarning("Under Construction");
}
return dbImport('xml');
}
@ -305,8 +308,6 @@ function dbImport($mode='db')
$mes = e107::getMessage();
define("RSS_IMPORT",vartrue($_POST['rss_feed'],false));
// if (IMPORT_DEBUG) echo "Importing: {$current_db_type}<br />";
$mes->addDebug("Loading: ".$current_db_type);
@ -314,6 +315,7 @@ function dbImport($mode='db')
{
$mes->addDebug("Class Available: ".$current_db_type);
$converter = new $current_db_type;
$converter->init();
}
else
{
@ -420,9 +422,9 @@ function dbImport($mode='db')
if(varset($_POST['import_type']) || varset($_POST['do_conversion']))
if(varset($_GET['import_type']) || varset($_POST['do_conversion']))
{
showImportOptions($_POST['import_type']);
showImportOptions($_GET['import_type']);
}
else
{
@ -443,7 +445,7 @@ function showStartPage()
global $ns, $emessage, $frm, $import_class_names, $import_class_support, $db_import_blocks, $import_class_comment;
$text = "
<form method='post' action='".e_SELF."' id='core-import-form'>
<form method='get' action='".e_SELF."' id='core-import-form'>
<fieldset id='core-import-select-type'>
<legend class='e-hideme'>".'DBLAN_10'."</legend>
<table class='adminlist'>
@ -521,7 +523,18 @@ function showStartPage()
function showImportOptions($mode='csv')
{
global $text, $frm, $ns, $emessage, $csv_names, $import_class_names, $e_userclass, $db_import_blocks, $import_class_support, $import_default_prefix;
global $text, $emessage, $csv_names, $import_class_names, $e_userclass, $db_import_blocks, $import_class_support, $import_default_prefix;
$frm = e107::getForm();
$ns = e107::getRender();
$mes = e107::getMessage();
if (class_exists($mode))
{
$mes->addDebug("Class Available: ".$mode);
$proObj = new $mode;
}
$message = LAN_CONVERT_02."<br /><strong>".LAN_CONVERT_05."</strong>";
$emessage->add($message, E_MESSAGE_WARNING);
@ -565,14 +578,24 @@ function showImportOptions($mode='csv')
";
}
elseif($mode == 'rss_import')
elseif(method_exists($proObj,"config"))
{
$text .= "<tr>
<td>Feed URL</td>
<td><input class='tbox' type='text' name='rss_feed' size='80' value='{$_POST['rss_feed']}' maxlength='250' />
<input type='hidden' name='import_source' value='rss' />
</td>
</tr>";
$ops = $proObj->config();
foreach($ops as $key=>$val)
{
$text .= "<tr>
<td>".$val['caption']."</td>
<td>".$val['html'];
$text .= (vartrue($val['help'])) ? "<div class='field-help'>".$val['help']."</div>" : "";
$text .= "</td>
</tr>\n";
}
if($proObj->sourceType)
{
$text .= "<input type='hidden' name='import_source' value='".$proObj->sourceType."' />\n";
}
}
else
{
@ -634,7 +657,9 @@ function showImportOptions($mode='csv')
$text .= $e_userclass->vetted_tree('classes_select',array($e_userclass,'checkbox'), $checked_class_list,'main,admin,classes,matchclass');
$text .= "</td></tr></table>
<div class='buttons-bar center'>".$frm->admin_button('do_conversion',LAN_CONTINUE, 'execute')."
<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='$mode' />
<input type='hidden' name='import_type' value='".$mode."' />
</div>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -158,7 +158,13 @@ class base_import_class
// Empty functions which descendants can inherit from
function init()
{
return;
}
function copyUserData(&$target, &$source)
{
return $target;

View File

@ -0,0 +1,112 @@
<?php
/*
* e107 website system
*
* Copyright (C) 2008-2009 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 $
*/
// This must be an incredibly pointless file! But it does allow testing of the basic plugin structure.
// Each import file has an identifier which must be the same for:
// a) This file name - add '_class.php' to get the file name
// b) The array index of certain variables
// Array element key defines the function prefix and the class name; value is displayed in drop-down selection box
// require_once('import_classes.php');
require_once('rss_import_class.php');
$import_class_names['blogger_import'] = 'Blogger';
$import_class_comment['blogger_import'] = 'Import up to 500 items from yourblog.blogspot.com';
$import_class_support['blogger_import'] = array('news');
$import_default_prefix['blogger_import'] = '';
class blogger_import extends rss_import
{
var $cleanupHtml = false;
/*
If the first 500 posts of your blog feed are here:
http://YOURBLOG.blogspot.com/feeds/posts/default?max-results=999
the second 500 posts are here:
http://YOURBLOG.blogspot.com/feeds/posts/default?max-results=999&start-index=501
*/
function init()
{
$mes = e107::getMessage();
if(vartrue($_POST['bloggerUrl']))
{
$this->feedUrl = rtrim($_POST['bloggerUrl'],"/")."/feeds/posts/default?max-results=999&alt=rss";
}
if(vartrue($_POST['bloggerCleanup']))
{
$this->cleanupHtml = true;
}
$mes->addDebug("Blogger Feed:".$this->feedUrl);
}
function config()
{
$var[0]['caption'] = "Blogger URL";
$var[0]['html'] = "<input class='tbox' type='text' name='bloggerUrl' size='80' value='{$_POST['bloggerUrl']}' maxlength='250' />";
$var[0]['help'] = "eg. http://blogname.blogspot.com";
$var[1]['caption'] = "Cleanup HTML in content";
$var[1]['html'] = "<input class='tbox' type='checkbox' name='bloggerCleanup' 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:
//http://blogname.blogspot.com/feeds/comments/default?alt=rss
}
?>

View File

@ -30,6 +30,23 @@ require_once('import_classes.php');
class rss_import extends base_import_class
{
var $sourceType = 'rss';
var $feedUrl = null;
function init()
{
$this->feedUrl = vartrue($_POST['rss_feed'],false);
}
function config()
{
$var[0]['caption'] = "Feed URL";
$var[0]['html'] = "<input class='tbox' type='text' name='rss_feed' size='80' value='{$_POST['rss_feed']}' maxlength='250' />";
return $var;
}
// Set up a query for the specified task.
// Returns TRUE on success. FALSE on error
function setupQuery($task, $blank_user=FALSE)
@ -37,32 +54,36 @@ class rss_import extends base_import_class
$this->arrayData = array();
$xml = e107::getXml();
$file = RSS_IMPORT;
$file = $this->feedUrl;
switch ($task)
{
case 'news' :
case 'page' :
case 'links' :
// $rawData = $xml->getRemoteFile($file);
// print_a($rawData);
$array = $xml->loadXMLfile($file,'advanced');
if ($array === FALSE || RSS_IMPORT === FALSE) return FALSE;
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;
$this->copyUserInfo = !$blank_user;
$this->currentTask = $task;
return TRUE;
}
@ -81,18 +102,45 @@ class rss_import extends base_import_class
}
/**
* Align source data to e107 News Table
* Align source data with e107 News Table
* @param $target array - default e107 target values for e107_news table.
* @param $source array - WordPress table data
*/
function copyNewsData(&$target, &$source)
{
$target['news_title'] = $source['title'][0];
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]".$source['description'][0]."[/html]";
$target['news_body'] = "[html]".$body."[/html]";
// $target['news_extended'] = '';
// $target['news_meta_keywords'] = '';
$target['news_meta_keywords'] = implode(",",$keywords);
// $target['news_meta_description'] = '';
$target['news_datestamp'] = strtotime($source['pubDate'][0]);
// $target['news_author'] = $source['post_author'];
@ -107,14 +155,52 @@ class rss_import extends base_import_class
// $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
@ -123,11 +209,11 @@ class rss_import extends base_import_class
*/
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]".$source['description'][0]."[/html]";
$target['page_text'] = "[html]".$body."[/html]";
// $target['page_metakeys'] = '';
// $target['page_metadscr'] = '';
$target['page_datestamp'] = strtotime($source['pubDate'][0]);
@ -165,17 +251,61 @@ class rss_import extends base_import_class
// $target['link_class'] = '';
// $target['link_sefurl'] = $source['post_password'];
return $target; // comment out to debug
$this->renderDebug($source,$target);
}
//TODO Option to save remote images locally and replace urlss in news_body with local ones. eg. {e_MEDIA}
function saveBodyFiles($body)
/** 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);
}

View File

@ -17,7 +17,7 @@ if($_POST['mode'] == 'tohtml')
{
$content = $tp->toDB($_POST['content']);
e107::getBB()->setClass($_SESSION['media_category']);
echo $tp->toHtml($content,true);
echo $tp->toHtml($content, true, 'wysiwyg');
e107::getBB()->clearClass();
}