Guest User

Untitled

a guest
Dec 2nd, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. <?php
  2. #init :D
  3. $branch_full = explode("//",$_POST["ref"]);
  4. $branch = $branch_full[sizeof($branch_full) -1];
  5. $messages = $_POST["messages"];
  6. $project_PWD = explode("//", $_POST["folder"]);
  7. $project = str_replace(".git", "", $project_PWD[sizeOf($project_PWD) -1]);
  8.  
  9.  
  10. #setting up the connection
  11. $dbconn = pg_connect("host=localhost dbname=SunBird user=commitAdd")
  12. or die('Could not connect: ' . pg_last_error()); #password=foo
  13.  
  14. $query_begining = "INSERT INTO commits VALUES (";
  15. $query_ending = ");";
  16.  
  17. $values = getMessages($messages);
  18.  
  19. for ( $i = 1; $i < sizeof($values); $i++)
  20. {
  21. pg_send_query($dbconn, $query_begining."\'".$project."\',\'".$branch."\',\'".$values[$i]);
  22. }
  23.  
  24. pg_close($dbconn);
  25.  
  26. function getMessages($msg)
  27. {
  28. $msgs = explode("Author:", $msg);
  29. $count = 0;
  30. $retur = array();
  31. foreach($msgs as $Msg)
  32. {
  33. $tmpLines = explode('\n', $Msg);
  34. $tmp = "\'".str_replace("commit ", "", $tmpLines[0])."\'".",\'".str_replace("Author: ", "", $tmpLines[1])."\'".",\'".str_replace("Date: ", "", $tmpLines[2])."\'".",\'";
  35. $tmp2 = "";
  36. for( $i = 3; $i < sizeOf(tmpLines); $i++)
  37. {
  38. $tmp2 .= str_replace("\n", "<br />", $tmpLines[i]);
  39. }
  40. $retur[$count] = $tmp.$tmp2."\'";
  41. $count += 1;
  42. }
  43. return $retur;
  44. }
  45.  
  46. function beginsWith($str, $sub) {
  47. return (strncmp($str, $sub, strlen($sub)) == 0);
  48. }
  49.  
  50. ?>
Add Comment
Please, Sign In to add comment