Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Commit

Permalink
Add modal form to submit the Steemit Contribution Link
Browse files Browse the repository at this point in the history
Add functions IsSteemLink() and ParseSteemLink() to get a contribution post's details
Add "New Contribution" sub-page to check the details (will not yet submit the details to the DB)
  • Loading branch information
dimitrisp2 committed Oct 22, 2018
1 parent d2f8fb3 commit ae6f721
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 3 deletions.
60 changes: 57 additions & 3 deletions contributions.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,29 @@
$page = "Contribution Search";

$pagecontent = GetContributionList($translator, $project, $fromdate, $todate, $voteutopian, $reviewed);

} else if ($action == "add") {
$page = "Add Contribution";
$returndata = IsSteemLink($_POST['steemlink']);
if(($_POST['steemlink'] != NULL) && (filter_var($_POST['steemlink'], FILTER_VALIDATE_URL) !== false) && is_array($returndata)) {
$parselink = ParseSteemLink($returndata);
if (is_array($parselink)) {
$pagecontent = "<i>Please verify if the contribution details are correct and press \"Submit\" to continue</i>";
$author = $parselink['author'];
$partno = $parselink['part'];
$wordcount = $parselink['words'];
$projectname = $parselink['project'];
} else {
$pagecontent = "<i>Unable to parse the post. Please try again later or fill the details below and press \"Submit\" to continue</i>";
$author = "";
$partno = "";
$wordcount = "";
$projectname = "";
}
//print_r($parselink);
$pagecontent .= "<form action=\"contributions.php?a=processadd\" method=\"post\"><div class=\"form-group row\"><label for=\"author\" class=\"col-4 col-form-label\">Author</label> <div class=\"col-8\"><input id=\"author\" name=\"author\" type=\"text\" aria-describedby=\"authorHelpBlock\" required=\"required\" class=\"form-control here\" value=\"$author\"> <span id=\"authorHelpBlock\" class=\"form-text text-muted\">Steem Username without @</span></div></div><div class=\"form-group row\"><label for=\"partno\" class=\"col-4 col-form-label\">Part Number</label> <div class=\"col-8\"><input id=\"partno\" name=\"partno\" placeholder=\"20\" type=\"text\" required=\"required\" class=\"form-control here\" value=\"$partno\"></div></div><div class=\"form-group row\"><label for=\"wordcount\" class=\"col-4 col-form-label\">Word Count</label> <div class=\"col-8\"><input id=\"wordcount\" name=\"wordcount\" placeholder=\"1251\" type=\"text\" required=\"required\" class=\"form-control here\" value=\"$wordcount\"></div></div><div class=\"form-group row\"><label for=\"projectname\" class=\"col-4 col-form-label\">Project</label> <div class=\"col-8\"><input id=\"projectname\" name=\"projectname\" placeholder=\"ReactOS\" type=\"text\" required=\"required\" class=\"form-control here\" value=\"$projectname\"></div></div> <div class=\"form-group row\"><div class=\"offset-4 col-8\"><button name=\"submit\" type=\"submit\" class=\"btn btn-primary\">Submit</button></div></div></form>";
} else {
$pagecontent = "The input is not a valid link, or is empty. Please try again by specifying a Steemit contribution link.";
}
} else {

}
Expand All @@ -37,7 +59,7 @@
<div class="container">
<div class="row">
<div class="col-lg-8 mx-auto">
<a href="#" data-toggle="modal" data-target="#searchfilters">Filter Results</a>
<p><a href="#" data-toggle="modal" data-target="#searchfilters">Filter Results</a> | <a href="#" data-toggle="modal" data-target="#addcontribution">Add Contribution</a></p>
<?php echo $pagecontent; ?>
</div>
</div>
Expand All @@ -49,7 +71,7 @@
$tcsv = GetTranslatorsCSV();
$thtml = ConvertArray2HTMLOptions(explode(",", $tcsv), "#", "translator", NULL, TRUE);
?>
<!-- Modal -->
<!-- Modal Search Filters-->
<div id="searchfilters" class="modal fade" role="dialog">
<div class="modal-dialog">

Expand Down Expand Up @@ -117,6 +139,38 @@

</div>
</div>

<!-- Modal Add Contribution -->
<div id="addcontribution" class="modal fade" role="dialog">
<div class="modal-dialog">

<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Add Contribution</h4>
<button type="button" class="close" data-dismiss="modal">&times;</button>
</div>
<div class="modal-body">
<p><form action="contributions.php?a=add" method="post">
<div class="form-group row">
<label for="steemlink" class="col-4 col-form-label">Steemit.com Link</label>
<div class="col-8">
<input id="steemlink" name="steemlink" type="text" aria-describedby="todateHelpBlock" class="form-control here">
<span id="steemlinkHelpBlock" class="form-text text-muted">https://steemit.com/utopian-io/@username/post</span>
</div>
</div>
</p>
</div>
<div class="modal-footer">
<button name="submit" type="submit" class="btn btn-primary">Submit</button></form>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>

</div>
</div>


<?php
include("common/foot.php");
?>
Expand Down
73 changes: 73 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

$teamname = "Greek";
$languagename = "Greek";

//////////////////
// MySQL Config //
Expand Down Expand Up @@ -299,6 +300,78 @@ function GetContributionList($user = NULL, $project = NULL, $from = NULL, $to =
}
}

function IsSteemLink($url) {
$urlcomponents = parse_url($url);
//print_r($urlcomponents);
if (strpos($urlcomponents['host'], 'steemit.com') !== false) {
//echo "is steemit link";
} else {
return FALSE;
}

$pathcomponents = explode("/", ltrim($urlcomponents['path'], "/"));
//print_r($pathcomponents);
// $pathcomponents[0] is the tag
// $pathcomponents[1] is the username
// $pathcomponents[2] is the post permlink

if ($pathcomponents[0] != "utopian-io") {
return FALSE;
} else {
$firsttag = $pathcomponents[0];
}


if (strncmp($pathcomponents[1], "@", 1) !== 0) {
return FALSE;
} else {
$data['username'] = $pathcomponents[1];
}

$data['permlink'] = $pathcomponents[2];

return $data;
}

function ParseSteemLink($postdata) {
// Add username to the $details array, as it will be returned with the rest of the data.
$details['author'] = ltrim($postdata['username'], "@");
$url = "https://api.steemjs.com/get_content?author=".$details['author']."&permlink=".$postdata['permlink'];

$json = file_get_contents($url);
//echo $json;

$postdetails = json_decode($json, TRUE);

//echo $postdetails['post']['title'];
// Valid title formats:
// "Project name XX Translation - Part YY (~ZZ words)"
// "Project name XX Translation | Part YY | ~ZZ Words
// where XX is the language name, YY is the part number and ZZ is the word count.
$title = $postdetails['title'];
if ((strpos($title, '-') !== false) || (strpos($title, '|') !== false)) {
$titlextr = explode($GLOBALS['languagename'], $title, 2);
// $titlextr[0] = Project name
// $titlextr[1] = Rest of the title without language name
$project = rtrim($titlextr[0]);
preg_match_all('/\d+/i', $title, $contrnumbers);
// $contrnumbers[0] = Part number
// $contrnumbers[1] = Word count
$partno = $contrnumbers[0][0];
$wordcount = $contrnumbers[0][1];
//echo "Project: " . $project . ", Part: " . $partno . ", Wordcount: " . $wordcount;
$details['project'] = $project;
$details['part'] = $partno;
$details['words'] = $wordcount;

$details['permlink'] = $postdetails['permlink'];
$details['fulltitle'] = $postdetails['title'];
return $details;
} else {
return FALSE;
}
}

///////////
// LOGIN //
///////////
Expand Down

0 comments on commit ae6f721

Please sign in to comment.