diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5e48310 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +./log/superdesk.txt diff --git a/autoload.php b/autoload.php index cda2b69..6cb68e6 100644 --- a/autoload.php +++ b/autoload.php @@ -3,9 +3,9 @@ require_once '../../../wp-load.php'; $json = file_get_contents('php://input'); -//$json = file_get_contents('log.txt'); +//$json = file_get_contents('./log/superdesk.txt'); -file_put_contents('log.txt', $json . "\n\n", FILE_APPEND); +file_put_contents('./log/superdesk.txt', $json . "\n\n", FILE_APPEND); $obj = json_decode($json, true); diff --git a/log/superdesk.txt b/log/superdesk.txt new file mode 100644 index 0000000..e69de29 diff --git a/superdeskPublisher.php b/superdeskPublisher.php index 21c26b3..438eaa1 100644 --- a/superdeskPublisher.php +++ b/superdeskPublisher.php @@ -86,10 +86,11 @@ function saveAttachment($picture, $post_ID, $caption, $alt) { $filenameQ = explode("/", $picture['renditions']['original']['media']); $filename = $filenameQ[count($filenameQ) - 1]; - saveFile($picture['renditions']['original']['href'], wp_upload_dir()['path'] . "/" . $filename); + $uploadDir = wp_upload_dir(); + saveFile($picture['renditions']['original']['href'], $uploadDir['path'] . "/" . $filename); $attachment = array( - 'guid' => wp_upload_dir()['url'] . '/' . basename($filename), + 'guid' => $uploadDir['url'] . '/' . basename($filename), 'post_mime_type' => $picture['mimetype'], 'post_title' => $caption, 'post_content' => '', @@ -101,7 +102,7 @@ function saveAttachment($picture, $post_ID, $caption, $alt) { require_once( ABSPATH . 'wp-admin/includes/image.php' ); - $attach_data = wp_generate_attachment_metadata($attach_id, wp_upload_dir()['path'] . "/" . $filename); + $attach_data = wp_generate_attachment_metadata($attach_id, $uploadDir['path'] . "/" . $filename); wp_update_attachment_metadata($attach_id, $attach_data); set_post_thumbnail($post_ID, $attach_id); @@ -112,6 +113,7 @@ function saveAttachment($picture, $post_ID, $caption, $alt) { function savePicture($localPath, $postId, $oldSrc, $associations, $alt) { $filenameQ = explode("/", $localPath); $filename = $filenameQ[count($filenameQ) - 1]; + $uploadDir = wp_upload_dir(); $name = null; $mimeType = null; @@ -135,7 +137,7 @@ function savePicture($localPath, $postId, $oldSrc, $associations, $alt) { } $attachment = array( 'guid' => $localPath, - 'post_mime_type' => $mimeType == null ? mime_content_type(wp_upload_dir()['path'] . "/" . $filename) : $mimeType, + 'post_mime_type' => $mimeType == null ? mime_content_type($uploadDir['path'] . "/" . $filename) : $mimeType, 'post_title' => $caption, 'post_content' => '', 'post_excerpt' => $caption, @@ -147,7 +149,7 @@ function savePicture($localPath, $postId, $oldSrc, $associations, $alt) { require_once( ABSPATH . 'wp-admin/includes/image.php' ); - $attach_data = wp_generate_attachment_metadata($attach_id, wp_upload_dir()['path'] . "/" . $filename); + $attach_data = wp_generate_attachment_metadata($attach_id, $uploadDir['path'] . "/" . $filename); wp_update_attachment_metadata($attach_id, $attach_data); set_post_thumbnail($postId, $attach_id); @@ -196,10 +198,11 @@ function generate_caption_image($media) { } function embed_src($src) { + $uploadDir = wp_upload_dir(); $filename = sha1($src); - saveFile($src, wp_upload_dir()['path'] . "/" . $filename); - return wp_upload_dir()['url'] . "/" . $filename; + saveFile($src, $uploadDir['path'] . "/" . $filename); + return $uploadDir['url'] . "/" . $filename; } class Image {