File: //opt/plugins/atalantini/data/parsexml.php
<?php
/**
* Atom Publishing Protocol support for WordPress
*
* @version 1.0.5-dc
*/
/**
* WordPress is handling an Atom Publishing Protocol request.
*
* @var bool
*/
define('APP_REQUEST', true);
/** Set up WordPress environment */
require_once('../../../../wp-load.php');
/** Atom Publishing Protocol Class */
require_once(ABSPATH . WPINC . '/atomlib.php');
/** Admin Image API for metadata updating */
require_once(ABSPATH . '/wp-admin/includes/image.php');
$_SERVER['PATH_INFO'] = preg_replace( '/.*\/wp-app\.php/', '', $_SERVER['REQUEST_URI'] );
/**
* Whether to enable Atom Publishing Protocol Logging.
*
* @name app_logging
* @var int|bool
*/
$app_logging = 0;
/**
* Whether to always authenticate user. Permanently set to true.
*
* @name always_authenticate
* @var int|bool
* @todo Should be an option somewhere
*/
$always_authenticate = 1;
/**
* Writes logging info to a file.
*
* @since 2.2.0
* @uses $app_logging
* @package WordPress
* @subpackage Logging
*
* @param string $label Type of logging
* @param string $msg Information describing logging reason.
*/
function log_app($label,$msg) {
global $app_logging;
if ($app_logging) {
$fp = fopen( 'wp-app.log', 'a+');
$date = gmdate( 'Y-m-d H:i:s' );
fwrite($fp, "\n\n$date - $label\n$msg\n");
fclose($fp);
}
}
global $wpdb;
$i = 0; // counter
$url = "http://www.gazzetta.it/rss/Squadre/Atalanta.xml"; // url to parse
$rss = simplexml_load_file($url); // XML parser
// RSS items loop
//print '<h2><img style="vertical-align: middle;" src="'.$rss->channel->image->url.'" /> '.$rss->channel->title.'</h2>'; // channel title + img with src
$i = 0;
$json['item'] = array();
$jsons = array();
foreach($rss->channel->item as $item) {
$json['item']['position'] = $i;
$json['item']['title'] = str_replace("\n","",preg_replace('/^\s*\/\/<!\[CDATA\[([\s\S]*)\/\/\]\]>\s*\z/', '$1', $item->title));
$json['item']['description'] = str_replace("\n","",preg_replace('/^\s*\/\/<!\[CDATA\[([\s\S]*)\/\/\]\]>\s*\z/', '$1', $item->description));
//echo $item->title;
$i++;
$jsons[] = $json;
}
echo "{\"lista\":" . json_encode($jsons) . "}";
?>