From 5d5aa05f0819e862f3b7bb2b035d23ac876ca835 Mon Sep 17 00:00:00 2001 From: bancika Date: Fri, 28 Oct 2016 10:47:55 +0200 Subject: [PATCH] update back-end code --- diylc-server-api/v1/createUser.php | 15 ++- diylc-server-api/v1/db/diylc_category.sql | 62 +++++++++ diylc-server-api/v1/db/diylc_comment.sql | 42 ++++++ diylc-server-api/v1/db/diylc_project.sql | 46 +++++++ .../v1/db/diylc_search_history.sql | 41 ++++++ diylc-server-api/v1/db/diylc_user.sql | 46 +++++++ diylc-server-api/v1/download-icon-32.png | Bin 0 -> 717 bytes diylc-server-api/v1/downloadProject.php | 36 +++++ diylc-server-api/v1/downloadThumbnail.php | 38 ++++++ diylc-server-api/v1/error_log | 55 -------- diylc-server-api/v1/getAnnouncements.php | 3 + diylc-server-api/v1/getCategories.php | 4 +- diylc-server-api/v1/getComments.php | 67 +++++++++ diylc-server-api/v1/getSortings.php | 3 + diylc-server-api/v1/getUserDetails.php | 54 ++++++++ diylc-server-api/v1/postComment.php | 72 ++++++++++ diylc-server-api/v1/search.php | 127 +++++++----------- diylc-server-api/v1/testUpload.html | 27 ---- diylc-server-api/v1/updatePassword.php | 55 ++++++++ diylc-server-api/v1/updateUserDetails.php | 59 ++++++++ diylc-server-api/v1/upload.php | 4 +- 21 files changed, 691 insertions(+), 165 deletions(-) create mode 100644 diylc-server-api/v1/db/diylc_category.sql create mode 100644 diylc-server-api/v1/db/diylc_comment.sql create mode 100644 diylc-server-api/v1/db/diylc_project.sql create mode 100644 diylc-server-api/v1/db/diylc_search_history.sql create mode 100644 diylc-server-api/v1/db/diylc_user.sql create mode 100644 diylc-server-api/v1/download-icon-32.png create mode 100644 diylc-server-api/v1/downloadProject.php create mode 100644 diylc-server-api/v1/downloadThumbnail.php delete mode 100644 diylc-server-api/v1/error_log create mode 100644 diylc-server-api/v1/getAnnouncements.php create mode 100644 diylc-server-api/v1/getComments.php create mode 100644 diylc-server-api/v1/getSortings.php create mode 100644 diylc-server-api/v1/getUserDetails.php create mode 100644 diylc-server-api/v1/postComment.php delete mode 100644 diylc-server-api/v1/testUpload.html create mode 100644 diylc-server-api/v1/updatePassword.php create mode 100644 diylc-server-api/v1/updateUserDetails.php diff --git a/diylc-server-api/v1/createUser.php b/diylc-server-api/v1/createUser.php index e5b01fa9..3a97a68c 100644 --- a/diylc-server-api/v1/createUser.php +++ b/diylc-server-api/v1/createUser.php @@ -19,7 +19,7 @@ if (strlen($pwd) < 6) { exit; } if (!$email) { - echo "{\"string\":E-mail not provided.}"; + echo "{\"string\":eMail not provided.}"; exit; } $pwd = hash("ripemd160", $pwd); @@ -45,10 +45,21 @@ if (!$result = $mysqli->query($sql)) { echo "{\"string\":Error}"; exit; } + +function ip_details($IPaddress) +{ + $json = file_get_contents("http://ip-api.com/json/{$IPaddress}"); + $details = json_decode($json); + return $details; +} + +$ip = $_SERVER["REMOTE_ADDR"]; +$location = ip_details($ip); + $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)."')"; + $sql= "INSERT INTO diylc_user (name, password, email, website, bio, ip, country) VALUES ('".addslashes($name)."', '".$pwd."', '".addslashes($email)."', '".addslashes($website)."', '".addslashes($bio)."', '".$ip."', '".$location->country."')"; if ($mysqli->query($sql) === TRUE) { echo "{\"string\":Success}"; diff --git a/diylc-server-api/v1/db/diylc_category.sql b/diylc-server-api/v1/db/diylc_category.sql new file mode 100644 index 00000000..d0874868 --- /dev/null +++ b/diylc-server-api/v1/db/diylc_category.sql @@ -0,0 +1,62 @@ +-- phpMyAdmin SQL Dump +-- version 4.0.10.14 +-- http://www.phpmyadmin.net +-- +-- Host: localhost:3306 +-- Generation Time: Oct 28, 2016 at 10:45 AM +-- Server version: 5.6.33 +-- PHP Version: 5.6.20 + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; + +-- +-- Database: `diyfever_db` +-- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `diylc_category` +-- + +CREATE TABLE IF NOT EXISTS `diylc_category` ( + `category_id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(30) NOT NULL, + `sort_order` int(11) NOT NULL DEFAULT '0', + `parent_id` int(11) NOT NULL, + PRIMARY KEY (`category_id`), + UNIQUE KEY `category_id` (`category_id`), + KEY `category_id_2` (`category_id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=22 ; + +-- +-- Dumping data for table `diylc_category` +-- + +INSERT INTO `diylc_category` (`category_id`, `name`, `sort_order`, `parent_id`) VALUES +(1, 'Effects', 200, 0), +(2, 'Compressors', 210, 1), +(3, 'Delays', 215, 1), +(4, 'Distortions', 220, 1), +(5, 'Reverbs', 235, 1), +(6, 'Boosters', 205, 1), +(7, 'Wahs', 240, 1), +(8, 'Modulations', 225, 1), +(9, 'Amplifiers', 100, 0), +(13, 'Hi-Fi Amplifiers', 150, 9), +(14, 'Guitar Amplifiers', 110, 9), +(21, 'Hi-Fi Preamps', 160, 9), +(20, 'Guitar Preamps', 120, 9), +(18, 'Guitar Wiring Diagrams', 400, 0), +(19, 'Other', 1000, 0); + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/diylc-server-api/v1/db/diylc_comment.sql b/diylc-server-api/v1/db/diylc_comment.sql new file mode 100644 index 00000000..de1c7c37 --- /dev/null +++ b/diylc-server-api/v1/db/diylc_comment.sql @@ -0,0 +1,42 @@ +-- phpMyAdmin SQL Dump +-- version 4.0.10.14 +-- http://www.phpmyadmin.net +-- +-- Host: localhost:3306 +-- Generation Time: Oct 28, 2016 at 10:45 AM +-- Server version: 5.6.33 +-- PHP Version: 5.6.20 + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; + +-- +-- Database: `diyfever_db` +-- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `diylc_comment` +-- + +CREATE TABLE IF NOT EXISTS `diylc_comment` ( + `comment_id` int(11) NOT NULL AUTO_INCREMENT, + `project_id` int(11) NOT NULL, + `parent_id` int(11) NOT NULL DEFAULT '0', + `user_id` int(11) NOT NULL, + `comment` varchar(1024) NOT NULL, + `posted_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `flagged` bit(1) NOT NULL, + PRIMARY KEY (`comment_id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=15 ; + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/diylc-server-api/v1/db/diylc_project.sql b/diylc-server-api/v1/db/diylc_project.sql new file mode 100644 index 00000000..5dd17b70 --- /dev/null +++ b/diylc-server-api/v1/db/diylc_project.sql @@ -0,0 +1,46 @@ +-- phpMyAdmin SQL Dump +-- version 4.0.10.14 +-- http://www.phpmyadmin.net +-- +-- Host: localhost:3306 +-- Generation Time: Oct 28, 2016 at 10:45 AM +-- Server version: 5.6.33 +-- PHP Version: 5.6.20 + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; + +-- +-- Database: `diyfever_db` +-- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `diylc_project` +-- + +CREATE TABLE IF NOT EXISTS `diylc_project` ( + `project_id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(50) NOT NULL, + `category_id` int(11) NOT NULL, + `owner_user_id` int(11) NOT NULL, + `description` varchar(1024) DEFAULT NULL, + `diylc_version` varchar(50) NOT NULL, + `uploaded_on` datetime NOT NULL, + `last_update` datetime NOT NULL, + `keywords` varchar(1024) NOT NULL, + `view_count` int(11) NOT NULL DEFAULT '0', + `download_count` int(11) NOT NULL DEFAULT '0', + PRIMARY KEY (`project_id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=28 ; + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/diylc-server-api/v1/db/diylc_search_history.sql b/diylc-server-api/v1/db/diylc_search_history.sql new file mode 100644 index 00000000..23390efe --- /dev/null +++ b/diylc-server-api/v1/db/diylc_search_history.sql @@ -0,0 +1,41 @@ +-- phpMyAdmin SQL Dump +-- version 4.0.10.14 +-- http://www.phpmyadmin.net +-- +-- Host: localhost:3306 +-- Generation Time: Oct 28, 2016 at 10:45 AM +-- Server version: 5.6.33 +-- PHP Version: 5.6.20 + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; + +-- +-- Database: `diyfever_db` +-- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `diylc_search_history` +-- + +CREATE TABLE IF NOT EXISTS `diylc_search_history` ( + `ip` varchar(100) NOT NULL, + `country` varchar(100) NOT NULL, + `criteria` varchar(100) NOT NULL, + `category` varchar(100) NOT NULL, + `format` varchar(10) NOT NULL, + `sort` varchar(20) NOT NULL, + `search_time` datetime NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/diylc-server-api/v1/db/diylc_user.sql b/diylc-server-api/v1/db/diylc_user.sql new file mode 100644 index 00000000..f6683c62 --- /dev/null +++ b/diylc-server-api/v1/db/diylc_user.sql @@ -0,0 +1,46 @@ +-- phpMyAdmin SQL Dump +-- version 4.0.10.14 +-- http://www.phpmyadmin.net +-- +-- Host: localhost:3306 +-- Generation Time: Oct 28, 2016 at 10:45 AM +-- Server version: 5.6.33 +-- PHP Version: 5.6.20 + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; + +-- +-- Database: `diyfever_db` +-- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `diylc_user` +-- + +CREATE TABLE IF NOT EXISTS `diylc_user` ( + `user_id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(50) NOT NULL, + `password` varchar(50) NOT NULL, + `email` varchar(50) NOT NULL, + `website` varchar(100) NOT NULL, + `bio` varchar(1024) NOT NULL, + `token` varchar(50) NOT NULL, + `machine_id` varchar(50) NOT NULL, + `last_login` datetime NOT NULL, + `ip` varchar(50) NOT NULL, + `country` varchar(50) NOT NULL, + PRIMARY KEY (`user_id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=14 ; + +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/diylc-server-api/v1/download-icon-32.png b/diylc-server-api/v1/download-icon-32.png new file mode 100644 index 0000000000000000000000000000000000000000..090ed55653e1842e0770438e42a65da2cbc5c462 GIT binary patch literal 717 zcmV;;0y6!HP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02y>eSaefwW^{L9 za%BK;VQFr3E^cLXAT%y8E-^Ag1Z(U700KQpL_t(oN7dHNi%oGH$MNf_D5Nk8qa+VY zEEIc<9SdSHjg2fU*w_%|A);h5+Yus~@~}{vzeQsqp)5Ryggm_8-0$r-$2sSodpq|| zKJ}_|&-tC-_j~Vo_}#|;oCVm43%HF5T*e5Np=Viyb9jee1-{}sR-o2w!V}~b&GQD^ z(N#9!46foVb|L-NFL45nn~!-|k3*P3jPutRLgmbc*YYP~lB|1JjH1}gCB*nw7(k^Q zLs~3r5_3=`V~F$oQf)IAZ{Z2=u>(us-R}O+7(~^0X`aLRJm2|Cvj)-es5_Eu#?il< z9pxfo&ModJ%K^mThwi8$`w(+}#D3&v80n4o8cR`>mDt{#@ehcCHsLB5pWTk)a$#$`_IH}CNSp9Ik+*Ge$Mz)ICbD{3 zJW|wz`+8nHl5L`|#Us(gj1-Spc*cs?kVfM-O2PMqkOJZ900000NkvXXu0mjfA3{z0 literal 0 HcmV?d00001 diff --git a/diylc-server-api/v1/downloadProject.php b/diylc-server-api/v1/downloadProject.php new file mode 100644 index 00000000..7332d3bc --- /dev/null +++ b/diylc-server-api/v1/downloadProject.php @@ -0,0 +1,36 @@ +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 = " +UPDATE diylc_project +SET download_count = download_count + 1 +WHERE project_id=".$id; + +//echo $sql; + +if (!$result = $mysqli->query($sql)) { + echo "{\"string\":Error}"; + exit; +} + +readfile("http://diy-fever.com/diylc/uploads/".$id.".diy"); + +$mysqli->close(); +?> \ No newline at end of file diff --git a/diylc-server-api/v1/downloadThumbnail.php b/diylc-server-api/v1/downloadThumbnail.php new file mode 100644 index 00000000..ab6bbc40 --- /dev/null +++ b/diylc-server-api/v1/downloadThumbnail.php @@ -0,0 +1,38 @@ +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 = " +UPDATE diylc_project +SET view_count = view_count + 1 +WHERE project_id=".$id; + +//echo $sql; + +if (!$result = $mysqli->query($sql)) { + echo "{\"string\":Error}"; + exit; +} + +$im = imagecreatefrompng("http://diy-fever.com/diylc/thumbnails/".$id.".png"); +if ($im) { + header('Content-Type: image/png'); + imagepng($im); + imagedestroy($im); +} + +$mysqli->close(); +?> \ No newline at end of file diff --git a/diylc-server-api/v1/error_log b/diylc-server-api/v1/error_log deleted file mode 100644 index 68a7c73b..00000000 --- a/diylc-server-api/v1/error_log +++ /dev/null @@ -1,55 +0,0 @@ -[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 '"' (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 diff --git a/diylc-server-api/v1/getAnnouncements.php b/diylc-server-api/v1/getAnnouncements.php new file mode 100644 index 00000000..8bef82fe --- /dev/null +++ b/diylc-server-api/v1/getAnnouncements.php @@ -0,0 +1,3 @@ +{"list":{"org.diylc.announcements.Announcement":[ +{"title":"Welcome note","date":"2016-10-25","text":"Thank you for trying out the latest and greatest DIYLC beta version.
Please note that all project submitted during beta testing stage will be deleted
once the we are ready for the release for a fresh start.
Enjoy surfing the cloud and please send your feedback to bancika@gmail.com"}, +]}} \ No newline at end of file diff --git a/diylc-server-api/v1/getCategories.php b/diylc-server-api/v1/getCategories.php index 56d373f9..b0d09f64 100644 --- a/diylc-server-api/v1/getCategories.php +++ b/diylc-server-api/v1/getCategories.php @@ -15,7 +15,7 @@ $database=$dbProperties->getProperty("db"); $mysqli = new mysqli(localhost,$username,$password,$database); // Run the query -$sql= "SELECT name FROM diylc_category ORDER BY sort_order"; +$sql= "SELECT display_name FROM diylc_category_view"; if (!$result = $mysqli->query($sql)) { echo "{\"string\":Error}"; @@ -29,7 +29,7 @@ $i=0; while ($row = $result->fetch_assoc()) { if ($i>0) echo ","; - echo "\"".$row["name"]."\""; + echo "\"".$row["display_name"]."\""; $i++; } diff --git a/diylc-server-api/v1/getComments.php b/diylc-server-api/v1/getComments.php new file mode 100644 index 00000000..ea60d7f4 --- /dev/null +++ b/diylc-server-api/v1/getComments.php @@ -0,0 +1,67 @@ +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 c.*, u.name username +FROM diylc_comment c +INNER JOIN diylc_user u ON u.user_id = c.user_id +WHERE project_id = ".$projectId; + +//echo $sql; + +if (!$result = $mysqli->query($sql)) { + echo "{\"string\":Error:".$mysqli->error."}"; + exit; +} + +$num = $num = $result->num_rows; +if ($num === 0) { + echo "{\"list\":\"\"}"; +} else { + // JSON header + echo "{\"list\":{\"".$className."\":["; + + $i=0; + while ($row = $result->fetch_assoc()) { + if ($i>0) { + echo ","; + } + + $time = strtotime($row["posted_at"]); + $postedAt= date("Y-m-d H:i:s", $time); + + + echo "{"; + echo "\"id\":".$row["comment_id"].","; + echo "\"parentId\":".$row["parent_id"].","; + echo "\"username\":\"".$row["username"]."\","; + echo "\"comment\":\"".$row["comment"]."\","; + echo "\"postedAt\":\"".$postedAt."\""; + echo "}"; + + $i++; +} + + echo "]}}"; +} + +$result->free(); +$mysqli->close(); +?> \ No newline at end of file diff --git a/diylc-server-api/v1/getSortings.php b/diylc-server-api/v1/getSortings.php new file mode 100644 index 00000000..feb61eae --- /dev/null +++ b/diylc-server-api/v1/getSortings.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/diylc-server-api/v1/getUserDetails.php b/diylc-server-api/v1/getUserDetails.php new file mode 100644 index 00000000..4b11868f --- /dev/null +++ b/diylc-server-api/v1/getUserDetails.php @@ -0,0 +1,54 @@ +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); + +$className="org.diylc.plugins.cloud.model.UserEntity"; + +// Verify that the user is logged in +$sql = " +SELECT email, website, bio +FROM diylc_user +WHERE name = \"".addslashes($name)."\" AND token= \"".addslashes($token)."\" AND machine_id = \"".addslashes($machineId)."\""; + +if (!$result = $mysqli->query($sql) or !($row = $result->fetch_assoc())) { + echo "{\"string\":Error while looking up the user.}"; +} else { + echo "{\"".$className."\": { + \"username\":\"".$name."\", + \"email\":\"".addslashes($row["email"])."\", + \"website\":\"".addslashes($row["website"])."\", + \"bio\":\"".addslashes(str_replace(array("\n","\r\n","\r"),"
", $row["bio"]))."\" + }}"; +} + +$mysqli->close(); +?> \ No newline at end of file diff --git a/diylc-server-api/v1/postComment.php b/diylc-server-api/v1/postComment.php new file mode 100644 index 00000000..3ef4ccc4 --- /dev/null +++ b/diylc-server-api/v1/postComment.php @@ -0,0 +1,72 @@ +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"]; + $sql = "INSERT INTO diylc_comment (project_id, user_id, comment, posted_at) VALUES (".addslashes($projectId).",".$userId.",\"".addslashes($comment)."\",NOW())"; + if (!$result = $mysqli->query($sql)) { + echo "{\"string\":Error while uploading the project into the database.}"; + exit; + } else { + echo "{\"string\":Success}"; + } +} else { + echo "{\"string\":User is not logged in.}"; +} + +$mysqli->close(); + +?> \ No newline at end of file diff --git a/diylc-server-api/v1/search.php b/diylc-server-api/v1/search.php index 6cca990c..432c2e91 100644 --- a/diylc-server-api/v1/search.php +++ b/diylc-server-api/v1/search.php @@ -1,12 +1,10 @@ getProperty("pass"); $database=$dbProperties->getProperty("db"); $mysqli = new mysqli(localhost,$username,$password,$database); +function ip_details($IPaddress) +{ + $json = file_get_contents("http://ip-api.com/json/{$IPaddress}"); + $details = json_decode($json); + return $details; +} + +$ip = $_SERVER["REMOTE_ADDR"]; +$location = ip_details($ip); + +$sql = "INSERT INTO diylc_search_history (ip, country, criteria, category, sort, search_time) VALUES (\"".$ip."\", \"".$location->country."\",\"".$criteria."\",\"".$category."\",\"".$sort."\",NOW())"; + +$mysqli->query($sql); + +//echo $sql; + +//if (!$result = $mysqli->query($sql)) { +// echo "{\"string\":Error:".$mysqli->error."}"; +// exit; +//} + $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 +SELECT p.project_id, p.name, p.description, c.search_name AS 'category', u.name AS 'owner', p.last_update, p.view_count, p.download_count, (SELECT COUNT(*) FROM diylc_comment co WHERE co.project_id = p.project_id) comment_count +FROM diylc_project p, diylc_category_view 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}"; + echo "{\"string\":Error:".$mysqli->error."}"; exit; } $num = $num = $result->num_rows; if ($num === 0) { - if ($isJson) - echo "{\"list\":\"\"}"; - else { - echo "
No matching projects found.
"; - echo "
"; - - if ($page > 1) - echo ""; - echo "
"; - } + echo "{\"list\":\"\"}"; } else { // JSON header - if ($isJson) - echo "{\"list\":{\"".$className."\":["; - else - echo ""; + echo "{\"list\":{\"".$className."\":["; $i=0; while ($row = $result->fetch_assoc()) { if ($i>0) { - if ($isJson) - echo ","; - else - echo ""; + echo ","; } $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 " - - - - - - - - - - - - - - - - - "; - } - $i++; - } - - // JSON footer - if ($isJson) - echo "]}}"; - else { - echo "
".$row["name"]."by ".$row["owner"]."

".$row["description"]."

Category: ".$row["category"]."
Uploaded on ".$updated."
"; - echo "
"; - - echo "
"; - if ($page > 1) - echo ""; - echo ""; - if ($num == $itemsPerPage) - echo ""; - echo "
"; - } + + 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/api/v1/downloadThumbnail.php?id=".$row["project_id"]."\","; + echo "\"downloadUrl\":\"http://diy-fever.com/diylc/api/v1/downloadProject.php?id=".$row["project_id"]."\","; + echo "\"commentCount\":\"".$row["comment_count"]."\","; + echo "\"viewCount\":\"".$row["view_count"]."\","; + echo "\"downloadCount\":\"".$row["download_count"]."\""; + echo "}"; + + $i++; +} + + echo "]}}"; } $result->free(); diff --git a/diylc-server-api/v1/testUpload.html b/diylc-server-api/v1/testUpload.html deleted file mode 100644 index 29fe3daa..00000000 --- a/diylc-server-api/v1/testUpload.html +++ /dev/null @@ -1,27 +0,0 @@ - - -
- Username: -
- MachineId: -
- Token: -
- Name: -
- Category: -
- Description: -
- Version: -
- Keywords: -
- Thumb: -
- Project: -
- -
- - \ No newline at end of file diff --git a/diylc-server-api/v1/updatePassword.php b/diylc-server-api/v1/updatePassword.php new file mode 100644 index 00000000..4dea4096 --- /dev/null +++ b/diylc-server-api/v1/updatePassword.php @@ -0,0 +1,55 @@ +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 = " +UPDATE diylc_user +SET password = \"".$newPwd."\" +WHERE name = \"".addslashes($name)."\" AND password= \"".$oldPwd."\""; + +if (!$result = $mysqli->query($sql)) { + echo "{\"string\":Database error.}"; + exit; +} + +if ($mysqli->affected_rows === 0) { + echo "{\"string\":Could not update the password.}"; +} else { + echo "{\"string\":Success}"; +} + +$mysqli->close(); +?> \ No newline at end of file diff --git a/diylc-server-api/v1/updateUserDetails.php b/diylc-server-api/v1/updateUserDetails.php new file mode 100644 index 00000000..8e94bf58 --- /dev/null +++ b/diylc-server-api/v1/updateUserDetails.php @@ -0,0 +1,59 @@ +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 = " +UPDATE diylc_user +SET email= \"".addslashes($email)."\", website= \"".addslashes($website)."\", bio= \"".addslashes($bio)."\" +WHERE name = \"".addslashes($name)."\" AND token= \"".addslashes($token)."\" AND machine_id = \"".addslashes($machineId)."\""; + +if (!$result = $mysqli->query($sql)) { + echo "{\"string\":Database error.}"; + exit; +} + +if ($mysqli->affected_rows === 0) { + echo "{\"string\":Could not update the account.}"; +} else { + echo "{\"string\":Success}"; +} + +$mysqli->close(); +?> \ No newline at end of file diff --git a/diylc-server-api/v1/upload.php b/diylc-server-api/v1/upload.php index 84093818..f6d4fb1f 100644 --- a/diylc-server-api/v1/upload.php +++ b/diylc-server-api/v1/upload.php @@ -90,8 +90,8 @@ if ($row = $result->fetch_assoc()) { // Find the right category $sql = " SELECT category_id - FROM diylc_category - WHERE LOWER(name) = LOWER(\"".addslashes($category)."\")"; + FROM diylc_category_view + WHERE LOWER(display_name) = LOWER(\"".addslashes($category)."\")"; if (!$result = $mysqli->query($sql)) { echo "{\"string\":Error while determining the category.}";