File: //opt/plugins/atalantini/data/service_newspublic.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;
$table = "wp_plugin_elettroteca_news_public";
$azione = $_GET['azione'];
if ($azione == "INSERT") {
$wpdb->insert(
$table,
array(
'data' => str_replace("\\","",$_POST['data']),
'titolo' => str_replace("\\","",$_POST['titolo']),
'abstract' => str_replace("\\","",$_POST['abstract']),
'testo' => str_replace("\\","",$_POST['testo']),
'tipo_accesso' => str_replace("\\","",$_POST['tipo_accesso']),
'tipo_target' => str_replace("\\","",$_POST['tipo_target'])
),
array(
'%s',
'%s',
'%s',
'%s',
'%s',
'%s'
)
);
}
if ($azione == "UPDATE") {
$wpdb->update(
$table,
array(
'data' => str_replace("\\","",$_POST['data']),
'titolo' => str_replace("\\","",$_POST['titolo']),
'abstract' => str_replace("\\","",$_POST['abstract']),
'testo' => str_replace("\\","",$_POST['testo']),
'tipo_accesso' => str_replace("\\","",$_POST['tipo_accesso']),
'tipo_target' => str_replace("\\","",$_POST['tipo_target'])
),
array( 'id' => $_POST['id'] ),
array(
'%s',
'%s',
'%s',
'%s',
'%s',
'%s'
),
array( '%d' )
);
}
if ($azione == "DELETE") {
$wpdb->query("delete from " . $table . " where id = " . $_POST['id']);
}
if ($azione == "SETPUBLICNEWS") {
$wpdb->query("insert into " . $table . "(wp_page) values (" . $_POST['id'] . ");");
}
if ($azione == "DELPUBLICNEWS") {
$wpdb->query("delete from " . $table . " where wp_page = " . $_POST['id']);
}
if ($azione == "LIST") {
$limit = "";
if ($_GET['pageNo'] == '1') {
$limit = "limit 0, " . $_GET['pageSize'];
}
if ($_GET['pageNo'] != '1') {
$page = $_GET['pageNo'];
$size = $_GET['pageSize'];
$page = $size * ($page - 1);
$limit = "limit " . $page . ", " . $_GET['pageSize'];
}
$where = " where post_type = 'post' and wp_terms.term_id = wp_term_taxonomy.term_id and wp_term_taxonomy.term_taxonomy_id = wp_term_relationships.term_taxonomy_id and wp_posts.id = object_id and post_status = 'publish' ";
if ($_GET['searchkey'] != '') {
$where .= " and (post_title like '%" . $_GET['searchkey'] . "%' or post_name like '%" . $_GET['searchkey'] . "%' or post_content like '%" . $_GET['searchkey'] . "%')";
}
$rs = $wpdb->get_results("select id, date_format(post_date, '%d-%m-%Y') as data, post_title as titolo,wp_terms.name as category, (select count(id) from wp_plugin_elettroteca_news_public where wp_page = wp_posts.id) as conteggio from wp_posts,wp_terms, wp_term_taxonomy, wp_term_relationships " . $where . " order by post_date desc " . $limit . ";");
foreach ( $rs as $line ) {
$elementiSingoli[] = json_encode(array('id' => $line->id, 'data' => $line->data, 'titolo' => $line->titolo, 'conteggio' => $line->conteggio, 'categoria' => $line->category));
}
// estraggo totaleValori
$totaleValori = 0;
$rs = $wpdb->get_results("select count(*) as contatore from " . $table . ";");
foreach ( $rs as $line ) {
$totaleValori = $line->contatore;
}
if (count($elementiSingoli) > 0) {
?>
{"totaleValori":"<?= $totaleValori ?>","lista":[<?= implode(",", $elementiSingoli) ?>]}
<?php
} else {
?>
{"totaleValori":"<?= $totaleValori ?>","lista":[]}
<?php
}
}
if ($azione == "DETAIL") {
$rs = $wpdb->get_results("select * from " . $table . " where id = " . $_GET['id'] . ";");
foreach ( $rs as $line ) {
$elementiSingoli[] = json_encode(array('id' => $line->id, 'data' => $line->data, 'titolo' => $line->titolo, 'abstract' => $line->abstract, 'testo' => $line->testo, 'tipo_accesso' => $line->tipo_accesso, 'tipo_target' => $line->tipo_target, 'immagine' => $line->immagine, 'wp_page' => $line->wp_page));
}
?>
{"dettaglio":[<?= implode(",", $elementiSingoli) ?>]}
<?php
}
?>