Last active
October 18, 2017 18:53
-
-
Save dg01d/d90b00b733b4cec7817bc15b69f91651 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function array_replace_keys(array $array, array $keys, $filter=false) | |
{ | |
$newArray = array(); | |
foreach($array as $key => $value) { | |
if (isset($keys[$key])) { | |
$newArray[$keys[$key]] = $value; | |
} elseif (!$filter) { | |
$newArray[$key] = $value; | |
} | |
} | |
return $newArray; | |
} | |
function decode_input(string $textFile, array $mfArray) | |
{ | |
$topArray = explode("\n\n", $textFile); | |
$jsonArray = json_decode($topArray[0], true); | |
$jsonArray["content"] = $topArray[1]; | |
$newArray = array(); | |
foreach ($jsonArray as $key => $value) { | |
if (!is_array($value)) { | |
$value = [$value]; | |
} | |
$newArray[$key] = $value; | |
} | |
$newArray = array_replace_keys($newArray, $mfArray, false); | |
return $newArray; | |
} | |
function recode_output(array $array, array $mfArray) | |
{ | |
$postArray = array(); | |
$singles = array("name", "published", "slug", "content"); | |
foreach ($array as $key => $value) { | |
if (in_array($key, $singles)) { | |
$value = $value[0]; | |
} | |
$postArray[$key] = $value; | |
} | |
$postArray = array_replace_keys($postArray, $mfArray, false); | |
return $postArray; | |
} | |
$mfArray = array( | |
"date" => "published", | |
"tags" => "category", | |
"replyto" => "in-reply-to", | |
"link" => "bookmark-of", | |
"title" => "name" | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment