Initial code drop
This commit is contained in:
98
autoload.php
Normal file
98
autoload.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
require_once '../../../wp-load.php';
|
||||
|
||||
$json = file_get_contents('php://input');
|
||||
//$json = file_get_contents('log.txt');
|
||||
|
||||
//file_put_contents('log.txt', $json . "\n\n", FILE_APPEND);
|
||||
$obj = json_decode($json, true);
|
||||
|
||||
if ($obj['type'] == 'composite') {
|
||||
|
||||
$settings = get_option('mvp_settings');
|
||||
|
||||
if ($obj['pubstatus'] == 'usable') {
|
||||
$content = $obj['description_html'] . "<!--more-->" . $obj['body_html'];
|
||||
|
||||
$guid = wp_strip_all_tags($obj['guid']);
|
||||
|
||||
$sync = $wpdb->get_row("SELECT post_id FROM " . $wpdb->prefix . DB_TABLE_SYNC_POST . " WHERE guid = '" . $guid . "'");
|
||||
|
||||
if ($sync) {
|
||||
$edit_post = array(
|
||||
'ID' => $sync->post_id,
|
||||
'post_title' => wp_strip_all_tags($obj['headline']),
|
||||
'post_name' => wp_strip_all_tags($obj['headline']),
|
||||
'post_content' => $content,
|
||||
'post_content_filtered' => $content
|
||||
);
|
||||
|
||||
wp_update_post($edit_post);
|
||||
} else {
|
||||
$postarr = array(
|
||||
'post_title' => wp_strip_all_tags($obj['headline']),
|
||||
'post_name' => wp_strip_all_tags($obj['headline']),
|
||||
'post_content' => $content,
|
||||
'post_content_filtered' => $content,
|
||||
'post_author' => (int) $settings['author'],
|
||||
'post_status' => $settings['status'],
|
||||
'post_category' => $settings['category'],
|
||||
);
|
||||
|
||||
$post_ID = wp_insert_post($postarr, true);
|
||||
|
||||
$table_name = $wpdb->prefix . DB_TABLE_SYNC_POST;
|
||||
|
||||
$wpdb->insert(
|
||||
$table_name, array(
|
||||
'post_id' => $post_ID,
|
||||
'guid' => wp_strip_all_tags($obj['guid']),
|
||||
'time' => current_time('mysql')
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
if ($obj['associations']['featuremedia'] && $obj['associations']['featuremedia']['type'] == 'picture') {
|
||||
/* save featured media */
|
||||
$picture = $obj['associations']['featuremedia'];
|
||||
|
||||
$filenameQ = explode("/", $picture['renditions']['original']['media']);
|
||||
$filename = $filenameQ[1];
|
||||
saveFile($picture['renditions']['original']['href'], wp_upload_dir()['path'] . "/" . $filename);
|
||||
|
||||
$attachment = array(
|
||||
'guid' => wp_upload_dir()['url'] . '/' . basename($filename),
|
||||
'post_mime_type' => $picture['mimetype'],
|
||||
'post_title' => preg_replace('/\.[^.]+$/', '', basename($picture['headline'])),
|
||||
'post_content' => '',
|
||||
'post_status' => 'inherit'
|
||||
);
|
||||
|
||||
$attach_id = wp_insert_attachment($attachment, date("Y") . "/" . date("m") . "/" . $filename, $post_ID);
|
||||
|
||||
require_once( ABSPATH . 'wp-admin/includes/image.php' );
|
||||
|
||||
$attach_data = wp_generate_attachment_metadata($attach_id, wp_upload_dir()['path'] . "/" . $filename);
|
||||
|
||||
wp_update_attachment_metadata($attach_id, $attach_data);
|
||||
set_post_thumbnail($post_ID, $attach_id);
|
||||
}
|
||||
}
|
||||
} elseif ($obj['pubstatus'] == 'canceled') {
|
||||
/* remove article */
|
||||
$guid = wp_strip_all_tags($obj['guid']);
|
||||
|
||||
$sync = $wpdb->get_row("SELECT post_id FROM " . $wpdb->prefix . DB_TABLE_SYNC_POST . " WHERE guid = '" . $guid . "'");
|
||||
|
||||
if ($sync) {
|
||||
|
||||
$edit_post = array(
|
||||
'ID' => $sync->post_id,
|
||||
'post_status' => 'draft'
|
||||
);
|
||||
|
||||
wp_update_post($edit_post);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user