Files
2018-08-02 19:00:59 +02:00

129 lines
3.7 KiB
PHP

<?php
$username="root";
$password="vpsad24068";
$hostname = "localhost";
define( 'SHORTINIT', true );
require( './wp-load.php' );
// require( 'wp-includes/post.php' );
// require( 'wp-includes/post-template.php' );
// require( 'wp-includes/revision.php' );
// require( 'wp-includes/class-wp-post.php' );
// require( 'wp-includes/user.php' );
// require( 'wp-includes/taxonomy.php' );
//connection string with database
$dbhandle = mysqli_connect($hostname, $username, $password);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
inserisci_pubblicazioni();
//echo 'Hello ' . htmlspecialchars($_GET["email"]) . htmlspecialchars($_GET["doi"]) . '!';
$doi = htmlspecialchars($_GET["doi"]);
$email = htmlspecialchars($_GET["email"]);
$selected = mysqli_select_db($dbhandle, "wptest")
or die("Could not select DB");
$query = "UPDATE wp_articoli SET appr = 1, wp_articoli.emailAppr = '$email'
WHERE wp_articoli.doi = '$doi'";
echo $query;
$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'";
echo $queryPost;
$post2ins = mysqli_query($dbhandle,$queryPost);
$post2insarr = mysqli_fetch_array($post2ins);
//$content = $post2insarr[5];
//$title = $post2insarr[2];
$post = array(
'post_author' => 1,
'post_content' => $post2insarr[5],
'post_title' => $post2insarr[2],
'post_name' => 'my-page',
'post_excerpt' => '',
'post_status' => 'publish',
'comment_status' => 'close',
'ping_status' => 'open',
'post_type' => 'page',
'comment_count' => 0
);
// $year = strtok($post2insarr[1], '-');
// echo $year;
// $post2 = array(
// 'post_author' => 1,
// 'post_content' => $post2insarr[5],
// 'post_title' => $post2insarr[2],
// 'post_name' => 'my-page',
// 'post_category' => array($year),
// 'tags_input' => array($post2insarr[0]),
// 'meta_input' => array(
// 'ajournal' => $post2insarr[3],
// 'doi' => $post2insarr[4]
// ),
// 'post_excerpt' => '',
// 'post_status' => 'publish',
// 'comment_status' => 'close',
// 'ping_status' => 'open',
// 'post_type' => 'page',
// 'comment_count' => 0
// );
//wp_insert_post($post2);
$wpdb->insert(
'wp_posts',
$post,
array( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ));
$postID = $wpdb->insert_id;
echo $postID;
$year = strtok($post2insarr[1], '-');
echo $year;
$wpdb->update( 'wp_posts',
array('comment_status'=> 'open',), // SET
array('ID'=> $postID,) // WHERE
);
$wpdb->update( 'wp_postmeta',
array(
'meta_value' => $post2insarr[3],
'meta_key' => 'ajournal'
), // SET
array('ID'=> $postID,) // WHERE
);
$wpdb->update( 'wp_postmeta',
array(
'meta_value' => $post2insarr[4],
'meta_key' => 'arxivdoi'
), // SET
array('ID'=> $postID,) // WHERE
);
//$item->published = date("Y",strtotime($item->published));
//recupero l'anno di pubblicazione da inserire poi come categoria
$year = strtok($post2insarr[1], '-');
echo $year;
// $current_post = $postID;
// if($current_post){
// setup_postdata( $GLOBALS['post'] =& $post_object );
// $post = $current_post;
// update_post_meta( "$postID", "ajournal", "$post2insarr[3]" );
// } else {
// echo "cippa !";
// }
//wp_set_post_tags( 50, array( 'awesome' ), true );
//update_post_meta( "$postID", "ajournal", "$post2insarr[3]" );
// update_post_meta( $postID, 'doi', $post2insarr[4] );
// wp_set_post_tags( $postID, $post2insarr[0] ) ;
// wp_set_post_categories( $postID, $year );
mysqli_close($dbhandle);
?>