mirror of
https://github.com/e107inc/e107.git
synced 2025-07-31 03:40:37 +02:00
Blogger import improvements and news_title and news_body field size limitations removed. (DB Update Required)
This commit is contained in:
@@ -300,9 +300,9 @@ CREATE TABLE menus (
|
||||
|
||||
CREATE TABLE news (
|
||||
news_id int(10) unsigned NOT NULL auto_increment,
|
||||
news_title varchar(200) NOT NULL default '',
|
||||
news_title varchar(255) NOT NULL default '',
|
||||
news_sef varchar(200) NOT NULL default '',
|
||||
news_body text NOT NULL,
|
||||
news_body longtext NOT NULL,
|
||||
news_extended text NOT NULL,
|
||||
news_meta_keywords varchar(255) NOT NULL default '',
|
||||
news_meta_description text NOT NULL,
|
||||
|
@@ -26,10 +26,6 @@
|
||||
// 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
|
||||
{
|
||||
@@ -40,9 +36,7 @@ class blogger_import extends rss_import
|
||||
|
||||
public $cleanupHtml = false;
|
||||
public $defaultClass = false;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
If the first 500 posts of your blog feed are here:
|
||||
@@ -56,7 +50,13 @@ class blogger_import extends rss_import
|
||||
function init()
|
||||
{
|
||||
$mes = e107::getMessage();
|
||||
|
||||
|
||||
if(E107_DEBUG_LEVEL > 0)
|
||||
{
|
||||
$this->action = 'preview'; // changes default action to 'preview' method below. (for testing)
|
||||
}
|
||||
|
||||
|
||||
if(vartrue($_POST['bloggerUrl']))
|
||||
{
|
||||
$this->feedUrl = rtrim($_POST['bloggerUrl'],"/")."/feeds/posts/default?max-results=999&alt=rss";
|
||||
@@ -65,20 +65,26 @@ class blogger_import extends rss_import
|
||||
if(vartrue($_POST['bloggerCleanup']))
|
||||
{
|
||||
$this->cleanupHtml = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$mes->addDebug("Blogger Feed:".$this->feedUrl);
|
||||
|
||||
if(!empty($_POST['preview']))
|
||||
{
|
||||
$this->preview();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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]['html'] = e107::getForm()->text('bloggerUrl', $_POST['bloggerUrl'],255, 'size=xxlarge'); // "<input class='tbox' type='text' name='bloggerUrl' size='120' 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]['html'] = e107::getForm()->checkbox('bloggerCleanup',1, $_POST['bloggerCleanup']); // "<input class='tbox' type='checkbox' name='bloggerCleanup' value='1' />";
|
||||
$var[1]['help'] = "Tick to enable";
|
||||
|
||||
return $var;
|
||||
@@ -86,16 +92,55 @@ class blogger_import extends rss_import
|
||||
|
||||
function process($type,$source)
|
||||
{
|
||||
|
||||
|
||||
$tp = e107::getParser();
|
||||
|
||||
$allowedTags = array('html', 'body', 'a','img','table','tr', 'td', 'th', 'tbody', 'thead', 'colgroup', 'b',
|
||||
'i', 'pre','code', 'strong', 'u', 'em','ul', 'ol', 'li','img','h1','h2','h3','h4','h5','h6','p','iframe',
|
||||
'div','pre','section','article', 'blockquote','hgroup','aside','figure', 'video', 'span', 'br',
|
||||
'small', 'caption', 'noscript'
|
||||
);
|
||||
|
||||
$allowedAttributes = array(
|
||||
'default' => array('id'),
|
||||
'img' => array('id', 'src', 'style', 'class', 'alt', 'title', 'width', 'height'),
|
||||
'a' => array('id', 'href', 'class', 'title', 'target'),
|
||||
'script' => array('type', 'src', 'language'),
|
||||
'iframe' => array('id', 'src', 'frameborder', 'class', 'width', 'height', 'style')
|
||||
);
|
||||
|
||||
$tp->setAllowedTags($allowedTags);
|
||||
$tp->setAllowedAttributes($allowedAttributes);
|
||||
|
||||
switch ($type)
|
||||
{
|
||||
case 'description':
|
||||
$body = $source[$type][0];
|
||||
if($this->cleanupHtml == TRUE)
|
||||
|
||||
if($this->cleanupHtml == true)
|
||||
{
|
||||
$body = preg_replace("/font-family: [\w]*;/i","", $body);
|
||||
$body = preg_replace('/class="[\w]*" /i',"", $body);
|
||||
// $body = preg_replace("/font-family: [\w]*;/i","", $body);
|
||||
// $body = preg_replace('/class="[\w]*" /i',"", $body);
|
||||
$body = str_replace("<br>","<br />",$body);
|
||||
|
||||
$body = $tp->cleanHtml($body,false);
|
||||
|
||||
$patterns = array();
|
||||
$patterns[0] = '/<div[^>]*>/';
|
||||
$patterns[1] = '/<\/div>/';
|
||||
|
||||
$replacements = array();
|
||||
$replacements[2] = '';
|
||||
$replacements[1] = '';
|
||||
|
||||
$body = preg_replace($patterns, $replacements, $body);
|
||||
|
||||
$srch = array('<span>', '</span>', '<br /><br /><br /><br />');
|
||||
$repl = array("", "", "<br /><br />");
|
||||
|
||||
$body = str_replace($srch, $repl, $body);
|
||||
|
||||
|
||||
return $body;
|
||||
}
|
||||
else
|
||||
@@ -103,6 +148,16 @@ class blogger_import extends rss_import
|
||||
return $body;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'sef':
|
||||
|
||||
if(!empty($source['link'][0]))
|
||||
{
|
||||
return str_replace(".html","", basename($source['link'][0]));
|
||||
}
|
||||
|
||||
return "";
|
||||
break;
|
||||
|
||||
default:
|
||||
return $source[$type][0];
|
||||
@@ -112,6 +167,28 @@ class blogger_import extends rss_import
|
||||
|
||||
}
|
||||
|
||||
|
||||
function preview()
|
||||
{
|
||||
$file = $this->feedUrl;
|
||||
$array = e107::getXml()->loadXMLfile($file,'advanced');
|
||||
|
||||
// print_a($array); // raw xml data;
|
||||
|
||||
|
||||
foreach($array['channel']['item'] as $src)
|
||||
{
|
||||
// $data = $this->process('description', $src);
|
||||
// $this->process('sef',$src);
|
||||
$data = $this->copyNewsData($target,$src);
|
||||
print_a($data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//TODO Comment Import:
|
||||
//http://blogname.blogspot.com/feeds/comments/default?alt=rss
|
||||
|
||||
|
@@ -149,6 +149,7 @@ class rss_import extends base_import_class
|
||||
|
||||
$body = $this->saveImages($body,'news');
|
||||
$keywords = $this->process('category',$source);
|
||||
$sef = $this->process('sef',$source);
|
||||
|
||||
if(!vartrue($source['title'][0]))
|
||||
{
|
||||
@@ -165,7 +166,7 @@ class rss_import extends base_import_class
|
||||
}
|
||||
|
||||
$target['news_title'] = $title;
|
||||
// $target['news_sef'] = $source['post_name'];
|
||||
$target['news_sef'] = $sef;
|
||||
$target['news_body'] = "[html]".$body."[/html]";
|
||||
// $target['news_extended'] = '';
|
||||
$target['news_meta_keywords'] = implode(",",$keywords);
|
||||
@@ -223,6 +224,10 @@ class rss_import extends base_import_class
|
||||
return $keywords;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'sef':
|
||||
return '';
|
||||
break;
|
||||
|
||||
default:
|
||||
return varset($source[$type][0]);
|
||||
|
Reference in New Issue
Block a user