bla-bla-bla
Зарегистрирован:
08 мая 2010, 22:11
|
[spoiler=Спойлер:11s4hap8] <?php
/*
=====================================================
Файл: dz_import.php
-----------------------------------------------------
Назначение: Импорт контента с программы Зеброид (http://zebroid.ru)
=====================================================
*/
define ( 'DATALIFEENGINE', true );
define(ZI_ERROR, 'zebroid_import_error!');
/*echoheader("user",$lang['opt_priv']);
echo <<<HTML
<div style="padding-top:5px;padding-bottom:2px;">
<table width="100%">
<tr>
<td width="4"><img src="engine/skins/images/tl_lo.gif" width="4" height="4" border="0"></td>
<td background="engine/skins/images/tl_oo.gif"><img src="engine/skins/images/tl_oo.gif" width="1" height="4" border="0"></td>
<td width="6"><img src="engine/skins/images/tl_ro.gif" width="6" height="4" border="0"></td>
</tr>
<tr>
<td background="engine/skins/images/tl_lb.gif"><img src="engine/skins/images/tl_lb.gif" width="4" height="1" border="0"></td>
<td style="padding:5px;" bgcolor="#FFFFFF">
<table width="100%">
<tr style='' id="general"><td>
<table width="100%">
<tr>
<td bgcolor="#EFEFEF" height="29" style="padding-left:10px;"><div class="navigation">Импорт файла в формате DXR</div></td>
</tr>
</table>
<div class="unterline"></div>
<!--Форма импорта-->
<form method="post" enctype="multipart/form-data">
<p>Автор: <input name="autor" type="text" size="30"></p>
<p>Файл: <input type="file" name="dz_file"></p>
<p><input type="submit" class="buttons" value=" Начать импорт "></p>
</form>
HTML;*/
function get_all_cats(){
global $db;
$sql_result = $db->query( "SELECT id, alt_name FROM " . PREFIX . "_category" );
while ($row = $db->get_row($sql_result)) $result [ $row['alt_name'] ] = $row['id'];
return $result;
}
function get_terms($from, $field, $where=''){
global $db;
if (!$where) $sql_result = $db->query( "SELECT $field FROM " . PREFIX . "_$from" );
else $sql_result = $db->query( "SELECT $field FROM " . PREFIX . "_$from WHERE $where" );
while ($row = $db->get_row($sql_result)) $result [] = $row[$field];
return $result;
}
function dle_insert_post($postdata, $tags, $autor){
//$postdata = array('post_title', 'post_alt_name', 'post_cats', 'post_short_story', 'post_full_story', 'post_description', 'post_date', 'post_keywords', 'post_tags');
global $db, $parse;
$postdata['post_full_story'] = $db->safesql ($parse->BB_Parse( $postdata['post_full_story'], false ));
$postdata['post_short_story'] = $db->safesql ($parse->BB_Parse( $postdata['post_short_story'], false ));
$postdata['post_description'] = $db->safesql ($parse->BB_Parse( $postdata['post_description'], false ));
$postdata['post_title'] = $db->safesql ($parse->BB_Parse( $postdata['post_title'], false ));
$postdata['post_keywords'] = $db->safesql ($parse->BB_Parse( $postdata['post_keywords'], false ));
$postdata['post_tags'] = $db->safesql ($parse->BB_Parse( $postdata['post_tags'], false ));
if (strlen($postdata['post_title'])>0) $symbol = strtolower($postdata['post_title'][0]); else $symbol = '';
$db->query( "INSERT INTO " . PREFIX . "_post (autor, date, short_story, full_story, title, descr, keywords, category, alt_name, tags, approve, xfields, allow_main, symbol) values ('".
$autor."', '".$postdata['post_date']."', '".$postdata['post_short_story']."', '".$postdata['post_full_story']."', '".
$postdata['post_title']."', '".$postdata['post_description']."', '".$postdata['post_keywords']."', '".$postdata['post_cats']."', '".
$postdata['post_alt_name']."', '".$postdata['post_tags']."', 1, '', 1, '". $symbol ."')" );
$post_id = $db->insert_id();
foreach ($tags as $tag) {
$ins_tag = $db->safesql ($parse->BB_Parse( $tag, false ));
$db->query( "INSERT INTO " . PREFIX . "_tags (news_id, tag) values (".$post_id.", '".$ins_tag."')" );
}
}
function dle_insert_category($catarr){
global $db;
$catarr['cat_name'] = $db->safesql($catarr['cat_name']);
$db->query( "INSERT INTO " . PREFIX . "_category (name, alt_name, parentid, posi, keywords) values ('".$catarr['cat_name']."', '".$catarr['category_nicename']."', ".$catarr['parentid'].", 1, '')" );
//Очищаем кэшь категорий
@unlink(ENGINE_DIR.'/cache/system/category.php');
$cat_id = $db->insert_id();
return $cat_id;
}
class DZ_Import {
var $file;
var $author;
var $home_url;
var $cats_list = array ();
var $categories = array ();
function get_tag( $string, $tag ) {
preg_match("|<($tag).*?>(.*?)</$tag>|is", $string, $return);
if ($return[1] == '') return ZI_ERROR;
$return = preg_replace('|^<!\[CDATA\[(.*)\]\]>$|s', '$1', $return[2]);
return $return;
}
function get_entries($process_post_func=NULL) {
set_magic_quotes_runtime(0);
$doing_entry = false;
$is_dxr_file = false;
$fp = fopen($this->file, 'r');
if ($fp) {
while ( !feof($fp) ) {
$importline = rtrim(fgets($fp));
// this doesn't check that the file is perfectly valid but will at least confirm that it's not the wrong format altogether
if ( !$is_dxr_file && preg_match('|xmlns:dle="http://zebroid[.]ru/"|', $importline) )
$is_dxr_file = true;
if ( false !== strpos($importline, '<dle:category>') ) {
preg_match('|<dle:category>(.*?)</dle:category>|is', $importline, $category);
$this->cats_list[] = $category[1];
continue;
}
if ( false !== strpos($importline, '<item>') ) {
$this->post = '';
$doing_entry = true;
continue;
}
if ( false !== strpos($importline, '</item>') ) {
$doing_entry = false;
if ($process_post_func)
call_user_func($process_post_func, $this->post);
continue;
}
if ( $doing_entry ) {
$this->post .= $importline . "\n";
}
}
fclose($fp);
}
return $is_dxr_file;
}
function import_file($file) {
//Записываем имя файла
$this->file = $file;
//Получаем список категорий с файла
if (!($this->get_entries())) {echo "Не верный формат файла";
} else {
//Обрабатываем этот список
$this->process_categories();
//Получаем и обрабатываем посты
$result = $this->process_posts();
}
}
function process_categories() {
//Получть имена всех категорий
$cat_names = (array) get_all_cats();
//Добавляем категории что необходимы
while ( $c = array_shift($this->cats_list) ) {
$cat_name = trim($this->get_tag( $c, 'dle:cat_name' ));
$category_nicename = $this->get_tag( $c, 'dle:category_nicename' );
$parent = $this->get_tag( $c, 'dle:category_parent' );
// Если категория уже есть, то пропускаем
if ( isset($cat_names[$category_nicename])) {
$this -> categories [$category_nicename] = $cat_names[$category_nicename];
continue;
}
//Определяем id родительской категории
if ( empty($parent) )
$parentid = '0';
else {
//echo $parent.' - ';
$parentid = $this -> categories [$parent];
//echo '"'.$parentid.'"';
}
//Добавляем категорию в БД
$catarr = compact('cat_name', 'category_nicename', 'parentid');
$cat_ID = dle_insert_category($catarr);
//Заносим категорию в массив
$this -> categories [$category_nicename] = $cat_ID;
}
}
function process_posts() {
echo '<ol>';
$this->get_entries(array(&$this, 'process_post'));
echo '</ol>';
echo '<h3>'.sprintf('<div style="text-align:center;">Вот и всё.'.' <a href="%s">'.'Посмотреть на сайт!'.'</a>', $this -> home_url).'</div></h3>';
}
function process_post($post) {
set_time_limit( 60 );
//Вытягаем данные
$post_title = $this->get_tag( $post, 'title' );
$post_alt_name = $this->get_tag( $post, 'alt_name' );
$post_date = $this->get_tag( $post, 'date' );
$post_keywords = $this->get_tag( $post, 'keywords' );
$post_full_story = $this->get_tag( $post, 'full_story' );
$post_full_story = preg_replace_callback('|<(/?[A-Z]+)|', create_function('$match', 'return "<" . strtolower($match[1]);'), $post_full_story);
$post_full_story = str_replace('<br>', '<br />', $post_full_story);
$post_full_story = str_replace('<hr>', '<hr />', $post_full_story);
$post_short_story = $this->get_tag( $post, 'short_story' );
$post_short_story = preg_replace_callback('|<(/?[A-Z]+)|', create_function('$match', 'return "<" . strtolower($match[1]);'), $post_short_story);
$post_description = $this->get_tag( $post, 'description' );
$post_description = preg_replace_callback('|<(/?[A-Z]+)|', create_function('$match', 'return "<" . strtolower($match[1]);'), $post_description);
//Достаем таги
preg_match_all('|<tag>(.*?)</tag>|is', $post, $tags);
$tags = $tags[1];
//Получаем список тагов
$post_tags = '';
$tag_index = 0;
foreach ($tags as $tag) {
$tags[$tag_index] = $tag;
$tag_index++;
$post_tags .= $tag.',';
}
$post_tags = substr($post_tags, 0, -1);
//Достаем категории
preg_match_all('|<category>(.*?)</category>|is', $post, $post_categories);
$post_categories = $post_categories[1];
//Получаем список категорий
$post_cats = '';
foreach ($post_categories as $category) {
$post_categories[$cat_index] = $category;
$post_cats .= $this -> categories[$category].',';
}
$post_cats = substr($post_cats, 0, -1);
//Проверяем нет ли такого поста
$post_exists = get_terms("post","id","alt_name='".$post_alt_name."'");
if ($post_full_story == ZI_ERROR) { //Слишком длинная фулл стори
echo '<li>';
printf('Добавляю статью <em>%s</em> - <font color="red"><b>слишком длинная статья (максимум 65535 символов)</b></font>.', stripslashes($post_title));
}
elseif ( $post_exists ) { //Если пост уже существует
echo '<li>';
printf('Добавляю статью <em>%s</em> - <font color="red"><b>уже существует</b></font>.', stripslashes($post_title));
} else {
//Иначе добавляем его
echo '<li>';
$postdata = compact('post_title', 'post_alt_name', 'post_cats', 'post_short_story', 'post_full_story', 'post_description', 'post_date', 'post_keywords', 'post_tags');
printf('Добавляю статью <em>%s</em>...', stripslashes($post_title));
//Добавляем в БД пост и таги
dle_insert_post($postdata, $tags, $this -> author);
echo ' - <font color="green"><b>добавлено</b></font>';
}
print "</li>\n";
flush();
}
function WP_Import() {
// Ничего :)
}
}
/*if (!( $_REQUEST['autor'] )) $error = "Не указан автор; ";
if (!$_FILES["dz_file"]["tmp_name"]) $error .= 'Не выбран файл';
if ((!$error) AND (strtolower($_SERVER['REQUEST_METHOD']) == 'post')) { */
if (isset ( $_REQUEST['doaction'] )) $doaction = $_REQUEST['doaction']; else $doaction = "";
$dz_import = new DZ_Import();
include_once $_SERVER['DOCUMENT_ROOT'].'/'.engine.'/classes/parse.class.php';
$parse = new ParseFilter( );
$dz_import -> author = 'admin';
$dz_import -> home_url = $config['http_home_url'];
$dz_import -> import_file($_SERVER['DOCUMENT_ROOT'].'/data.xml');
unset($parse);
unset($dz_import);
//Очищаем кэш
clear_cache();
/*} else {
if ((strtolower($_SERVER['REQUEST_METHOD']) == 'post')) echo '<div style="color:red; text-align:center;"><b>Ошибка</b>: '.$error.'</div>';
}*/
/*echo <<<HTML
</table>
</td>
<td background="engine/skins/images/tl_rb.gif"><img src="engine/skins/images/tl_rb.gif" width="6" height="1" border="0"></td>
</tr>
<tr>
<td><img src="engine/skins/images/tl_lu.gif" width="4" height="6" border="0"></td>
<td background="engine/skins/images/tl_ub.gif"><img src="engine/skins/images/tl_ub.gif" width="1" height="6" border="0"></td>
<td><img src="engine/skins/images/tl_ru.gif" width="6" height="6" border="0"></td>
</tr>
</table>
</form>
HTML;
echofooter();*/
?> [/spoiler:11s4hap8]
сделал как сказал, ошибка появилась
Fatal error: Call to a member function query() on a non-object in Z:\home\dle.ua\www\engine\inc\dz_import.php on line 46
запускаю как http://dle.ua/engine/inc/dz_import.php
|