Ejemplo n.º 1
0
    $s = preg_replace('/(\\r?\\n){2,}/', '</p><p>', $s);
    $s = preg_replace('/(\\r?\\n)+/', '<br>', $s);
    return '<p>' . $s . '</p>';
}
$key = makeKey($_POST['name']);
$icon = $_POST['icon'];
$label = $_POST['name'];
$countries = makeYamlArray($_POST['countries']);
$location = sprintf('[%s]', $_POST['location']);
$content = textToHTML($_POST['description']);
$url = $_POST['website'];
$coins = makeYamlArray($_POST['coins']);
$file = './data/services.yaml';
$current = file_get_contents($file);
$yaml = "\n{$key}:\n  label: {$label}\n  icon: {$icon}\n  countries: {$countries}\n  location: {$location}\n  url: {$url}\n  content: |\n    {$content}\n  coins: {$coins}\n";
try {
    $branchname = 'update/' . time() . '_' . $key;
    $git = new Git();
    $git->createNewBranch($branchname);
    $fileInfo = $git->getFileInformation('master');
    $sha = $fileInfo->sha;
    $newFile = base64_encode($current . PHP_EOL . $yaml);
    $git->updateFile($branchname, $sha, $newFile);
    $git->sendPR($branchname);
} catch (Exception $e) {
    echo json_encode(array("error" => "couldNotPublishToGit"));
    return;
}
$_SESSION['lastUpdate'] = time();
echo json_encode(array("great" => "success"));
return;