Refactoring of init.php
- fetching is now done by a global function in fetch.php. This allows to use this functions in test/xpath.php for testing. - besides of user configuration as explained in README.d json files from `mods` are now also loaded and used for fetching articles - loading of json files is done only one time and not for each article to process - test/xpath.php is now a script, which can be used to test a configuration from `mods`-directory Added two mods for 4players and visions.de. TODO: rewrite README.md
This commit is contained in:
@ -1,33 +1,37 @@
|
||||
<?php
|
||||
|
||||
$config = array(
|
||||
'type' => 'xpath',
|
||||
'xpath' => 'div[@itemprop="articleBody"]',
|
||||
);
|
||||
require_once('../fetch.php');
|
||||
|
||||
$article = array(
|
||||
'link' => 'http://www.der-postillon.com/2013/04/nordkoreas-armee-nach-wochenlangem.html',
|
||||
'content' => 'This is the feed content',
|
||||
'plugin_data' => '',
|
||||
);
|
||||
|
||||
$doc = new DOMDocument();
|
||||
$html = file_get_contents($article['link']);
|
||||
$doc->loadHTML($html);
|
||||
|
||||
if ($doc) {
|
||||
$basenode = false;
|
||||
$xpath = new DOMXPath($doc);
|
||||
$entries = $xpath->query('(//'.$config['xpath'].')'); // find main DIV according to config
|
||||
|
||||
var_dump($entries);
|
||||
|
||||
if ($entries->length > 0) $basenode = $entries->item(0);
|
||||
|
||||
if ($basenode) {
|
||||
$article['content'] = $doc->saveXML($basenode);
|
||||
$article['plugin_data'] = "feedmod,$owner_uid:" . $article['plugin_data'];
|
||||
}
|
||||
if (count($argv) <= 2) {
|
||||
echo 'USAGE: php fetch.php [mod_file] [article_url]' . PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
print_r($article);
|
||||
$mod = $argv[1];
|
||||
$article_url = $argv[2];
|
||||
|
||||
//
|
||||
// Getting json config
|
||||
//
|
||||
|
||||
$json = file_get_contents($mod);
|
||||
$data = json_decode($json, true);
|
||||
|
||||
echo "<pre>";
|
||||
print_r($data);
|
||||
echo "</pre>";
|
||||
|
||||
if (json_last_error() != JSON_ERROR_NONE) {
|
||||
echo 'Json error' . PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$config = $data['config'];
|
||||
|
||||
//
|
||||
// Fetching article
|
||||
//
|
||||
|
||||
$owner_uid = 100;
|
||||
$article = array( 'link' => $article_url, 'plugin_data' => '' );
|
||||
echo fetch_article($article, $config)['content'];
|
||||
|
Reference in New Issue
Block a user