194 lines
8.6 KiB
PHP
194 lines
8.6 KiB
PHP
<?php
|
|
/* Plugin Name: Approva pubblicazioni
|
|
* Plugin URI: http://steamware.net/
|
|
* Description: Plugin approvazione articoli graspa
|
|
* Version: 1.0.0
|
|
* Author: Marco Salvi
|
|
* Author URI: http://steamware.net/
|
|
* License: GPL-2.0+
|
|
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
|
|
*/
|
|
function insertpub(){
|
|
if(isset($_GET['email']) && isset($_GET['doi']) && isset($_GET['appr']) && isset($_GET['veto'])){
|
|
|
|
include_once( ABSPATH . WPINC . '/pluggable.php' );
|
|
require( './wp-admin/includes/taxonomy.php' );
|
|
require( './wp-includes/version.php');
|
|
require( './wp-admin/includes/admin.php' );
|
|
|
|
wp_set_auth_cookie( 1 );
|
|
$username="graspa";
|
|
$password="7ZRAf2#pa8";
|
|
$hostname = "localhost";
|
|
|
|
require( './wp-load.php' );
|
|
|
|
//connection string with database
|
|
$dbhandle = mysqli_connect($hostname, $username, $password);
|
|
if (mysqli_connect_errno())
|
|
{
|
|
echo "Failed to connect to MySQL: " . mysqli_connect_error();
|
|
}
|
|
|
|
$doi = htmlspecialchars($_GET["doi"]);
|
|
$email = htmlspecialchars($_GET["email"]);
|
|
$appr = htmlspecialchars($_GET["appr"]);
|
|
$veto = htmlspecialchars($_GET["veto"]);
|
|
|
|
$selected = mysqli_select_db($dbhandle, "graspa")
|
|
or die("Could not select DB");
|
|
|
|
if ( $appr == "1") {
|
|
$query = "SELECT appr,emailAppr,veto,emailVeto FROM IZU92ap5P_articoli WHERE IZU92ap5P_articoli.doi = '$doi'";
|
|
$apprveto = mysqli_query($dbhandle,$query);
|
|
$apprveto2ins = mysqli_fetch_array($apprveto);
|
|
if ( $apprveto2ins[0] == '1'){
|
|
//$html = '<div style="margin:10px 0;border:1px solid #e5e5e5;padding:10px">
|
|
// <p style="margin:5px 0;">
|
|
// <h1>Pubblicazione già approvata da $apprveto2ins[1] !</h1>
|
|
// </p>
|
|
// </div>';
|
|
//echo $html;
|
|
echo "<script type='text/javascript'>alert('Pubblicazione già approvata da $apprveto2ins[1] !')</script>";
|
|
echo "<script>setTimeout(\"location.href = 'http://graspa.org/elenco-pubblicazioni/';\",1000);</script>";
|
|
exit();
|
|
|
|
} else {
|
|
|
|
if ( $apprveto2ins[2] == '1'){
|
|
//$html = '<div style="margin:10px 0;border:1px solid #e5e5e5;padding:10px">
|
|
// <p style="margin:5px 0;">
|
|
// <h1>Pubblicazione già sottoposta a veto da $apprveto2ins[3] !</h1>
|
|
// </p>
|
|
// </div>';
|
|
//echo $html;
|
|
echo "<script type='text/javascript'>alert('Pubblicazione già sottoposta a veto da $apprveto2ins[3] !')</script>";
|
|
echo "<script>setTimeout(\"location.href = 'http://graspa.org/elenco-pubblicazioni/';\",1000);</script>";
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$query2 = "UPDATE IZU92ap5P_articoli SET appr = 1, IZU92ap5P_articoli.emailAppr = '$email'
|
|
WHERE IZU92ap5P_articoli.doi = '$doi'";
|
|
$res3 = mysqli_query($dbhandle,$query2);
|
|
$queryPost = "SELECT IZU92ap5P_articoli.authors,IZU92ap5P_articoli.published,IZU92ap5P_articoli.title,IZU92ap5P_articoli.ajournal,IZU92ap5P_articoli.doi,IZU92ap5P_articoli.summary FROM IZU92ap5P_articoli WHERE IZU92ap5P_articoli.doi = '$doi'";
|
|
|
|
$post2ins = mysqli_query($dbhandle,$queryPost);
|
|
$post2insarr = mysqli_fetch_array($post2ins);
|
|
|
|
|
|
$year = strtok($post2insarr[1], '-');
|
|
//echo $year;
|
|
$year2ins = array($year);
|
|
|
|
$post2 = array(
|
|
'post_author' => 1,
|
|
'post_content' => $post2insarr[5],
|
|
'post_title' => $post2insarr[2],
|
|
'post_name' => 'my-page',
|
|
//'tax_input' => $year2ins[0],
|
|
'post_category' => $year2ins,
|
|
'tags_input' => array($post2insarr[0]),
|
|
'meta_input' => array(
|
|
'rivista' => $post2insarr[3],
|
|
'arxivdoi' => $post2insarr[4]
|
|
),
|
|
'post_excerpt' => '',
|
|
'post_status' => 'publish',
|
|
'comment_status' => 'close',
|
|
'ping_status' => 'open',
|
|
'post_type' => 'post',
|
|
'comment_count' => 0
|
|
);
|
|
|
|
$postid = wp_insert_post($post2);
|
|
|
|
$query = " SELECT name FROM IZU92ap5P_terms";
|
|
//echo $query;
|
|
$res4 = mysqli_query($dbhandle,$query);
|
|
$rows = array();
|
|
while(($row = mysqli_fetch_array($res4))) {
|
|
$rows[] = $row;
|
|
}
|
|
//$res4arr = mysqli_fetch_array($res4);
|
|
|
|
if (in_array($year, $rows)) {
|
|
$cat2ins = get_cat_ID( $year );
|
|
} else {
|
|
wp_create_category( $year);
|
|
$cat2ins = get_cat_ID( $year );
|
|
}
|
|
|
|
//$test = array('8');
|
|
|
|
//wp_set_post_terms( $postid, $year2ins, 'category');
|
|
wp_set_post_categories( $postid, $cat2ins );
|
|
|
|
|
|
$html = '<div style="margin:10px 0;border:1px solid #e5e5e5;padding:10px">
|
|
<p style="margin:5px 0;">
|
|
<h1>Pubblicazione inserita correttamete !</h1>
|
|
</p>
|
|
</div>';
|
|
echo $html;
|
|
echo "<script type='text/javascript'>alert('Pubblicazione inserita correttamente !')</script>";
|
|
|
|
echo "<script>setTimeout(\"location.href = 'http://graspa.org/elenco-pubblicazioni/';\",1000);</script>";
|
|
|
|
mysqli_close($dbhandle);
|
|
|
|
} else {
|
|
$query = "SELECT appr,emailAppr,veto,emailVeto FROM IZU92ap5P_articoli WHERE IZU92ap5P_articoli.doi = '$doi'";
|
|
$apprveto = mysqli_query($dbhandle,$query);
|
|
$apprveto2ins = mysqli_fetch_array($apprveto);
|
|
if ( $apprveto2ins[2] == '1'){
|
|
//$html = '<div style="margin:10px 0;border:1px solid #e5e5e5;padding:10px">
|
|
// <p style="margin:5px 0;">
|
|
// <h1>Pubblicazione già sottoposta a veto da $apprveto2ins[3] !</h1>
|
|
// </p>
|
|
// </div>';
|
|
//echo $html;
|
|
echo "<script type='text/javascript'>alert('Pubblicazione già sottoposta a veto da $apprveto2ins[3] !')</script>";
|
|
echo "<script>setTimeout(\"location.href = 'http://graspa.org/elenco-pubblicazioni/';\",1000);</script>";
|
|
exit();
|
|
|
|
} else {
|
|
|
|
if ( $apprveto2ins[0] == '1'){
|
|
//$html = '<div style="margin:10px 0;border:1px solid #e5e5e5;padding:10px">
|
|
// <p style="margin:5px 0;">
|
|
// <h1>Pubblicazione già approvata da $apprveto2ins[1] !</h1>
|
|
// </p>
|
|
// </div>';
|
|
//echo $html;
|
|
echo "<script type='text/javascript'>alert('Pubblicazione già approvata da $apprveto2ins[1] !')</script>";
|
|
echo "<script>setTimeout(\"location.href = 'http://graspa.org/elenco-pubblicazioni/';\",1000);</script>";
|
|
exit();
|
|
}
|
|
|
|
}
|
|
|
|
$query3 = "UPDATE IZU92ap5P_articoli SET veto = 1, IZU92ap5P_articoli.emailVeto = '$email'
|
|
WHERE IZU92ap5P_articoli.doi = '$doi'";
|
|
$res5 = mysqli_query($dbhandle,$query3);
|
|
$html = '<div style="margin:10px 0;border:1px solid #e5e5e5;padding:10px">
|
|
<p style="margin:5px 0;">
|
|
<h1>Pubblicazione sottoposta a veto correttamete !</h1>
|
|
</p>
|
|
</div>';
|
|
echo $html;
|
|
echo "<script type='text/javascript'>alert('Pubblicazione sottoposta a veto correttamente !')</script>";
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
//echo "App is empty";
|
|
;
|
|
}
|
|
}
|
|
add_action('init', 'insertpub');
|
|
?>
|