File: /var/www/html/wp-content/plugins/adnkronos/admin/option-panel.php
<?php
/*
Admin Panel Option
*/
// Exit if accessed directly
if (!defined('ABSPATH')) {
exit;
}
// Start Class
if (!class_exists('adnk_importer_Options')) {
class adnk_importer_Options
{
/**
* Start things up
*
* @since 1.0.0
*/
public function __construct()
{
// We only need to register the admin panel on the back-end
if (is_admin()) {
add_action('admin_menu', array('adnk_importer_Options', 'add_admin_menu'));
add_action('admin_init', array('adnk_importer_Options', 'register_settings'));
}
}
/**
* Returns all adnk_importer options
*
* @since 1.0.0
*/
public static function get_adnk_importer_options()
{
return get_option('adnk_importer_options');
}
/**
* Returns single adnk_importer option
*
* @since 1.0.0
*/
public static function get_adnk_importer_option($id)
{
$options = self::get_adnk_importer_options();
if (isset($options[$id])) {
return $options[$id];
}
}
/**
* Add sub menu page
*
* @since 1.0.0
*/
public static function add_admin_menu()
{
add_menu_page(
esc_html__('AdnKronos', 'adnkronos'),
esc_html__('AdnKronos', 'adnkronos'),
'manage_options',
'adnk-plugin-settings',
array('adnk_importer_Options', 'create_admin_page')
);
}
/**
* Register a setting and its sanitization callback.
*
* We are only registering 1 setting so we can store all options in a single option as
* an array. You could, however, register a new setting for each option
*
* @since 1.0.0
*/
public static function register_settings()
{
register_setting('adnk_importer_options', 'adnk_importer_options', array('adnk_importer_Options', 'sanitize'));
}
/**
* Sanitization callback
*
* @since 1.0.0
*/
public static function sanitize($options)
{
//Get the active tab from the $_GET param
$default_tab = null;
$tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : $default_tab;
// If we have options lets sanitize them
if ($options) {
if ($tab === null) {
// Checkbox consent_send_statistical_data
if (!empty($options['consent_send_statistical_data'])) {
$options['consent_send_statistical_data'] = 'on';
} else {
unset($options['consent_send_statistical_data']); // Remove from options if not checked
}
} elseif ($tab === 'settings') {
// Select selected_post_owner
if (!empty($options['selected_post_owner'])) {
$options['selected_post_owner'] = sanitize_text_field($options['selected_post_owner']);
}
// frenquenza import
if (!empty($options['selected_freq_import'])) {
$options['selected_freq_import'] = sanitize_text_field($options['selected_freq_import']);
}
// Feed gestiti dal plugin: 'ultimora', 'primapagina', 'newsregionali', 'salute', 'lavoro', 'sostenibilita', 'comunicati', 'motori', 'fintech',
// Feed aggiuntivi corrieri: 'facilitalia', 'finanza', 'tecnologia', 'wine', 'sport', 'fisco', 'demografica', 'toscana',
// Get feeds dynamically from API
$feeds_data = adnk_feed_by_site();
$feeds = array();
if ($feeds_data && isset($feeds_data->feeds)) {
foreach ($feeds_data->feeds as $feed) {
$feeds[] = $feed->code;
}
}
// Process all feeds dynamically
foreach ($feeds as $feed_code) {
// Checkbox for feed
$checkbox_key = 'url_' . $feed_code . '_feed';
if (!empty($options[$checkbox_key])) {
$options[$checkbox_key] = 'on';
} else {
unset($options[$checkbox_key]); // Remove from options if not checked
}
// Select feed Category
$category_key = 'selected_' . $feed_code . '_feed_category';
if (!empty($options[$category_key])) {
$options[$category_key] = sanitize_text_field($options[$category_key]);
}
// Select posts status
$status_key = 'selected_' . $feed_code . '_post_status';
if (!empty($options[$status_key])) {
$options[$status_key] = sanitize_text_field($options[$status_key]);
}
// Feed post owner
$owner_key = 'selected_' . $feed_code . '_post_owner';
if (!empty($options[$owner_key])) {
$options[$owner_key] = sanitize_text_field($options[$owner_key]);
}
}
}
}
// Return sanitized options
return $options;
}
/**
* Settings page output
*
* @since 1.0.0
*/
public static function create_admin_page()
{ ?>
<?php
/* call function for register user */
//$site_url = get_home_url();
$regist_user = adnk_verify_site();
if (get_adnk_settings_option('consent_send_statistical_data') == 'on' || $regist_user == true) {
$field_disabled = '';
} else {
$field_disabled = 'disabled';
}
// Ottiene gli utenti per i menu a discesa
$users = get_users(['fields' => ['user_email', 'user_login']]);
/* set cron event */
$selected_freq_import = get_adnk_importer_option('selected_freq_import');
adnk_import_activation($selected_freq_import);
?>
<div id="adk">
<div class="container wrap">
<?php $logo_tdm_url = plugin_dir_url(__FILE__) . "img/logoadnkronos.jpg" ?>
<h1><img src="<?php echo esc_url($logo_tdm_url) ?>"><?php esc_html_e('AdnKronos Feed Importer Options', 'adnkronos'); ?></h1>
<p></p>
<nav class="nav-tab-wrapper">
<a href="?page=adnk-plugin-settings" class="nav-tab nav-tab-active"><?php esc_html_e('Impostazioni di Importazione', 'adnkronos'); ?></a>
<a href="?page=adnk-plugin-account" class="nav-tab "><?php echo esc_html_e('Abilitazione dominio', 'adnkronos'); ?></a>
<a href="?page=adnk-plugin-log" class="nav-tab"><?php esc_html_e('Log importazioni', 'adnkronos'); ?></a>
</nav>
<div class="tab-content">
<form method="post" action="options.php" novalidate>
<div class="row">
<div class="col-9">
<?php settings_fields('adnk_importer_options'); ?>
<div class="card card-static mt-4">
<div class="card-header"><strong><?php esc_html_e('Utente di destinazione di articoli e foto', 'adnkronos'); ?></strong></div>
<div class="card-body">
<p>
Selezionare l'utente che risulterà proprietario degli articoli dopo l'importazione.
</p>
<?php $value = self::get_adnk_importer_option('selected_post_owner'); ?>
<select required id="selected_post_owner" name="adnk_importer_options[selected_post_owner]">
<option value=""><?php esc_html_e('Seleziona proprietario del post', 'adnkronos') ?></option>
<?php foreach ($users as $user_email) { ?>
<option value="<?php echo esc_attr($user_email->user_email); ?>" <?php selected($user_email->user_email, $value); ?>><?php echo esc_html($user_email->user_login) . ' - ' . esc_html($user_email->user_email); ?>
</option>
<?php } ?>
</select>
</div>
<div class="card-body">
<p>
Selezionare l'utente che risulterà proprietario delle immagini dopo l'importazione.<br/>
Può essere diverso dal proprietario del post.
</p>
<p>
<?php $value = self::get_adnk_importer_option('check_no_image_import'); ?>
<input type="checkbox" name="adnkronos_options[check_no_image_import]" <?php checked($value, 'on'); ?>> <?php esc_html_e('Non importare le immagini', 'adnkronos'); ?>
</p>
<?php $value = self::get_adnk_importer_option('selected_image_owner'); ?>
<select required id="selected_image_owner" name="adnk_importer_options[selected_image_owner]">
<option value=""><?php esc_html_e('Seleziona proprietario delle immagini', 'adnkronos') ?></option>
<?php foreach ($users as $user_email) { ?>
<option value="<?php echo esc_attr($user_email->user_email); ?>" <?php selected($user_email->user_email, $value); ?>><?php echo esc_html($user_email->user_login) . ' - ' . esc_html($user_email->user_email); ?>
</option>
<?php } ?>
</select>
</div>
</div>
<div class="card card-static mt-4">
<div class="card-header"><strong><?php esc_html_e('Intervallo di Import articoli', 'adnkronos'); ?></strong></div>
<div class="card-body">
<p>
Selezionare l'intervallo temporale di importazione automatica degli articoli. E' possibile avviare una importazione
immediata con il pulsante "Importa Ora". Importazioni entro i 3 minuti dall'ultima importazione vengono ignorate.
</p>
<div class="row">
<div class="col-9">
<?php $value = self::get_adnk_importer_option('selected_freq_import'); ?>
<select id="selected_freq_import" name="adnk_importer_options[selected_freq_import]">
<option value="halfhourly" <?php selected('halfhourly', $value); ?>><?php esc_html_e('Una volta ogni 30 minuti', 'adnkronos') ?></option>
<option value="hourly" <?php selected('hourly', $value); ?>><?php esc_html_e('Una volta ogni ora', 'adnkronos') ?></option>
<option value="twohourly" <?php selected('twohourly', $value); ?>><?php esc_html_e('Una volta ogni due ore', 'adnkronos') ?></option>
<option value="fourhourly" <?php selected('fourhourly', $value); ?>><?php esc_html_e('Una volta ogni quattro ore', 'adnkronos') ?></option>
<option value="sixhourly" <?php selected('sixhourly', $value); ?>><?php esc_html_e('Una volta ogni sei ore', 'adnkronos') ?></option>
<option value="twicedaily" <?php selected('twicedaily', $value); ?>><?php esc_html_e('Ogni 12 ore', 'adnkronos') ?></option>
<option value="daily" <?php selected('daily', $value); ?>><?php esc_html_e('Una volta al giorno', 'adnkronos') ?></option>
</select>
<span class="message"></span>
</div>
<div class="col-3">
<?php
$regist_user = get_option('adn_site_active', 0);
if ($regist_user != true) {
$user = wp_get_current_user(); ?>
<span style="margin-bottom: 5px; color: #333">Registra il sito per importare le news</span>
<?php } else { ?>
<a href="<?php echo esc_url(site_url()) ?>/wp-admin/admin.php?action=adnk_import_now" style="margin-bottom: 5px;" class="button button-primary">Importa Ora</a>
<?php } ?>
</div>
</div>
</div>
</div>
<div class="card card-static mt-4">
<div class="card-header"><strong><?php esc_html_e('Intervallo di cancellazione degli articoli', 'adnkronos'); ?></strong></div>
<div class="card-body">
<p>
E' possibile selezionare l'intervallo temporale di cancellazione dei vecchi articoli
</p>
<div class="row">
<div class="col-9">
<?php $value = self::get_adnk_importer_option('selected_freq_cancel'); ?>
<select id="selected_freq_cancel" name="adnk_importer_options[selected_freq_cancel]">
<option value="" <?php selected('', $value); ?>><?php esc_html_e('Non cancellare', 'adnkronos') ?></option>
<option value="30" <?php selected('30', $value); ?>><?php esc_html_e('Dopo 30 giorni', 'adnkronos') ?></option>
<option value="60" <?php selected('60', $value); ?>><?php esc_html_e('Dopo 60 giorni', 'adnkronos') ?></option>
<option value="90" <?php selected('90', $value); ?>><?php esc_html_e('Dopo 90 giorni', 'adnkronos') ?></option>
<option value="120" <?php selected('120', $value); ?>><?php esc_html_e('Dopo 120 giorni', 'adnkronos') ?></option>
<option value="240" <?php selected('240', $value); ?>><?php esc_html_e('Dopo 240 giorni', 'adnkronos') ?></option>
</select>
<span class="message"></span>
</div>
<div class="col-3">
</div>
</div>
</div>
</div>
</div>
<div class="col-3">
<div class="card card-static border-primary mt-4">
<div class="card-body">
<p class="card-text">
<?php $logo_tdm_url = plugin_dir_url(__FILE__) . "img/logo-adnkronos.svg" ?>
<img width="200px" src="<?php echo esc_url($logo_tdm_url) ?>">
<br/><br/>
<b>ROMA</b> Piazza Mastai n.9 - 00153<br/>
T: +39 06 5807666 <br/> F: +39 06 5807815<br/>
<br/>
<b>MILANO</b> Via Manin, 37 - 20121<br/>
T: +39 02 763661
</p>
</div>
</div>
</div>
<div class="col-12">
<?php
$args = array("hide_empty" => 0,
"type" => "post",
"orderby" => "name",
"order" => "ASC");
$categories = get_categories($args);
?>
<div class="card card-static">
<div class="card-header">
Feed disponibili
</div>
<div class="card-body">
<p>
E' possibile per ogni feed rilasciato da AdnKronos selezionare la categoria di
destinazione ed il relativo stato di pubblicazione.<br/>
Per abilitare l'accesso a tutti i feed è necessario registrare il tuo dominio.
</p>
<table class="form-table wpex-custom-admin-login-table">
<tr valign="top">
<td><strong><?php esc_html_e('Feed da importare', 'adnkronos'); ?></strong></td>
<td><strong><?php esc_html_e('Categoria di destinazione', 'adnkronos'); ?></strong></td>
<td><strong><?php esc_html_e('Stato di destinazione', 'adnkronos'); ?></strong></td>
<td><strong><?php esc_html_e('Proprietario', 'adnkronos'); ?></strong></td>
</tr>
<?php
$feeds = adnk_feed_by_site();
if (!is_iterable($feeds)) {
?>
<tr valign="top">
<td>
<i>Problema di importazione dei feeds</i>
</td>
</tr>
<?php
} else {
foreach ($feeds as $feed) {
$checkOptionCode = 'url_' . $feed['code'] . '_feed';
$checkOptionValue = self::get_adnk_importer_option($checkOptionCode);
$categoryOptionCode = 'selected_' . $feed['code'] . '_feed_category';
$categoryOptionValue = self::get_adnk_importer_option($categoryOptionCode);
$statusOptionCode = 'selected_' . $feed['code'] . '_post_status';
$statusOptionValue = self::get_adnk_importer_option($statusOptionCode);
$ownerOptionCode = 'selected_' . $feed['code'] . '_post_owner';
$ownerOptionValue = self::get_adnk_importer_option($ownerOptionCode);
if (!$feed['youtube']) {
?>
<tr valign="top">
<td>
<input type="checkbox" name="adnk_importer_options[<?php echo esc_attr($checkOptionCode) ?>]" <?php checked($checkOptionValue, 'on'); ?>> <?php echo esc_html($feed['name']); ?>
</td>
<td>
<select required id="<?php echo esc_attr($categoryOptionCode) ?>" name="adnk_importer_options[<?php echo esc_attr($categoryOptionCode) ?>]">
<option value=""><?php esc_html_e('---', 'adnkronos') ?></option>
<?php foreach ($categories as $category) { ?>
<option value="<?php echo esc_attr($category->term_id); ?>" <?php selected($category->term_id, $categoryOptionValue); ?>>
<?php echo esc_html($category->name); ?>
</option>
<?php } ?>
</select>
</td>
<td>
<select id="<?php echo esc_attr($statusOptionCode) ?>" name="adnk_importer_options[<?php echo esc_attr($statusOptionCode) ?>]">
<option value="publish" <?php selected('publish', $statusOptionValue); ?>><?php esc_html_e('Pubblicato', 'adnkronos') ?></option>
<option value="draft" <?php selected('draft', $statusOptionValue); ?>><?php esc_html_e('Bozza', 'adnkronos') ?></option>
</select>
</td>
<td>
<select required id="<?php echo esc_attr($ownerOptionCode) ?>" name="adnk_importer_options[<?php echo esc_attr($ownerOptionCode) ?>]">
<option value=""><?php esc_html_e('Seleziona proprietario degli articoli', 'adnkronos') ?></option>
<?php foreach ($users as $user_email) { ?>
<option value="<?php echo esc_attr($user_email->user_email); ?>" <?php selected($user_email->user_email, $ownerOptionValue); ?>><?php echo esc_html($user_email->user_login) . ' - ' . esc_html($user_email->user_email); ?>
</option>
<?php } ?>
</select>
</td>
</tr>
<?php } else { ?>
<tr valign="top">
<td>
<input type="checkbox" name="adnk_importer_options[<?php echo esc_attr($checkOptionCode) ?>]" <?php checked($checkOptionValue, 'on'); ?>> <?php echo esc_html($feed['name']); ?>
</td>
<td>
<select required id="<?php echo esc_attr($categoryOptionCode) ?>" name="adnk_importer_options[<?php echo esc_attr($categoryOptionCode) ?>]">
<option value=""><?php esc_html_e('---', 'adnkronos') ?></option>
<?php foreach ($categories as $category) { ?>
<option value="<?php echo esc_attr($category->term_id); ?>" <?php selected($category->term_id, $categoryOptionValue); ?>>
<?php echo esc_html($category->name); ?>
</option>
<?php } ?>
</select>
</td>
<td>
<select id="<?php echo esc_attr($statusOptionCode) ?>" name="adnk_importer_options[<?php echo esc_attr($statusOptionCode) ?>]">
<option value="publish" <?php selected('publish', $statusOptionValue); ?>><?php esc_html_e('Pubblicato', 'adnkronos') ?></option>
<option value="draft" <?php selected('draft', $statusOptionValue); ?>><?php esc_html_e('Bozza', 'adnkronos') ?></option>
</select>
</td>
<td>
<select required id="<?php echo esc_attr($ownerOptionCode) ?>" name="adnk_importer_options[<?php echo esc_attr($ownerOptionCode) ?>]">
<option value=""><?php esc_html_e('Seleziona proprietario degli articoli', 'adnkronos') ?></option>
<?php foreach ($users as $user_email) { ?>
<option value="<?php echo esc_attr($user_email->user_email); ?>" <?php selected($user_email->user_email, $ownerOptionValue); ?>><?php echo esc_html($user_email->user_login) . ' - ' . esc_html($user_email->user_email); ?>
</option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td colspan="4">
I video vengono inclusi nel contenuto dell'articolo tramite shortcode [embed] come da standard WordPress. Per poter essere
visualizzati E' NECESSARIO che il sito (tema o altri plugin) siano in grado di elaborare correttamente
lo shortcode. Nessun file video viene scaricato in locale.
</td>
</tr>
<?php }
}
}
?>
</table>
</div>
</div>
<?php submit_button(); ?>
</div>
</div>
</form>
</div><!-- tab-content -->
</div><!-- .wrap -->
</div>
<?php }
}
}
new adnk_importer_Options();
// Helper function to use in your theme to return a theme option value
function get_adnk_importer_option($id = '')
{
return adnk_importer_Options::get_adnk_importer_option($id);
}
add_action('admin_enqueue_scripts', 'ecctdm_enqueue_color_picker');
function ecctdm_enqueue_color_picker($hook_suffix)
{
// first check that $hook_suffix is appropriate for your admin page
wp_enqueue_style('wp-color-picker');
wp_enqueue_style('admin-style-adk', plugin_dir_url(__FILE__) . '/css/admin.css');
}
if (!class_exists('adnk_settings_Options')) {
class adnk_settings_Options
{
/**
* Start things up
*
* @since 1.0.0
*/
public function __construct()
{
// We only need to register the admin panel on the back-end
if (is_admin()) {
add_action('admin_menu', array('adnk_settings_Options', 'add_settings_menu_page'));
add_action('admin_init', array('adnk_settings_Options', 'register_settings'));
}
}
/**
* Returns all adnk_settings options
*
* @since 1.0.0
*/
public static function get_adnk_settings_options()
{
return get_option('adnk_settings_options');
}
/**
* Returns single adnk_settings option
*
* @since 1.0.0
*/
public static function get_adnk_settings_option($id)
{
$options = self::get_adnk_settings_options();
if (isset($options[$id])) {
return $options[$id];
}
}
/**
* Add sub menu page
*
* @since 1.0.0
*/
public static function add_settings_menu_page()
{
add_submenu_page('adnk-plugin-settings', 'Impostazioni Account', 'Impostazioni Account', 'manage_options', 'adnk-plugin-account', array('adnk_settings_Options', 'adnk_plugin_func_accsettings'));
}
/**
* Register a setting and its sanitization callback.
*
* We are only registering 1 setting so we can store all options in a single option as
* an array. You could, however, register a new setting for each option
*
* @since 1.0.0
*/
public static function register_settings()
{
register_setting('adnk_settings_options', 'adnk_settings_options', array('adnk_settings_Options', 'sanitize_settings'));
}
public static function sanitize_settings($options)
{
// If we have options lets sanitize them
if ($options) {
// Checkbox consent_send_statistical_data
if (!empty($options['consent_send_statistical_data'])) {
$options['consent_send_statistical_data'] = 'on';
} else {
unset($options['consent_send_statistical_data']); // Remove from options if not checked
}
}
// Return sanitized options
return $options;
}
/* */
public static function adnk_plugin_func_accsettings()
{
?>
<div id="adk">
<div class="container wrap">
<?php $logo_tdm_url = plugin_dir_url(__FILE__) . "img/logoadnkronos.jpg" ?>
<h1><img src="<?php echo esc_url($logo_tdm_url) ?>"><?php esc_html_e('AdnKronos Feed Importer Options', 'adnkronos'); ?></h1>
<p></p>
<nav class="nav-tab-wrapper">
<a href="?page=adnk-plugin-settings" class="nav-tab "><?php esc_html_e('Impostazioni di Importazione', 'adnkronos'); ?></a>
<a href="?page=adnk-plugin-account" class="nav-tab nav-tab-active"><?php esc_html_e('Account Settings', 'adnkronos'); ?></a>
<a href="?page=adnk-plugin-log" class="nav-tab"><?php esc_html_e('Log importazioni', 'adnkronos'); ?></a>
</nav>
<div class="tab-content">
<div class="row">
<div class="col-9">
<form method="post" action="options.php">
<?php settings_fields('adnk_settings_options'); ?>
<div class="card card-static mt-4">
<div class="card-header"><strong><?php esc_html_e('Consenso invio dati statistici', 'adnkronos'); ?></strong></div>
<div class="card-body">
<p>
Il sistema non raccoglie dati di navigazione degli utenti, siano essi visitatori del sito o gestori.<br/>
Le statistiche raccolte sono relative al numero di articoli importati e pubblicati per categoria, non rientrano pertanto
nella categoria dei "dati sensibili" o "dati personali".<br/>
Il consenso è necessario per poter abilitare tutti i feed.
</p>
<?php $value = self::get_adnk_settings_option('consent_send_statistical_data'); ?>
<input type="checkbox" name="adnk_settings_options[consent_send_statistical_data]" <?php checked($value, 'on'); ?>> <?php esc_html_e('Acconsento all\'invio dei dati', 'adnkronos'); ?>
</div>
</div>
<?php $regist_user = get_option('adn_site_active', 0);
if (!$regist_user) {
?>
<div class="card card-static mt-4">
<div class="card-header"><strong><?php esc_html_e('Verifica il tuo dominio', 'adnkronos'); ?></strong></div>
<div class="card-body">
<p>
Per verificare il tuo dominio <a target="_blank" href="<?php echo ADNK_API_BASE_URL ?>?domain=<?php echo urlencode(esc_url(get_site_url())) ?>">compila la richiesta cliccando qui registrando il tuo dominio <?php echo esc_url(get_site_url()); ?></a>!
</p>
</div>
</div>
<?php } ?>
<?php submit_button(); ?>
</form>
</div>
<div class="col-3">
<div class="card card-static border-primary mt-4">
<div class="card-body">
<p class="card-text">
<?php $logo_tdm_url = plugin_dir_url(__FILE__) . "img/logo-adnkronos.svg" ?>
<img width="200px" src="<?php echo esc_url($logo_tdm_url) ?>">
<br/><br/>
<b>ROMA</b> Piazza Mastai n.9 - 00153<br/>
T: +39 06 5807666 <br/> F: +39 06 5807815<br/>
<br/>
<b>MILANO</b> Via Manin, 37 - 20121<br/>
T: +39 02 763661
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
}
}
}
new adnk_settings_Options();
// Helper function to use in your theme to return a theme option value
function get_adnk_settings_option($id = '')
{
return adnk_settings_Options::get_adnk_settings_option($id);
}
/* admin notices */
function adnk_admin_notice()
{
//$site_url = get_home_url();
$regist_user = get_option('adn_site_active', 0);
if ($regist_user != true) {
$user = wp_get_current_user();
if (in_array('administrator', (array)$user->roles)) {
echo '<div class="notice notice-warning is-dismissible">
<p>Adnkronos importer non è registrato <a href="/wp-admin/admin.php?page=adnk-plugin-account">Registra il tuo dominio</a></p>
<p>Se non registri il tuo dominio sarai limitato nell\'importazione delle notizie.</p>
</div>';
}
}
}
add_action('admin_notices', 'adnk_admin_notice');