Subversion-Projekte lars-tiefland.content-management

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * XML_Serializer
4
 *
5
 * Creates XML documents from PHP data structures like arrays, objects or scalars.
6
 *
7
 * PHP versions 4 and 5
8
 *
9
 * LICENSE: This source file is subject to version 3.0 of the PHP license
10
 * that is available through the world-wide-web at the following URI:
11
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
12
 * the PHP License and are unable to obtain it through the web, please
13
 * send a note to license@php.net so we can mail you a copy immediately.
14
 *
15
 * @category   XML
16
 * @package    ImmoScout24Export
17
 * @author     Markus Niewerth <markus@weban.de>
18
 * @copyright  1997-2007 The PHP Group
19
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
20
 * @version    CVS: $Id: ImmoScout24Export.php,v 1.0 2007/09/27 9:45:30 markusniewerth Exp $
21
 * @link       http://pear.php.net/package/XML_Serializer
22
 * @see        XML_Unserializer
23
 */
24
 
25
require_once 'PEAR.php';
26
 
27
/**
28
 * XML_DTD_XmlValidator
29
 *
30
 * Usage:
31
 *
32
 * <code>
33
 * $validator = XML_DTD_XmlValidator;
34
 * // This will check if the xml is well formed
35
 * // and will validate it against its DTD
36
 * if (!$validator->isValid($dtd_file, $xml_file)) {
37
 *   die($validator->getMessage());
38
 * }
39
 * </code>
40
 *
41
 * @package XML_DTD
42
 * @category XML
43
 * @author Tomas V.V.Cox <cox@idecnet.com>
44
 * @copyright Copyright (c) 2003
45
 * @version $Id: XmlValidator.php,v 1.5 2004/05/17 19:51:45 schst Exp $
46
 * @access public
47
*/
48
 
49
/**
50
 * Creates XML documents from PHP data structures like arrays, objects or scalars.
51
 *
52
 *
53
 * @category   XML
54
 * @package    ImmoScout24Export
55
 * @author     Markus Niewerth <markus@weban.de>
56
 * @copyright  1997-2007 The PHP Group
57
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
58
 * @version    CVS: $Id: ImmoScout24Export.php,v 1.0 2007/09/27 9:45:30 markusniewerth Exp $
59
 * @link       http://pear.php.net/package/XML_Serializer
60
 * @see        XML_Unserializer
61
 */
62
 
63
 
64
/**#@+
65
 * Error constants
66
 */
67
/**
68
 * Close XML parsed tags
69
 */
70
define('IMMOSCOUT24EXPORT_CLOSE_TAGS_AFTER', 0);
71
/**
72
 * Parameter declared to be numeric but the values are not
73
 */
74
define('IMMOSCOUT24EXPORT_CLOSE_TAGS_DIRECT', 1);
75
/**
76
 * Communication error
77
 */
78
define('IMMOSCOUT24EXPORT_CLOSE_TAGS_INTAG', 2);
79
/**#@-*/
80
 
81
 
82
 
83
class ImmoScout24Export extends PEAR {
84
 
85
	// the XML String
86
	var $XMLString;
87
 
88
	// To close all elements
89
	var $closeStack;
90
 
91
	// Last file path
92
	var $tempPath;
93
 
94
	// Last path where the file was put into it
95
	var $dirName;
96
 
97
	// enable debbuging in some cases?
98
	var $debugMode;
99
 
100
	var $_ftpConnection;
101
 
102
	var $_loginResult;
103
 
104
 	var $dtdFile;
105
 
106
	/**
107
	 * Constructor
108
	 *
109
	 * @param string $database
110
	 * @return ImmoScout24Export
111
	 */
112
 
113
	function ImmoScout24Export
114
	(
115
		$database='gwg_gladbeck_de',
116
		$debugMode=true,
117
		$dtdFile='http://www.gwg-gladbeck.de/XML/xsi/is24immotransfer.xsd'
118
	) {
119
		// Datenbankverbindung initialisieren
120
		// require_once "/web/apache/content-management/Online-Shop/connect2.php";
121
 
122
		// Init properties
123
		$this->XMLString	=	null;
124
		$this->closeStack	=	array();
125
		$this->debugMode	=	$debugMode;
126
		$this->dtdFile		=	$dtdFile;
127
	}
128
 
129
	/**
130
	 * Returns the current API Version
131
	 *
132
	 * @return string
133
	 */
134
 
135
	function apiVersion() {
136
		return '1.0';
137
	}
138
 
139
   /**
140
    * Build an xml declaration
141
    *
142
    * <code>
143
    * require_once 'ImmoScout24Export.php';
144
    *
145
    * // get an XML declaration:
146
    * $xmlDecl = ImmoScout24Export::getXMLDeclaration("1.0", "UTF-8", true);
147
    * </code>
148
    *
149
    * @access   public
150
    * @static
151
    * @param    string  $version     xml version
152
    * @param    string  $encoding    character encoding
153
    * @param    boolean $standAlone  document is standalone (or not)
154
    * @return   string  $decl xml declaration
155
    * @uses     ImmoScout24Export::attributesToString() to serialize the attributes of the XML declaration
156
    */
157
    function getXMLDeclaration($version = "1.0", $encoding = null, $standalone = null)
158
    {
159
        $attributes = array (
160
        	"version" => $version,
161
        );
162
        // add encoding
163
        if ($encoding !== null) {
164
            $attributes["encoding"] = $encoding;
165
        }
166
        // add standalone, if specified
167
        if ($standalone !== null) {
168
            $attributes["standalone"] = $standalone ? "yes" : "no";
169
        }
170
 
171
        return sprintf("<?xml%s?>", ImmoScout24Export::attributesToString($attributes));
172
    }
173
	/**
174
	 * Creates elements from attributes array
175
	 *
176
	 * @param array $attributes
177
	 * @return string
178
	 */
179
    function attributesToString($attributes=array()) {
180
    	if (sizeof($attributes)<1) {
181
    		return "";
182
    	}
183
    	$return = " ";
184
    	foreach (array_keys($attributes) AS $element) {
185
    		$return .= $element . "=\"".$attributes[$element]."\" ";
186
    	}
187
    	return $return;
188
    }
189
 
190
    /**
191
     * Parse an array with elements and attributes
192
     * NOTE: Only usable if constructed!
193
     *
194
     * @param array $data
195
     * @return string
196
     */
197
	function parse2XML($data) {
198
		$string=null;
199
		$this->XMLString=null;
200
		foreach (array_keys($data) AS $root) {
201
			if (is_array($data[$root])) {
202
 
203
				$string .= "<".$root." \r\n";
204
				foreach (array_keys($data[$root]) AS $child){
205
					if ($child != 'close' && $child != 'Contents') {
206
						$string .= "\t".$child."=\"".utf8_decode($data[$root][$child])."\" \r\n";
207
					}
208
				}
209
 
210
				switch($data[$root]['close'])
211
				{
212
					case IMMOSCOUT24EXPORT_CLOSE_TAGS_INTAG:
213
						$string .= "/>\r\n";
214
						break;
215
					case  IMMOSCOUT24EXPORT_CLOSE_TAGS_NESTED:
216
						$this->closeStack[] = $root;
217
						$string .= ">\r\n";
218
						break;
219
					case  IMMOSCOUT24EXPORT_CLOSE_TAGS_NORMAL:
220
						$string .= ">\r\n".$data[$root]['Contents']."\r\n";
221
						$string .= "</$root>\r\n";
222
						break;
223
				}
224
			}
225
		}
226
		$this->closeStack = array_reverse($this->closeStack, TRUE);
227
		foreach ($this->closeStack AS $closer) {
228
			$string .= "</$closer>\r\n";
229
		}
230
		// reffer to $string
231
		$this->XMLString = &$string;
232
		return $this->XMLString;
233
	}
234
 
235
	function XMLSave($fileName='ImmoScout24Export.xml' , $path='./') {
236
		if ($this->XMLString==null) {
237
			return false;
238
		} else {
239
			$XMLDeclaration = ImmoScout24Export::getXMLDeclaration("1.0", 'UTF-8');
240
			$this->XMLString = $XMLDeclaration."\r\n".$this->XMLString;
241
			// create a tempFile
242
			$tmpFileName = tempnam ("/tmp", "XMLTMP");
243
			// open it for reading
244
			$myHandle 	 = fopen($tmpFileName, "w+");
245
			// write contents to
246
			fwrite($myHandle, $this->XMLString);
247
			// then close the handle
248
			fclose($myHandle);
249
			// define a prefix/suffix
250
			$dateTime = date ("Y.M.D.h.s.i_");
251
			// log the filename
252
			$this->tmpPath = $path . $dateTime . $fileName;
253
 
254
			// Validate the XML File
255
			// This will check if the xml is well formed
256
			// and will validate it against its DTD
257
 
258
			if (!MyValidator::validate($tmpFileName,$this->dtdFile)) {
259
				print( $this->debugMode ? '<pre>'.nl2br(htmlentities($validator->getMessage())) . '<br />'. htmlentities(file_get_contents($tmpFileName)). '</pre>' : '');
260
				return false;
261
			}
262
 
263
			// and copy it to the given path
264
			if (!copy($tmpFileName, $this->tmpPath)) {
265
				$copyFalse = true;
266
			}
267
			// delete the tempFile
268
			unlink($tmpFileName);
269
 
270
			if ($copyFalse)
271
				return false;
272
		}
273
		// debug question
274
		if ($this->debugMode)
275
			return $this->XMLString;
276
		else
277
			return true;
278
	}
279
 
280
	function ftp($username=null,$password=null,$hostname=null, $option='open', $destFile=null) {
281
 
282
		switch ($option) {
283
			case 'open':
284
				$this->_ftpConnection = ftp_connect($hostname);
285
				// Login with username und password
286
				$this->_loginResult = ftp_login($this->_ftpConnection, $username, $password);
287
				break;
288
			case 'close':
289
				if (is_resource($this->_ftpConnection))
290
					ftp_close($this->_ftpConnection);
291
				return true;
292
				break;
293
			case 'put':
294
				// Datei hochladen
295
				$uploadStatus = ftp_put($this->_ftpConnection, $destFile, $this->tmpPath, FTP_BINARY);
296
				// Upload überprüfen
297
				if (!$uploadStatus)
298
			        return false;
299
			    return true;
300
				break;
301
			case 'chdir':
302
				// Datei hochladen
303
				$chdirStatus = ftp_chdir($this->_ftpConnection, $destFile);
304
				// Upload überprüfen
305
				if (!$chdirStatus)
306
			        return false;
307
			    return true;
308
				break;
309
		}
310
 
311
		// check the connection status
312
		if (!$this->_ftpConnection || !$this->_loginResult) {
313
			return false;
314
	    } else {
315
	        return true;
316
	    }
317
	}
318
 
319
	/**
320
	 * Export Data Array into XML Format
321
	 *
322
	 * @param array $data
323
	 * @return string
324
	 */
325
 
326
	function export($config) {
327
		$this->savePath = dirname($this->tmpPath);
328
		if
329
		(
330
			$this->ftp($config['username'],$config['password'],$config['hostname'], 'open')
331
			&&
332
			$this->ftp(null,null,null, 'chdir', $config['path'])
333
		)
334
		{
335
			if ($this->ftp(null,null,null, 'put', $config['file'])) {
336
				$upload = true;
337
			}
338
			$this->ftp(null,null,null, 'close');
339
			$connection = true;
340
		}
341
 
342
		if ($connection && $upload && $this->debugMode)
343
	    	return $this->XMLString;
344
	    else
345
	    	return false;
346
 
347
		if (!$connection && $this->debugMode)
348
	    	return "connection schlug fehl";
349
 
350
	    return false;
351
	}
352
 
353
}
354
 
355
class MyValidator {
356
 
357
	function validate($xml,$schema) {
358
		$dom = new DomDocument();
359
		$dom->load($xml);
360
 
361
		if ($dom->schemaValidate($schema)) {
362
			return true;
363
		}
364
		else {
365
			return false;
366
		}
367
	}
368
 
369
}
370
 
371
/*
372
 
373
// ImmoScout24 Testdaten
374
$tags = array(
375
 
376
		"IS24ImmobilienTransfer" 					=> array (
377
		     "close"								=>	1,
378
             "xmlns"    							=> 	"http://www.immobilienscout24.de/immobilientransfer",
379
             "xmlns:xsi"    						=> 	"http://www.w3.org/2001/XMLSchema-instance",
380
             "xsi:schemaLocation" 					=> 	"http://gwg.weban.de/XML/xsi/is24immotransfer.xsd",
381
             "ErstellerSoftware"   					=> 	"ImmoScout24Export",
382
             "ErstellerSoftwareVersion" 			=> 	"1.0",
383
             "EmailBeiFehler"      					=> 	"markus@weban.de"
384
		),
385
		"Anbieter" 									=> array (
386
			 "close"								=>	1,
387
			 "ScoutKundenID"						=>	"30302"
388
		),
389
		"WohnungMiete"								=> array (
390
			"close"									=>	1,
391
			"AnbieterObjektID"						=>	"0815",
392
			"Ueberschrift"							=>	"Schöne Wohnung" ,
393
			"Importmodus"							=>	"importieren" ,
394
			"Wohnflaeche"							=>	"100.00" ,
395
			"Zimmer"								=>	"4.00" ,
396
			"Adressdruck"							=>	"true" ,
397
			"AnzahlBadezimmer"						=>	"2" ,
398
			"AnzahlSchlafzimmer"					=>	"2" ,
399
			"Aufzug"								=>	"true" ,
400
			"BalkonTerrasse"						=>	"true" ,
401
			"Baujahr"								=>	"1869" ,
402
			"BetreutesWohnen"						=>	"true" ,
403
			"Einbaukueche"							=>	"true" ,
404
			"Etage"									=>	"2" ,
405
			"Etagenzahl"							=>	"6" ,
406
			"Foerderung"							=>	"true" ,
407
			"FreiAb"								=>	"sofort" ,
408
			"GartenBenutzung"						=>	"true" ,
409
			"GruppierungsID"						=>	"1" ,
410
			"Haustiere"								=>	"nachVereinbarung" ,
411
			"Heizungsart"							=>	"Zentralheizung" ,
412
			"Nutzflaeche"							=>	"22" ,
413
			"Objektzustand"							=>	"Gepflegt" ,
414
			"Parkplatz"								=>	"true" ,
415
			"Provision"								=>	"3.8% zzg. 16%MSt" ,
416
			"Rollstuhlgerecht"						=>	"true" ,
417
			"StatusHP"								=>	"aktiv" ,
418
			"StatusIS24"							=>	"aktiv" ,
419
			"StatusVBM"								=>	"aktiv" ,
420
			"Waehrung"								=>	"EUR" ,
421
			"WohnungKategorie"						=>	"Etagenwohnung"
422
		),
423
 
424
		"Adresse" 									=> array (
425
			 "close"								=>	0,
426
			 "Strasse"								=>	"Magazin Str.",
427
			 "Hausnummer"							=>	"15-16",
428
			 "Ort"									=>	"Berlin",
429
			 "Postleitzahl"							=>	"10179",
430
			 "Laenderkennzeichen"					=>	"DEU"
431
		),
432
 
433
		"Kontaktperson" 							=> array (
434
			 "close"								=>	0,
435
			 "Anrede"								=>	"Herr",
436
			 "Vorname"								=>	"Martin",
437
			 "Nachname"								=>	"Mustermann",
438
			 "Strasse"								=>	"Musterstr.",
439
			 "Hausnummer"							=>	"22",
440
			 "Ort"									=>	"Musterhausen",
441
			 "Postleitzahl"							=>	"12345",
442
			 "Laenderkennzeichen"					=>	"DEU",
443
			 "Telefon"								=>	"0123-43627272872",
444
			 "Mobiltelefon"							=>	"0179-534538729238",
445
			 "Telefax"								=>	"0123-43276728298",
446
			 "Homepage"								=>	"www.makler-wer.de",
447
			 "EMail"								=>	"info@wer.de"
448
		),
449
 
450
		"SonstigeAngaben" 							=> array (
451
			 "close"								=>	2,
452
			 "Contents"								=> "Sonstige Angaben"
453
		),
454
 
455
		"MultimediaAnhang" 							=> array (
456
			 "close"								=>	0,
457
			 "AnhangArt"							=>	"video",
458
			 "Titel"								=>	"Video",
459
			 "Dateityp"								=>	".MPG",
460
			 "Abspieldauer"							=>	"22",
461
			 "Dateiname"							=>	"video1.mpg"
462
		),
463
		"Mietpreise" 								=> array (
464
			 "close"								=>	0,
465
			 "Kaltmiete"							=>	"1234.3",
466
			 "Heizkosten"							=>	"200.30",
467
			 "HeizkostenInWarmmieteEnthalten"		=>	"true",
468
			 "Kaution"								=>	"3 Moanatsmieten",
469
			 "Nebenkosten"							=>	"250.33",
470
			 "StellplatzMiete"						=>	"160.00",
471
			 "Warmmiete"							=>	"2223.56"
472
		)
473
 
474
);
475
*/
476
 
477
/*
478
 
479
	www.ImmobilienScout24.de:
480
	Kunden-Nr: Ihre Scout Kunden-ID.
481
	Schemadatei: is24immotransfer.xsd
482
	Übertragung: FTP, als Zip-Archiv, (Teilabgleich)
483
	Host-Name: ftp.is24.de
484
	Benutzername: Ihre Scout Kunden-ID
485
	Kennwort: Ihr Scout Passwort
486
 
487
	www.Immonet.de:
488
	Kunden-Nr: Ihre Immonet Anbieter-Id.
489
	Schemadatei: openimmo.xsd
490
	Übertragung: FTP, als Zip-Archiv, Teilabgleich
491
	Host-Name: ftp.immonet.de
492
	Benutzername: Ihr spezieller Immonet-igeda username (bekommen Sie über uns)
493
	Kennwort: Ihr spezielles Immonet-igeda passwd (bekommen Sie über uns)
494
 
495
	www.immowelt.de:
496
	Kunden-Nr: Ihre immowelt Anbieter ID.
497
	Schemadatei: openimmo.xsd
498
	Übertragung: FTP, als Zip-Archiv, (Teilabgleich)
499
	Host-Name: ftp2.immowelt.net
500
	Benutzername: Ihr immowelt Benutzername
501
	Kennwort: Ihr immowelt Kennwort
502
 
503
	www.immobilien.de:
504
	Kunden-Nr: Ihre immobilien.de Kunden Nr.
505
	Schemadatei: openimmo.xsd
506
	Übertragung: FTP, als Zip-Archiv, (Teilabgleich)
507
	Host-Name: openimmo.immobilien.de
508
	Benutzername: Ihre immobilien Benutzername (Kunden Nr)
509
	Kennwort: Ihr immobilien Passwort
510
 
511
	www.immopool.de:
512
	Kunden-Nr: Ihre immopool Anbieternr.
513
	Schemadatei: openimmo.xsd
514
	Übertragung: FTP, als Zip-Archiv, (Teilabgleich)
515
	Host-Name: 62.225.144.225
516
	Verzeichnis: /Igeda/ Ihre immopool User-ID
517
	Benutzername: Ihre immopool User-ID
518
	Kennwort: Ihr immopool Passwort
519
 
520
	www. planethome.de:
521
	Kunden-Nr: Ihr Planethome Username
522
	Schemadatei: openimmo.xsd
523
	Übertragung: EMAIL, als Zip-Archiv
524
	E-Mail Adresse objekteinstellung@planethome.de
525
	E-Mail Betreff IMS 2000 Objekteinstellung: Ihr Planethome Username, Ihr Firmenname
526
 
527
 
528
$immoCompanys = array
529
(
530
	"immobilienscout24",
531
	"immonet",
532
	"immowelt",
533
	"immobilien",
534
	"immopool",
535
	"planethome"
536
);
537
 
538
$ftpServer= array
539
(
540
	"immobilienscout24",
541
	"immonet",
542
	"immowelt",
543
	"immobilien",
544
	"immopool",
545
	"planethome"
546
);
547
 
548
 
549
// GWG-Konfiguration
550
$config	= array(
551
	'username'	=> "gwg-gladbeck.de",
552
	'password'	=> "g-w7-a",
553
	'hostname'	=> "gwg-gladbeck.de",
554
	'path'		=> "immoscout",
555
	'file'		=> "ImmoScout24Export_GWG_".date("Y-m-d-h-i-s").".xml"
556
);
557
 
558
// initiate a ImmoScout24Export object
559
$ImmoScout24Export 	= &new ImmoScout24Export('gwg_gladbeck_de');
560
$header 			= $ImmoScout24Export->getXMLDeclaration('1.0','UTF-8');
561
$string 			= $ImmoScout24Export->parse2XML($tags);
562
 
563
// Save Handler
564
$ImmoScout24Export->XMLSave($content, "ImmoScout24Export.xml","./XML_DATA/");
565
 
566
// show export
567
if (($return = $ImmoScout24Export->export($config)) !== FALSE)
568
{
569
	echo "UploadServer: 	".$config['hostname']."<br>";
570
	echo "UploadUser: 		".$config['username']."<br>";
571
	echo "UploadVerzeichnis: ./".$config['path']."/<br>";
572
 
573
	echo "Der Export verlief erfolgreich, die Datei: ".$config['file']." hat folgenden Inhalt: <br />";
574
	echo "<textarea name=\"textarea\" id=\"textarea\" cols=\"80\" rows=\"20\">$return</textarea>";
575
}
576
*/
577
?>