add back end PHP code to the repository

This commit is contained in:
Branislav Stojkovic
2016-10-22 12:45:49 +02:00
parent 4738a23fc6
commit 83e7c0b077
14 changed files with 835 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>diylc-server-api</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
+64
View File
@@ -0,0 +1,64 @@
<?php
$name=$_REQUEST["username"];
$pwd=$_REQUEST["password"];
$email=$_REQUEST["email"];
$website=$_REQUEST["website"];
$website=$_REQUEST["bio"];
if (!$name) {
echo "{\"string\":Username not provided.}";
exit;
}
if (!$pwd) {
echo "{\"string\":Password not provided.}";
exit;
}
if (strlen($pwd) < 6) {
echo "{\"string\":Password must be at least 6 characters long.}";
exit;
}
if (!$email) {
echo "{\"string\":E-mail not provided.}";
exit;
}
$pwd = hash("ripemd160", $pwd);
// Load help class
require_once("properties.php");
// Load properties
$dbProperties = new Properties();
$propertiesFile = fopen("db.properties", "rb");
$dbProperties->load($propertiesFile);
// Connect to the DB
$username=$dbProperties->getProperty("user");
$password=$dbProperties->getProperty("pass");
$database=$dbProperties->getProperty("db");
$mysqli = new mysqli(localhost,$username,$password,$database);
// Run the query
$sql= "SELECT name FROM diylc_user WHERE LOWER(name) = LOWER('".$name."')";
if (!$result = $mysqli->query($sql)) {
echo "{\"string\":Error}";
exit;
}
$num = $num = $result->num_rows;
if ($num === 0) {
$sql= "INSERT INTO diylc_user (name, password, email, website, bio) VALUES ('".addslashes($name)."', '".$pwd."', '".addslashes($email)."', '".addslashes($website)."', '".addslashes($bio)."')";
if ($mysqli->query($sql) === TRUE) {
echo "{\"string\":Success}";
} else {
echo "{\"string\":Error}";
}
} else {
echo "{\"string\":User already exists.}";
}
$mysqli->close();
?>
Binary file not shown.

After

Width:  |  Height:  |  Size: 717 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

+55
View File
@@ -0,0 +1,55 @@
[22-Dec-2009 22:17:29] PHP Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';' in /home/diyfever/public_html/diylc/db/project_search.php on line 40
[22-Dec-2009 22:19:40] PHP Fatal error: Call to a member function getProperty() on a non-object in /home/diyfever/public_html/diylc/db/project_search.php on line 15
[23-Dec-2009 11:39:11] PHP Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/diyfever/public_html/diylc/db/downloadProject.php on line 25
[23-Dec-2009 11:39:11] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/diyfever/public_html/diylc/db/downloadProject.php:25) in /home/diyfever/public_html/diylc/db/downloadProject.php on line 28
[23-Dec-2009 11:39:11] PHP Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/diyfever/public_html/diylc/db/downloadProject.php on line 29
[23-Dec-2009 11:39:39] PHP Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/diyfever/public_html/diylc/db/downloadProject.php on line 25
[23-Dec-2009 11:39:39] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/diyfever/public_html/diylc/db/downloadProject.php:25) in /home/diyfever/public_html/diylc/db/downloadProject.php on line 28
[23-Dec-2009 11:39:39] PHP Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/diyfever/public_html/diylc/db/downloadProject.php on line 29
[23-Dec-2009 11:40:46] PHP Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/diyfever/public_html/diylc/db/downloadProject.php on line 25
[23-Dec-2009 11:40:46] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/diyfever/public_html/diylc/db/downloadProject.php:25) in /home/diyfever/public_html/diylc/db/downloadProject.php on line 28
[23-Dec-2009 11:40:46] PHP Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/diyfever/public_html/diylc/db/downloadProject.php on line 29
[10-Oct-2011 11:17:43] PHP Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/diyfever/public_html/diylc/db/downloadProject.php on line 25
[10-Oct-2011 11:17:43] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/diyfever/public_html/diylc/db/downloadProject.php:25) in /home/diyfever/public_html/diylc/db/downloadProject.php on line 28
[10-Oct-2011 11:17:43] PHP Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/diyfever/public_html/diylc/db/downloadProject.php on line 29
[23-Jul-2014 13:13:53 Europe/Belgrade] PHP Warning: mysql_numrows() expects parameter 1 to be resource, boolean given in /home/diyfever/public_html/diylc/db/downloadProject.php on line 25
[23-Jul-2014 13:13:53 Europe/Belgrade] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/diyfever/public_html/diylc/db/downloadProject.php:25) in /home/diyfever/public_html/diylc/db/downloadProject.php on line 28
[23-Jul-2014 13:13:53 Europe/Belgrade] PHP Warning: mysql_result() expects parameter 1 to be resource, boolean given in /home/diyfever/public_html/diylc/db/downloadProject.php on line 29
[14-Oct-2016 12:36:05 Europe/Belgrade] PHP Warning: require_once(properties.php): failed to open stream: No such file or directory in /home/diyfever/public_html/diylc/db/login.php on line 7
[14-Oct-2016 12:36:05 Europe/Belgrade] PHP Fatal error: require_once(): Failed opening required 'properties.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/diyfever/public_html/diylc/db/login.php on line 7
[14-Oct-2016 13:36:44 Europe/Belgrade] PHP Parse error: syntax error, unexpected '}' in /home/diyfever/public_html/diylc/db/projectSearch.php on line 26
[14-Oct-2016 15:32:48 Europe/Belgrade] PHP Parse error: syntax error, unexpected '.' in /home/diyfever/public_html/diylc/db/projectSearch.php on line 30
[14-Oct-2016 16:08:33 Europe/Belgrade] PHP Fatal error: Call to undefined function query() in /home/diyfever/public_html/diylc/db/createUser.php on line 46
[14-Oct-2016 16:09:24 Europe/Belgrade] PHP Fatal error: Call to undefined function query() in /home/diyfever/public_html/diylc/db/createUser.php on line 50
[14-Oct-2016 16:09:53 Europe/Belgrade] PHP Fatal error: Call to undefined function query() in /home/diyfever/public_html/diylc/db/createUser.php on line 52
[14-Oct-2016 16:27:45 Europe/Belgrade] PHP Parse error: syntax error, unexpected ':' in /home/diyfever/public_html/diylc/db/login.php on line 45
[14-Oct-2016 17:50:59 Europe/Belgrade] PHP Fatal error: Call to a member function free() on boolean in /home/diyfever/public_html/diylc/db/login.php on line 50
[14-Oct-2016 17:53:52 Europe/Belgrade] PHP Parse error: syntax error, unexpected 'echo' (T_ECHO) in /home/diyfever/public_html/diylc/db/loginWithToken.php on line 47
[19-Oct-2016 12:45:17 Europe/Belgrade] PHP Parse error: syntax error, unexpected '.' in /home/diyfever/public_html/diylc/db/projectSearch.php on line 83
[19-Oct-2016 12:45:54 Europe/Belgrade] PHP Parse error: syntax error, unexpected '.' in /home/diyfever/public_html/diylc/db/projectSearch.php on line 83
[19-Oct-2016 12:56:27 Europe/Belgrade] PHP Parse error: syntax error, unexpected '}', expecting ',' or ';' in /home/diyfever/public_html/diylc/db/projectSearch.php on line 94
[19-Oct-2016 12:56:35 Europe/Belgrade] PHP Warning: Illegal string offset 'owner' in /home/diyfever/public_html/diylc/db/projectSearch.php on line 84
[19-Oct-2016 12:57:13 Europe/Belgrade] PHP Warning: Illegal string offset 'owner' in /home/diyfever/public_html/diylc/db/projectSearch.php on line 86
[19-Oct-2016 13:44:33 Europe/Belgrade] PHP Parse error: syntax error, unexpected '"</td>' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ';' in /home/diyfever/public_html/diylc/db/projectSearch.php on line 105
[19-Oct-2016 14:15:35 Europe/Belgrade] PHP Parse error: syntax error, unexpected 'right' (T_STRING), expecting ',' or ';' in /home/diyfever/public_html/diylc/db/projectSearch.php on line 106
[19-Oct-2016 14:25:05 Europe/Belgrade] PHP Parse error: syntax error, unexpected 'right' (T_STRING), expecting ',' or ';' in /home/diyfever/public_html/diylc/db/projectSearch.php on line 96
[19-Oct-2016 15:48:00 Europe/Belgrade] PHP Warning: mysql_query(): Access denied for user ''@'localhost' (using password: NO) in /home/diyfever/public_html/diylc/db/upload.php on line 96
[19-Oct-2016 15:48:00 Europe/Belgrade] PHP Warning: mysql_query(): A link to the server could not be established in /home/diyfever/public_html/diylc/db/upload.php on line 96
[19-Oct-2016 15:51:34 Europe/Belgrade] PHP Parse error: syntax error, unexpected ')' in /home/diyfever/public_html/diylc/db/upload.php on line 113
[19-Oct-2016 15:56:04 Europe/Belgrade] PHP Warning: move_uploaded_file(/path/to/your/destination/4.png): failed to open stream: No such file or directory in /home/diyfever/public_html/diylc/db/upload.php on line 120
[19-Oct-2016 15:56:04 Europe/Belgrade] PHP Warning: move_uploaded_file(): Unable to move '/tmp/phpCQK5Bb' to '/path/to/your/destination/4.png' in /home/diyfever/public_html/diylc/db/upload.php on line 120
[19-Oct-2016 15:56:04 Europe/Belgrade] PHP Warning: move_uploaded_file(/path/to/your/destination/4.diy): failed to open stream: No such file or directory in /home/diyfever/public_html/diylc/db/upload.php on line 121
[19-Oct-2016 15:56:04 Europe/Belgrade] PHP Warning: move_uploaded_file(): Unable to move '/tmp/phpCQK5Bb' to '/path/to/your/destination/4.diy' in /home/diyfever/public_html/diylc/db/upload.php on line 121
[19-Oct-2016 15:56:04 Europe/Belgrade] PHP Fatal error: Call to a member function free() on boolean in /home/diyfever/public_html/diylc/db/upload.php on line 131
[19-Oct-2016 15:58:21 Europe/Belgrade] PHP Fatal error: Call to a member function free() on boolean in /home/diyfever/public_html/diylc/db/upload.php on line 131
[19-Oct-2016 16:00:57 Europe/Belgrade] PHP Warning: move_uploaded_file(public_html/diylc/thumbnails7.png): failed to open stream: No such file or directory in /home/diyfever/public_html/diylc/db/upload.php on line 120
[19-Oct-2016 16:00:57 Europe/Belgrade] PHP Warning: move_uploaded_file(): Unable to move '/tmp/php5NzI1v' to 'public_html/diylc/thumbnails7.png' in /home/diyfever/public_html/diylc/db/upload.php on line 120
[19-Oct-2016 16:00:57 Europe/Belgrade] PHP Warning: move_uploaded_file(public_html/diylc/uploads/7.diy): failed to open stream: No such file or directory in /home/diyfever/public_html/diylc/db/upload.php on line 121
[19-Oct-2016 16:00:57 Europe/Belgrade] PHP Warning: move_uploaded_file(): Unable to move '/tmp/phpYopq2O' to 'public_html/diylc/uploads/7.diy' in /home/diyfever/public_html/diylc/db/upload.php on line 121
[19-Oct-2016 16:26:43 Europe/Belgrade] PHP Parse error: syntax error, unexpected '$isJson' (T_VARIABLE) in /home/diyfever/public_html/diylc/api/search.php on line 14
[19-Oct-2016 16:26:55 Europe/Belgrade] PHP Parse error: syntax error, unexpected 'require_once' (T_REQUIRE_ONCE) in /home/diyfever/public_html/diylc/api/search.php on line 43
[19-Oct-2016 16:33:12 Europe/Belgrade] PHP Parse error: syntax error, unexpected '<' in /home/diyfever/public_html/diylc/api/search.php on line 130
[19-Oct-2016 16:33:25 Europe/Belgrade] PHP Parse error: syntax error, unexpected end of file in /home/diyfever/public_html/diylc/api/search.php on line 137
[19-Oct-2016 16:40:41 Europe/Belgrade] PHP Parse error: syntax error, unexpected '&' in /home/diyfever/public_html/diylc/api/search.php on line 131
[22-Oct-2016 10:10:56 Europe/Belgrade] PHP Parse error: syntax error, unexpected end of file in /home/diyfever/public_html/diylc/api/v1/getAvailableCategories.php on line 39
[22-Oct-2016 10:26:50 Europe/Belgrade] PHP Parse error: syntax error, unexpected '"', expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /home/diyfever/public_html/diylc/api/v1/getCategories.php on line 32
+39
View File
@@ -0,0 +1,39 @@
<?php
// Load help class
require_once("properties.php");
// Load properties
$dbProperties = new Properties();
$propertiesFile = fopen("db.properties", "rb");
$dbProperties->load($propertiesFile);
// Connect to the DB
$username=$dbProperties->getProperty("user");
$password=$dbProperties->getProperty("pass");
$database=$dbProperties->getProperty("db");
$mysqli = new mysqli(localhost,$username,$password,$database);
// Run the query
$sql= "SELECT name FROM diylc_category ORDER BY sort_order";
if (!$result = $mysqli->query($sql)) {
echo "{\"string\":Error}";
exit;
}
echo "{\"list\":{\"java.lang.String\":[";
$i=0;
while ($row = $result->fetch_assoc()) {
if ($i>0)
echo ",";
echo "\"".$row["name"]."\"";
$i++;
}
echo "]}}";
$mysqli->close();
?>
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

+52
View File
@@ -0,0 +1,52 @@
<?php
$name=$_REQUEST["username"];
$pwd=$_REQUEST["password"];
$machineId=$_REQUEST["machineId"];
if (!$name) {
echo "{\"string\":Username not provided.}";
exit;
}
if (!$pwd) {
echo "{\"string\":Password not provided.}";
exit;
}
if (!$machineId) {
echo "{\"string\":Machine ID not provided.}";
exit;
}
$pwd = hash("ripemd160", $pwd);
// Load help class
require_once("properties.php");
// Load properties
$dbProperties = new Properties();
$propertiesFile = fopen("db.properties", "rb");
$dbProperties->load($propertiesFile);
// Connect to the DB
$username=$dbProperties->getProperty("user");
$password=$dbProperties->getProperty("pass");
$database=$dbProperties->getProperty("db");
$mysqli = new mysqli(localhost,$username,$password,$database);
// Run the query
$sql= "SELECT name FROM diylc_user WHERE name = \"".addslashes($name)."\" AND password = \"".addslashes($pwd)."\"";
if (!$result = $mysqli->query($sql)) {
echo "{\"string\":Error}";
exit;
}
if ($result->num_rows === 0) {
echo "{\"string\":Error}";
} else {
$token = uniqid(addslashes($name), false);
$sql = "UPDATE diylc_user SET last_login = NOW(), machine_id = '".$machineId."', token='".$token."' WHERE name = \"".$name."\"";
$result2 = $mysqli->query($sql);
echo "{\"string\":".$token."}";
}
$result->free();
$mysqli->close();
?>
+53
View File
@@ -0,0 +1,53 @@
<?php
$name=$_REQUEST["username"];
$pwd=$_REQUEST["token"];
$machineId=$_REQUEST["machineId"];
if (!$name) {
echo "{\"string\":Username not provided.}";
exit;
}
if (!$pwd) {
echo "{\"string\":Token not provided.}";
exit;
}
if (!$machineId) {
echo "{\"string\":Machine ID not provided.}";
exit;
}
// Load help class
require_once("properties.php");
// Load properties
$dbProperties = new Properties();
$propertiesFile = fopen("db.properties", "rb");
$dbProperties->load($propertiesFile);
// Connect to the DB
$username=$dbProperties->getProperty("user");
$password=$dbProperties->getProperty("pass");
$database=$dbProperties->getProperty("db");
$mysqli = new mysqli(localhost,$username,$password,$database);
// Run the query
$sql= "SELECT name FROM diylc_user WHERE name = \"".addslashes($name)."\" AND token= \"".addslashes($pwd)."\" AND machine_id = \"".addslashes($machineId)."\"";
if (!$result = $mysqli->query($sql)) {
echo "{\"string\":Error}";
exit;
}
if ($result->num_rows === 0) {
echo "{\"string\":Error}";
} else {
$sql = "UPDATE diylc_user SET last_login = NOW() WHERE name = \"".$name."\"";
$result2 = $mysqli->query($sql);
echo "{\"string\":Success}";
}
$result->free();
$mysqli->close();
?>
+250
View File
@@ -0,0 +1,250 @@
<?php
/**
* PHP Version of the class java.util.Properties. Loads and saves Java
* .properties files.
*
* The methods inherited from Hashtable are not implemented, as they are
* merely another interface to the same functionality. The save method is not
* implemented, as it is considered deprecated; use store instead.
*
* In general, methods which are overloaded to accept an optional parameter
* are combined into a single method with a default value of null for the
* optional parameters. Methods which take versions of streams, writers,
* etc. are consolidated into a single method taking a PHP stream.
*
* The list() methods are replaced with debugList(), as list is a reserved
* word in PHP.
*
* For more information on the .properties format, see
* http://java.sun.com/javase/6/docs/api/java/util/Properties.html
*/
class Properties
{
/**
* Constructor. Takes an optional Properties object defining the default
* values of the properties.
*/
public function __construct($defaults = null) {
if($defaults != null) {
$this->defaults = $defaults;
}
$this->properties = array();
}
/**
* Retrieves a property value. If a value is not found for this key, the
* defaults object is searched for a default. If not default value is
* found there, the default value passed into this function is used. If
* a value still cannot be determined, null is returned.
*/
public function getProperty($key, $defaultValue = null) {
$value = null;
if(array_key_exists($key, $this->properties)) {
$value = $this->properties[$key];
}
if($value == null && $this->defaults != null) {
$value = $this->defaults->getProperty($key);
}
if($value == null) {
$value = $defaultValue;
}
return $value;
}
/**
* Sets a property value. Returns the old value, if available. No defaults
* are used when searching for the old value; a value is returned only if it
* was explicitly set.
*/
public function setProperty($key, $value) {
$oldValue = null;
if(array_key_exists($key, $this->properties)) {
$oldValue = $this->properties[$key];
}
$this->properties[$key] = $value;
return $oldValue;
}
/**
* Returns the names of all keys in this property set, including keys in the
* default property set if no value is defined in this property set.
*/
public function propertyNames() {
$keys = array();
if($this->defaults != null) {
$keys = $this->defaults->propertyNames();
}
$myKeys = array_keys($this->properties);
sort($myKeys);
for($i = 0; $i < count($myKeys); $i++) {
if(!array_key_exists($myKeys[$i], $keys)) {
array_push($keys, $myKeys[$i]);
}
}
return $keys;
}
/**
* Writes the properties to the given stream, in the format defined by
* java.util.Properties.
*/
public function store($handle, $comment = null) {
if($comment != null) {
fwrite($handle, "#" . $this->escapeComment($comment) . PHP_EOL);
}
fwrite($handle, "#" . date("D M d H:i:s T Y") . PHP_EOL);
$propertyNames = array_keys($this->properties);
for($i = 0; $i < count($propertyNames); $i++) {
fwrite($handle, $this->escapeKey($propertyNames[$i]) . "=" . $this->escapeValue($this->properties[$propertyNames[$i]]) . PHP_EOL);
}
}
/**
* Loads a file from the given stream, in the format defined by
* java.util.Properties
*/
public function load($handle) {
$this->properties = array();
$logicalLine = "";
$appendNext = false;
while(!feof($handle)) {
$line = fgets($handle);
$line = rtrim($line, "\r\n"); // Chomp!
$line = ltrim($line);
// If the previous line was a continuation line, append this one
if($appendNext) {
$logicalLine .= $line;
$appendNext = false;
} else {
$logicalLine = $line;
}
// Is it a comment line?
// Check this before checking for continuations, as comments cannot be continued
if(preg_match("/^[ ]*[#!]/", $logicalLine)) {
continue;
}
// Is this line continued?
// A continuation line is one ending in an odd number of backslashes
$numTrailingBackslashes = 0;
while((strlen($logicalLine) - $numTrailingBackslashes - 1) > -1 &&
$logicalLine[strlen($logicalLine) - $numTrailingBackslashes - 1] == "\\") {
$numTrailingBackslashes++;
}
if($numTrailingBackslashes % 2 == 1) {
// If it is a continuation line, append a newline.. this will
// removed when the line is unescaped, but appending it in
// advance prevents backslashes other than the final one from
// escaping the next line, e.g. in the case
// a=b\\\
// n
// If you are not careful, this will be transformed into
// a=b\\n
// And bad things could happen.
$logicalLine .= "\n";
$appendNext = true;
continue;
}
// Now that we've combined the physical lines to form one large
// logical line, see if it's empty.
if(strcmp($logicalLine, "") == 0) {
continue;
}
// Split into key-value pairs
$matches = array();
$key = "";
$value = "";
// This regex splits the string into 3 sections:
// - Leading whitespace plus all non-whitespace characters up to
// the first unescaped :, =, space, or tab character
// - The :, =, space, or tab character itself, which separates
// the key from the value
// - The rest of the string
// If this match succeeds, the first and third pieces form the key
// and value. Otherwise, the entire string is considered to be a
// key with no value.
if(preg_match("/^([ ]*.*?[^\\\\])([:= ]+?)([^:= ].*)$/s", $logicalLine, $matches)) {
$key = $matches[1];
$value = $matches[3];
} else {
$key = $logicalLine;
}
$key = $this->unescapeGeneric($key);
$value = $this->unescapeGeneric($value);
$this->properties[$key] = $value;
}
}
/**
* List the contents to an output stream. This is useful for debugging.
*/
public function debugList($handle) {
fwrite($handle, "-- listing properties --" . PHP_EOL);
$propertyNames = $this->propertyNames();
for($i = 0; $i < count($propertyNames); $i++) {
fwrite($handle, $propertyNames[$i] . "=" . $this->getProperty($propertyNames[$i]) . PHP_EOL);
}
}
private function escapeKey($key) {
return str_replace(" ", "\\ ", $this->escapeGeneric($key));
}
private function escapeValue($value) {
$value = $this->escapeGeneric($value);
// Values have leading space replaced, but none other
if(strlen($value) > 0 && strcmp($value[0], ' ') == 0) {
$value = "\\" . $value;
}
return $value;
}
private function escapeGeneric($value) {
$value = str_replace("#", "\\#", $value);
$value = str_replace("!", "\\!", $value);
$value = str_replace("=", "\\=", $value);
$value = str_replace(":", "\\:", $value);
$value = str_replace("\t", "\\t", $value);
$value = str_replace("\n", "\\n", $value);
$value = str_replace("\r", "\\r", $value);
return $value;
}
private function escapeComment($comment) {
return preg_replace("/\n([^#])/", "\n#\\1", $comment);
}
private function unescapeGeneric($value) {
$value = preg_replace("/\\\\([^\\\\trn\\n])/s", "\\1", $value);
$value = str_replace("\\\n", "", $value);
$value = str_replace("\\t", "\t", $value);
$value = str_replace("\\r", "\r", $value);
$value = str_replace("\\n", "\n", $value);
return $value;
}
private $properties /* Array */;
private $defaults /* Properties */;
}
?>
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

+150
View File
@@ -0,0 +1,150 @@
<?php
$className="com.diyfever.diylc.plugins.cloud.model.ProjectEntity";
$criteria=$_REQUEST["criteria"];
$category=$_REQUEST["category"];
$format=$_REQUEST["format"];
$page=$_REQUEST["page"];
$itemsPerPage=$_REQUEST["itemsPerPage"];
$isJson=$format==="json";
$sort=$_REQUEST["sort"];
if(!$page)
$page=1;
if(!$itemsPerPage)
$itemsPerPage=10;
if(!$sort)
$sort="Project Name";
$condition="";
if ($category)
$condition = $condition." AND LOWER(c.name) = LOWER('".$category."')";
if ($criteria)
$condition = $condition." AND (LOWER(p.description) LIKE LOWER('%".$criteria."%') OR LOWER(p.name) LIKE LOWER('%".$criteria."%') OR LOWER(p.keywords) LIKE LOWER('%".$criteria."%'))";
$limit = " LIMIT ".$itemsPerPage." OFFSET ".(($page-1)*$itemsPerPage);
$orderBy = " ORDER BY ";
if ($sort==="Author")
$orderBy = $orderBy." u.name, p.name";
else if ($sort==="Category")
$orderBy = $orderBy." c.name, p.name";
else if ($sort==="Age")
$orderBy = $orderBy." p.last_update";
else
$orderBy = $orderBy." p.name";
$params="?criteria=".$criteria."&category=".$category."&format=".$format."&sort=".$sort;
// Load help class
require_once("properties.php");
// Load properties
$dbProperties = new Properties();
$propertiesFile = fopen("db.properties", "rb");
$dbProperties->load($propertiesFile);
// Connect to the DB
$username=$dbProperties->getProperty("user");
$password=$dbProperties->getProperty("pass");
$database=$dbProperties->getProperty("db");
$mysqli = new mysqli(localhost,$username,$password,$database);
$sql = "
SELECT p.project_id, p.name, p.description, c.name AS 'category', u.name AS 'owner', p.last_update
FROM diylc_project p, diylc_category c, diylc_user u
WHERE p.category_id = c.category_id AND p.owner_user_id = u.user_id ".$condition.$orderBy.$limit;
//echo $sql;
if (!$result = $mysqli->query($sql)) {
echo "{\"string\":Error}";
exit;
}
$num = $num = $result->num_rows;
if ($num === 0) {
if ($isJson)
echo "{\"list\":\"\"}";
else {
echo "<table width='600px' height='100px'><tr><td align='center' valign='top'><b>No matching projects found.</b></tr></td></table>";
echo "<table width='600px'><tr><td align='left'>";
if ($page > 1)
echo "<a href='".$params."&page=".($page-1)."'><img src='http://diy-fever.com/diylc/api/v1/left-arrow.png'></a>";
echo "</td><td align='right'></td></tr></table>";
}
} else {
// JSON header
if ($isJson)
echo "{\"list\":{\"".$className."\":[";
else
echo "<table width='600px' border='0' cellspacing='0' cellpadding='1'>";
$i=0;
while ($row = $result->fetch_assoc()) {
if ($i>0) {
if ($isJson)
echo ",";
else
echo "<tr height='8px'></tr>";
}
$time = strtotime($row["last_update"]);
$updated = date("Y-m-d", $time);
if ($isJson)
{
echo "{";
echo "\"id\":".$row["project_id"].",";
echo "\"name\":\"".$row["name"]."\",";
echo "\"description\":\"".$row["description"]."\",";
echo "\"owner\":\"".$row["owner"]."\",";
echo "\"category\":\"".$row["category"]."\",";
echo "\"updated\":\"".$updated ."\",";
echo "\"thumbnailUrl\":\"http://diy-fever.com/diylc/thumbnails/".$row["project_id"].".png\",";
echo "\"downloadUrl\":\"http://diy-fever.com/diylc/uploads/".$row["project_id"].".diy\"";
echo "}";
} else {
echo "
<tr style='background-color:#999999;color:#FFFFFF;border-spacing:0;padding:0;'>
<td rowspan='3' width='1'><img src='http://diy-fever.com/diylc/thumbnails/".$row["project_id"].".png'/></td>
<td width='2px'></td>
<td height='1px' colspan='2'><b>".$row["name"]."</b></td>
<td height='1px' colspan='2' nowrap='1' align='right'>by ".$row["owner"]."</td>
<td width='2px'></td>
</tr>
<tr>
<td width='2px'></td>
<td valign='top' halign='left' colspan='4'><p align='justify'>".$row["description"]."</p></td>
<td style='border-right: 1px solid #999999;' width='2px'></td>
</tr>
<tr>
<td style='border-bottom: 1px solid #999999;' width='2px'></td>
<td style='border-bottom: 1px solid #999999;'colspan='3' valign='bottom'>Category: ".$row["category"]."<br>Uploaded on ".$updated."</td>
<td style='border-right: 1px solid #999999;border-bottom: 1px solid #999999;' width='1px' colspan='2' valign='bottom' align='right'><a href='http://diy-fever.com/diylc/uploads/".$row["project_id"].".diy'><img src='http://diy-fever.com/diylc/api/v1/download-icon-32.png'/></a></td>
</tr>";
}
$i++;
}
// JSON footer
if ($isJson)
echo "]}}";
else {
echo "</table>";
echo "<br>";
echo "<table width='600px'><tr><td align='left'>";
if ($page > 1)
echo "<a href='".$params."&page=".($page-1)."'><img src='http://diy-fever.com/diylc/api/v1/left-arrow.png'></a>";
echo "</td><td align='right'>";
if ($num == $itemsPerPage)
echo "<a href='".$params."&page=".($page+1)."'><img src='http://diy-fever.com/diylc/api/v1/right-arrow.png'></a>";
echo "</td></tr></table>";
}
}
$result->free();
$mysqli->close();
?>
+27
View File
@@ -0,0 +1,27 @@
<html>
<body>
<form method="POST" action="http://www.diy-fever.com/diylc/api/upload.php" enctype="multipart/form-data">
Username: <input type="text" name="username" value="testUser3">
<br>
MachineId: <input type="text" name="machineId" value="tttjg">
<br>
Token: <input type="text" name="token" value="testUser35800ffaabb0b92.58166942">
<br>
Name: <input type="text" name="projectName" value="">
<br>
Category: <input type="text" name="category" value="TestCat">
<br>
Description: <input type="text" name="description" value="The quick brown fox jumps over the lazy dog.">
<br>
Version: <input type="text" name="diylcVersion" value="3.0.0">
<br>
Keywords: <input type="text" name="keywords" value="">
<br>
Thumb: <input type="file" name="thumbnail" id="thumbnail">
<br>
Project: <input type="file" name="project" id="project">
<br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
+134
View File
@@ -0,0 +1,134 @@
<?php
$name=$_REQUEST["username"];
$token=$_REQUEST["token"];
$machineId=$_REQUEST["machineId"];
$projectName=$_REQUEST["projectName"];
$category=$_REQUEST["category"];
$description=$_REQUEST["description"];
$diylcVersion=$_REQUEST["diylcVersion"];
$keywords=$_REQUEST["keywords"];
//echo var_dump($_FILES);
$thumbnailFile=$_FILES["thumbnail"];
$projectFile=$_FILES["project"];
if (!$name) {
echo "{\"string\":Username not provided.}";
exit;
}
if (!$token) {
echo "{\"string\":Token not provided.}";
exit;
}
if (!$machineId) {
echo "{\"string\":Machine ID not provided.}";
exit;
}
if (!$category) {
echo "{\"string\":Category not provided.}";
exit;
}
if (!$description) {
echo "{\"string\":Description not provided.}";
exit;
}
if (!$diylcVersion) {
echo "{\"string\":DIYLC version not provided.}";
exit;
}
if (!$thumbnailFile) {
echo "{\"string\":Thumbnail file not uploaded.}";
exit;
}
if (!$projectFile) {
echo "{\"string\":Project file not uploaded.}";
exit;
}
if ($thumbnailFile['size'] > 100000) {
echo "{\"string\":Thumbnail file is too big.}";
exit;
}
if ($projectFile['size'] > 10000000) {
echo "{\"string\":Project file is too big.}";
exit;
}
if (getimagesize($thumbnailFile['tmp_name']) == false) {
echo "{\"string\":Thumbnail image is not valid.}";
exit;
}
// Load help class
require_once("properties.php");
// Load properties
$dbProperties = new Properties();
$propertiesFile = fopen("db.properties", "rb");
$dbProperties->load($propertiesFile);
// Connect to the DB
$username=$dbProperties->getProperty("user");
$password=$dbProperties->getProperty("pass");
$database=$dbProperties->getProperty("db");
$mysqli = new mysqli(localhost,$username,$password,$database);
// Verify that the user is logged in
$sql = "
SELECT user_id
FROM diylc_user
WHERE name = \"".addslashes($name)."\" AND token= \"".addslashes($token)."\" AND machine_id = \"".addslashes($machineId)."\"";
if (!$result = $mysqli->query($sql)) {
echo "{\"string\":Error while looking up the user.}";
exit;
}
if ($row = $result->fetch_assoc()) {
$userId = $row["user_id"];
// Find the right category
$sql = "
SELECT category_id
FROM diylc_category
WHERE LOWER(name) = LOWER(\"".addslashes($category)."\")";
if (!$result = $mysqli->query($sql)) {
echo "{\"string\":Error while determining the category.}";
exit;
}
if ($row = $result->fetch_assoc()) {
$categoryId = $row["category_id"];
// Insert into the database
$sql= "
INSERT INTO diylc_project (name, description, category_id, owner_user_id, diylc_version, keywords, uploaded_on, last_update)
VALUES (\"".$projectName."\",\"".$description."\",".$categoryId.",".$userId.",\"".$diylcVersion."\",\"".$keywords."\",now(),now())";
if (!$result = $mysqli->query($sql)) {
echo "{\"string\":Error while uploading the project into the database.}";
exit;
} else {
$projectId = $mysqli->insert_id;
// Move the uploaded files
if (move_uploaded_file($thumbnailFile['tmp_name'], '/home/diyfever/public_html/diylc/thumbnails/'.$projectId.".png") and
move_uploaded_file($projectFile['tmp_name'], '/home/diyfever/public_html/diylc/uploads/'.$projectId.".diy"))
echo "{\"string\":Success}";
else {
// delete the entry if we couldn't move the files
$sql="DELETE diylc_project WHERE project_id=".$projectId;
$mysqli->query($sql);
echo "{\"string\":Error processing uploaded files.}";
}
}
} else {
echo "{\"string\":Invalid category.}";
}
} else {
echo "{\"string\":User is not logged in.}";
}
$mysqli->close();
?>