1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-22 22:25:31 +02: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

@@ -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);
}