Skip to content

Instantly share code, notes, and snippets.

@dg01d
Last active October 18, 2017 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dg01d/d90b00b733b4cec7817bc15b69f91651 to your computer and use it in GitHub Desktop.
Save dg01d/d90b00b733b4cec7817bc15b69f91651 to your computer and use it in GitHub Desktop.
<?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