Plugin per caricamento pubblicazioni
Inserisce e controlla che le pubblicazioni inserire nelle mail agli utenti non siano già state approvate o rifiutate Es. url http://localhost/test/?email=alessandro.fasso@unibg.it&doi=http://arxiv.org/abs/hep-ph/0412178v1&appr=1&veto=0
This commit is contained in:
+193
@@ -0,0 +1,193 @@
|
||||
<?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="root";
|
||||
$password="vpsad24068";
|
||||
$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, "wptest")
|
||||
or die("Could not select DB");
|
||||
|
||||
if ( $appr == "1") {
|
||||
$query = "SELECT appr,emailAppr,veto,emailVeto FROM wp_articoli WHERE wp_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://localhost/test/index.php/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à approvata da $apprveto2ins[3] !')</script>";
|
||||
echo "<script>setTimeout(\"location.href = 'http://localhost/test/index.php/pubblicazioni/';\",1000);</script>";
|
||||
exit();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$query = "UPDATE wp_articoli SET appr = 1, wp_articoli.emailAppr = '$email'
|
||||
WHERE wp_articoli.doi = '$doi'";
|
||||
$res3 = mysqli_query($dbhandle,$query);
|
||||
$queryPost = "SELECT wp_articoli.authors,wp_articoli.published,wp_articoli.title,wp_articoli.ajournal,wp_articoli.doi,wp_articoli.summary FROM wp_articoli WHERE wp_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 wp_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://localhost/test/index.php/pubblicazioni/';\",1500);</script>";
|
||||
|
||||
mysqli_close($dbhandle);
|
||||
|
||||
} else {
|
||||
$query = "SELECT appr,emailAppr,veto,emailVeto FROM wp_articoli WHERE wp_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[1] !')</script>";
|
||||
echo "<script>setTimeout(\"location.href = 'http://localhost/test/index.php/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://localhost/test/index.php/pubblicazioni/';\",1000);</script>";
|
||||
exit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$query = "UPDATE wp_articoli SET veto = 1, wp_articoli.emailVeto = '$email'
|
||||
WHERE wp_articoli.doi = '$doi'";
|
||||
$res5 = mysqli_query($dbhandle,$query);
|
||||
$html = '<div style="margin:10px 0;border:1px solid #e5e5e5;padding:10px">
|
||||
<p style="margin:5px 0;">
|
||||
<h1>Pubblicazione sottooposta 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');
|
||||
?>
|
||||
Reference in New Issue
Block a user