From 075fdc05e721a8f479b3b0dc431a00b7ddbe6eac Mon Sep 17 00:00:00 2001 From: Phitherek Date: Sat, 15 Sep 2012 16:20:15 +0200 Subject: [PATCH] slightly modified database, added 3m specific fields in separate table, modified the code for database changes and changed scripts to extend entries, written new script - 3mrelinc.php --- 3mrelinc.php | 24 +++++++++ README.md | 114 +++++++++++++++++++++++++--------------- addentry.php | 11 +++- api/3m/getmodbyname.php | 29 +++++++--- api/3m/getmods.php | 4 +- deleteentry.php | 3 ++ editentry.php | 42 +++++++++++++-- scripts/addentry.php | 25 ++++++++- scripts/loadmods.php | 11 +++- viewmod.php | 11 +++- 10 files changed, 213 insertions(+), 61 deletions(-) create mode 100644 3mrelinc.php diff --git a/3mrelinc.php b/3mrelinc.php new file mode 100644 index 0000000..b8bace9 --- /dev/null +++ b/3mrelinc.php @@ -0,0 +1,24 @@ + Back to home"); +} + +include "scripts/pageheader.php"; + +$mmmres = mysql_query("SELECT rel FROM 3m_specific WHERE id=".$id, $handle) or SQLerror("SQL Error", "Could not find the entry!"); +$mmmarr = mysql_fetch_array($mmmres); +$mmmrel = $mmmarr['rel']; +$mmmrel = $mmmrel + 1; +$q = mysql_query("UPDATE 3m_specific SET rel=".$mmmrel." WHERE id=".$id, $handle) or SQLerror("SQL Error", "Could not increase 3m release value!"); +echo("3m Release increased!
"); + +header("location: viewmod.php?id=$id"); +// End of Phitherek_' s code +?> + diff --git a/README.md b/README.md index ec92522..70bc9f6 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,14 @@ Rubenwardy's Mod Forum ====================== -A php and mysgl forum for mods. +A php and mysql forum for mods. -Also a mod database for Jeijas Ingame Mod Manager -and Sfan's Python Mod Manager +Also a mod database for Jeija' s Ingame Mod Manager, Sfan's Python Mod Manager and Phitherek_' s 3m Minetest Mod Manager License ======= -Copyright (c) 2012, Andrew "Rubenwardy" Ward +Copyright (c) 2012, Andrew "Rubenwardy" Ward and Piotr "Phitherek_" Żurek All rights reserved. Redistribution and use in source and binary forms, with or without @@ -53,44 +52,77 @@ Database ======== The database structure. -USERS: +mysql> show tables; ++-----------------------------+ +| Tables_in_minetest_forum_db | ++-----------------------------+ +| 3m_specific | +| mods | +| posts | +| users | ++-----------------------------+ +4 rows in set (0.00 sec) -* id (int) -* name -* email -* password -* level (int) -* stars -* avatar -* location -* sig +mysql> describe users; ++----------+--------------+------+-----+---------+----------------+ +| Field | Type | Null | Key | Default | Extra | ++----------+--------------+------+-----+---------+----------------+ +| id | int(11) | NO | PRI | NULL | auto_increment | +| name | varchar(100) | YES | | NULL | | +| email | varchar(300) | YES | | NULL | | +| password | varchar(500) | YES | | NULL | | +| level | int(11) | YES | | NULL | | +| stars | int(11) | YES | | NULL | | +| avatar | int(11) | YES | | NULL | | +| location | varchar(50) | YES | | NULL | | +| sig | varchar(500) | YES | | NULL | | ++----------+--------------+------+-----+---------+----------------+ +9 rows in set (0.00 sec) -MOD: +mysql> describe mods; ++-------------------+--------------+------+-----+---------+----------------+ +| Field | Type | Null | Key | Default | Extra | ++-------------------+--------------+------+-----+---------+----------------+ +| mod_id | int(11) | NO | PRI | NULL | auto_increment | +| name | varchar(100) | YES | | NULL | | +| version | varchar(20) | YES | | NULL | | +| owner | int(11) | YES | | NULL | | +| description | varchar(500) | YES | | NULL | | +| likes | int(11) | YES | | NULL | | +| dislikes | int(11) | YES | | NULL | | +| tags | varchar(100) | YES | | NULL | | +| license | varchar(10) | YES | | NULL | | +| file | varchar(500) | YES | | NULL | | +| depend | varchar(500) | YES | | NULL | | +| basename | varchar(100) | YES | | NULL | | +| date_released | date | YES | | NULL | | +| quality_total | int(11) | YES | | NULL | | +| quality_voters | int(11) | YES | | NULL | | +| usefullness_total | int(11) | YES | | NULL | | +| cpu_total | int(11) | YES | | NULL | | +| cpu_voters | int(11) | YES | | NULL | | ++-------------------+--------------+------+-----+---------+----------------+ +18 rows in set (0.01 sec) -* mod_id (int) -* name -* version -* owner -* description -* likes (int) -* dislikes (int) -* tags -* license -* file -* depend -* basename (the mod name, eg: "moreblocks") -* date_released (date) -* quality_total (int) -* quality_voters (int) -* usefullness_total (int) -* cpu_total (int) -* cpu_voters (int) +mysql> describe posts; ++----------+--------------+------+-----+---------+----------------+ +| Field | Type | Null | Key | Default | Extra | ++----------+--------------+------+-----+---------+----------------+ +| post_id | int(11) | NO | PRI | NULL | auto_increment | +| owner | int(11) | YES | | NULL | | +| post | varchar(500) | YES | | NULL | | +| topic | int(11) | YES | | NULL | | +| likes | int(11) | YES | | NULL | | +| dislikes | int(11) | YES | | NULL | | ++----------+--------------+------+-----+---------+----------------+ +6 rows in set (0.00 sec) -POSTS: - -* post_id (int) -* Owner -* Post -* Topic (int) -* Like (int) -* Dislike (int) \ No newline at end of file +mysql> describe 3m_specific; ++----------+-------------+------+-----+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++----------+-------------+------+-----+---------+-------+ +| id | int(11) | NO | PRI | NULL | | +| rel | int(11) | YES | | NULL | | +| repotype | varchar(20) | YES | | NULL | | ++----------+-------------+------+-----+---------+-------+ +3 rows in set (0.01 sec) \ No newline at end of file diff --git a/addentry.php b/addentry.php index 3c90ba5..039624e 100644 --- a/addentry.php +++ b/addentry.php @@ -24,7 +24,10 @@ if (is_member_moderator($_SESSION['user'])==true){ Mod Name:* -Version:* + +Version:* +3m Release:* + @@ -64,6 +67,12 @@ Delete these notes before adding the entry--> + +3m Repotype: + File URL*: License: diff --git a/api/3m/getmodbyname.php b/api/3m/getmodbyname.php index 5aeafb1..04bb860 100644 --- a/api/3m/getmodbyname.php +++ b/api/3m/getmodbyname.php @@ -3,23 +3,36 @@ include "../../scripts/setup.php"; $id=$_GET['id']; $id= mysql_real_escape_string ($id); -$res = mysql_query("SELECT * FROM mods WHERE name='$id'",$handle) or SQLerror("MySQL Query Error","Error on searching database.mods.mod_id for '$id'"); +$res = mysql_query("SELECT * FROM mods WHERE basename='$id'",$handle) or SQLerror("MySQL Query Error","Error on searching database.mods.mod_id for '$id'"); header("Content-type: text/plain"); -$row = mysql_fetch_row($res) or die("Name:\nDepends:\nFile:\nVersion:\n"); +$row = mysql_fetch_array($res) or die("Name:\nDepends:\nFile:\nVersion:\n"); +$mmmres = mysql_query("SELECT * FROM 3m_specific WHERE id=".$row['id']); +$mmmarr = mysql_fetch_array($mmmres); - -echo "{{$row[1]}}\n"; +echo "{{$row['basename']}}\n"; echo "[description]\n"; -echo "{$row[3]}\n"; +echo "{$row['desc']}\n"; echo "[release]\n"; -echo "{$row[2]}\n"; +echo "{$mmmres['rel']}\n"; echo "[deps]\n"; +$deps = $row['depend']; +$parseddeps = ""; +for($i=0; $i < strlen($deps); $i++) { + if($deps[$i] == ",") { + $parseddeps .= "\n"; + } else if($deps == " ") { + + } else { + $parseddeps .= $deps[$i]; + } +} +echo "{$parseddeps}\n"; echo "[depsend]\n"; echo "[repotype]\n"; -echo "archive\n"; +echo "{$mmmres['repotype']}\n"; echo "[repoaddr]\n"; -echo "{$row[9]}\n"; +echo "{$row['file']}\n"; echo "{end}\n"; diff --git a/api/3m/getmods.php b/api/3m/getmods.php index 91530a8..8fd21c0 100644 --- a/api/3m/getmods.php +++ b/api/3m/getmods.php @@ -10,11 +10,11 @@ header("Content-type: text/plain"); // Get projects loop while ($hash = mysql_fetch_assoc($res)){ - echo "{{$hash['name']}}\n"; + echo "{{$hash['basename']}}\n"; echo "[server]\n"; echo "multa.bugs3.com\n"; echo "[modinfo]\n"; - echo "minetest/forum/api/3m/getmodbyname?id={$hash['name']}\n"; + echo "minetest/forum/api/3m/getmodbyname?id={$hash['basename']}\n"; echo "{end}\n\n"; } diff --git a/deleteentry.php b/deleteentry.php index d141243..0737097 100644 --- a/deleteentry.php +++ b/deleteentry.php @@ -33,6 +33,9 @@ if ($name==""){ if ($do==true){ $name=mysql_real_escape_string($name); mysql_query("DELETE FROM mods WHERE name='$name'",$handle) or SQLerror("MySQL Query Error","Error finding entry $name"); + // 3m specific removal (by Phitherek_) + mysql_query("DELETE FROM 3m_specific WHERE id=".$id, $handle); + // End of Phitherek_' s code header("location: index.php"); } ?> diff --git a/editentry.php b/editentry.php index dcdfe9c..03f18ae 100644 --- a/editentry.php +++ b/editentry.php @@ -13,7 +13,12 @@ include "scripts/pageheader.php"; $res = mysql_query("SELECT * FROM mods WHERE mod_id=$id",$handle) or SQLerror("MySQL Query Error","Error on searching database.mods.mod_id for '$id'"); $row = mysql_fetch_row($res) or die("row error"); - +// Owner name instead of id, 3m_specific (by Phitherek_) +$owr = mysql_query("SELECT name FROM users WHERE id=".$row[3], $handle); +$owar = mysql_fetch_array($owr); +$mmmres = mysql_query("SELECT * FROM 3m_specific WHERE id=".$id, $handle); +$mmmarr = mysql_fetch_array($mmmres); +// End of Phitherek_' s code if (is_member_moderator($_SESSION['user']) || $_SESSION['user']==$row[3]){ }else{ SQLerror("Editing Denied","You do not own that entry, and you are not a moderator"); @@ -34,7 +39,16 @@ $version=$_POST['mod_version']; if ($version=="") $version=$row[2]; -$owner=$row[3]; +//3m release (by Phitherek_) +$mmmrel=$_POST['mmmrel']; +if($mmmrel=="") { +$mmmrel=$mmmarr['rel']; +} +//End of Phitherek_' s code + +// Owner name instead of id (by Phitherek_) +$owner=$owar['name']; +// End of Phitherek_' s change $desc=$_POST['mod_desc']; if ($desc=="") @@ -48,6 +62,13 @@ $license=$_POST['mod_lic']; if ($license=="") $license=$row[8]; +// 3m repotype (by Phitherek_) +$mmmrt=$_POST['mmmrt']; +if($mmmrt =="") { +$mmmrt = $mmmarr['repotype']; +} +// End of Phitherek_' s code + $file=$_POST['mod_file']; if ($file=="") $file=$row[9]; @@ -62,6 +83,9 @@ if ($basename=="") if ($do==true){ include "scripts/entry_adders_sql_safe.php"; mysql_query("UPDATE mods SET version='$version' WHERE name='$name'",$handle); + // 3m release (by Phitherek_) + mysql_query("UPDATE 3m_specific SET rel='$mmmrel' WHERE id='$id'",$handle) or SQLerror("Error on 3m_specific:rel",""); + // End of Phitherek_' s code /*echo "$name
"; echo "$desc
"; echo "$tags
"; @@ -72,6 +96,9 @@ if ($do==true){ mysql_query("UPDATE mods SET description='$desc' WHERE name='$name'",$handle) or SQLerror("Error on desc",""); mysql_query("UPDATE mods SET tags='$tags' WHERE name='$name'",$handle)or SQLerror("Error on tags",""); mysql_query("UPDATE mods SET license='$license' WHERE name='$name'",$handle)or SQLerror("Error on license",""); + // 3m repotype (by Phitherek_) + mysql_query("UPDATE 3m_specific SET repotype='$mmmrt' WHERE id='$id'",$handle) or SQLerror("Error on 3m_specific:repotype",""); + // End of Phitherek_' s code mysql_query("UPDATE mods SET file='$file' WHERE name='$name'",$handle)or SQLerror("Error on file",""); mysql_query("UPDATE mods SET depend='$depend' WHERE name='$name'",$handle)or SQLerror("Error on depend",""); mysql_query("UPDATE mods SET basename='$basename' WHERE name='$name'",$handle)or SQLerror("Error on basename",""); @@ -96,7 +123,10 @@ Help: Description Markup - Mod Name: -Version: + +Version: +3m Release: + @@ -110,6 +140,12 @@ Help: Description Markup - + +3m Repotype: + File URL: License: diff --git a/scripts/addentry.php b/scripts/addentry.php index abe017b..940a3bf 100644 --- a/scripts/addentry.php +++ b/scripts/addentry.php @@ -9,6 +9,12 @@ $version=$_POST['mod_version']; if ($version=="") return 0; +//3m release (by Phitherek_) +$mmmrel=$_POST['mmmrel']; +if ($mmrel=="") + return 0; +//End of Phitherek_' s code + $desc=$_POST['mod_desc']; if ($desc=="") return 0; @@ -23,6 +29,11 @@ if ($tags_msc=="") return 0; $license=$_POST['mod_lic']; +//3m repotype +$mmmrt=$_POST['mmmrt']; +if($mmmrt=="") + return 0; +//End of Phitherek_' s code $file=$_POST['mod_file']; if ($file=="") @@ -37,17 +48,27 @@ $owner=$_POST['user']; if ($owner=="") $owner=$_SESSION['user']; +//Extract ownerid from database (by Phitherek_) +$q = mysql_query("SELECT id FROM users WHERE name='".$owner."'"); +$qr = mysql_fetch_array($q); +$ownerid = $qr['id']; +//End of Phitherek_' s code //Load on_submit values $date = date('Y-m-d H:i:s'); $tags = "$tags_type,$tags_msc,"; if (entry_exists($name,$handle)) return 1; - +//Substitute owner with ownerid (by Phitherek_) mysql_query("INSERT INTO mods (name,version,owner,description,tags,likes,dislikes,license,file,depend,basename,date_released) -VALUES ('$name','$version','$owner','$desc','$tags',0,0,'$license','$file','$depend','$basename','$date')"); +VALUES ('$name','$version',$ownerid,'$desc','$tags',0,0,'$license','$file','$depend','$basename','$date')"); +//End of Phitherek_' s change $the_id=mysql_insert_id($handle); +//3m specific adding (by Phitherek_) +mysql_query("INSERT INTO 3m_specific VALUES($the_id,$mmmrel,'$mmmrt')"); +//End of Phitherek_' s code + header("location: viewmod.php?id=$the_id"); ?> \ No newline at end of file diff --git a/scripts/loadmods.php b/scripts/loadmods.php index d438e5d..f8ba383 100644 --- a/scripts/loadmods.php +++ b/scripts/loadmods.php @@ -12,8 +12,15 @@ while ($hash = mysql_fetch_assoc($res)){ }else{ $bgcolor="#FFFFBD"; } - - echo "{$hash['name']}
by {$hash['owner']}"; + + // Owner name from id (by Phitherek_) + $q = mysql_query("SELECT name FROM users WHERE id=".$hash['owner']); + $qr = mysql_fetch_array($q); + // End of Phitherek_' s code + + // Owner name instead of id (by Phitherek_) + echo "{$hash['name']}
by {$qr['name']}"; + // End of Phitherek_' s change echo "{$hash['likes']}"; echo "{$hash['tags']}"; echo "{$hash['license']}\n"; diff --git a/viewmod.php b/viewmod.php index 542ac09..5a7686f 100644 --- a/viewmod.php +++ b/viewmod.php @@ -17,19 +17,26 @@ $res = mysql_query("SELECT * FROM mods WHERE mod_id=$id",$handle) or SQLerror("M $row = mysql_fetch_row($res) or die("row error"); $page_title="View mod - {$row[1]}"; +// Substitute owner ID with owner name (by Phitherek_): +$r = mysql_query("SELECT name FROM users WHERE id=".$row[3],$handle) or SQLerror("MySQL Query Error","Error on getting owner name from users"); +$ra = mysql_fetch_array($r); +$owner = $ra['name']; +// End of Phitherek_' s code include "scripts/pageheader.php"; include "scripts/formatcode.php"; if (is_member_moderator($_SESSION['user']) || $_SESSION['user']==$row[3]){ -$links="Edit Delete"; +//3m Release Increasing (by Phitherek_) +$links="Edit Increase 3m Release Delete"; +//End of Phitherek_' s change }else{ $links=""; } echo ""; // Title and User Link +echo "

{$row[1]} - by {$owner}

"; // Title and User Link echo ""; // Version echo ""; // Description echo ""; // Likes
Download"; // Download Link -echo "

{$row[1]} - by {$row[3]}

{$row[2]}

".formatbb($row[4])."

+