-
Notifications
You must be signed in to change notification settings - Fork 0
/
pluriofeed.php
62 lines (51 loc) · 1.48 KB
/
pluriofeed.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* Plurioparser
*
* Parses data from various sources and generates plurio.net XML data
*
* @author David Raison <david@raison.lu>
* @file pluriofeed.php
* @ingroup plurioparser
* @version 1.1
*/
define('DS', DIRECTORY_SEPARATOR);
// first get the config data (not using a multi-array here)
$config = parse_ini_file( 'config/config.ini', false );
$config['debug'] && $time_start = time();
/**
* Complicated autoloading function...
*/
function __autoload( $name ) {
if ( strpos( $name, '_' ) ) {
$parts = explode('_', $name );
$dir = strtolower( $parts[0] ) . DS;
$name = $parts[1];
} else $dir = '';
$filename = dirname( __FILE__ ) . DS . $dir . strtolower( $name ) . '.class.php';
if (file_exists( $filename ) ) {
require_once $filename;
} else {
throw new Exception( sprintf( 'Couldn\'t require component "%s"', $name ), 405 );
}
}
// main()
try {
$data = SourceParser::retrieve( $config['data.format'], $config['data.source'] );
$plurio = new PlurioXMLBuilder( $data );
$xmlFeed = $plurio->createFeed();
} catch ( Exception $e ) {
print($e->getMessage());
}
if ( $config['output.type'] == 'stdout' ) {
$plurio->send_headers();
print( $xmlFeed );
} elseif ( $config['output.type'] == 'file' ) {
file_put_contents( $config['output.dest'], $xmlFeed );
} else throw new Exception( 'output.type must be specified in the config file' );
// More debug
if( $config['debug'] ){
$exectime = time() - $time_start;
printf("Execution took %d seconds\n", $exectime);
}
?>