Skip to content

Commit

Permalink
Merge pull request #18 - Updated the code format
Browse files Browse the repository at this point in the history
Updated code format
  • Loading branch information
owenvoke committed Aug 30, 2016
2 parents e45a24e + 60518ed commit 7dfb943
Show file tree
Hide file tree
Showing 14 changed files with 429 additions and 428 deletions.
22 changes: 11 additions & 11 deletions api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
include ('../funcs.php');
if (isset($_GET['h']) && !empty($_GET['h']) && strlen($_GET['h']) == 40) {
$db_conn = \funcs\Functions::conn();
$sql = "SELECT * FROM t_collection WHERE torrent_info_hash='" . mysqli_real_escape_string($db_conn, $_GET['h']) . "'";
$sql = "SELECT * FROM t_collection WHERE torrent_info_hash='".mysqli_real_escape_string($db_conn, $_GET['h'])."'";
$res = \funcs\Functions::query($db_conn, $sql);

while ($row = mysqli_fetch_assoc($res)) {
Expand Down Expand Up @@ -32,30 +32,30 @@
}

if (isset($_GET['q']) && !empty($_GET['q'])) {
$query = "WHERE torrent_name LIKE '%" . mysqli_real_escape_string($db_conn, $_GET['q']) . "%' ";
$query = "WHERE torrent_name LIKE '%".mysqli_real_escape_string($db_conn, $_GET['q'])."%' ";
}
else {
$query = '';
}

if (isset($_GET['c']) && !empty($_GET['c'])) {
if ($query !== '') {
$category = "AND category_id = " . mysqli_real_escape_string($db_conn, $_GET['c']) . " ";
$category = "AND category_id = ".mysqli_real_escape_string($db_conn, $_GET['c'])." ";
}
else {
$category = "WHERE category_id = " . mysqli_real_escape_string($db_conn, $_GET['c']) . " ";
$category = "WHERE category_id = ".mysqli_real_escape_string($db_conn, $_GET['c'])." ";
}
}
else {
$category = '';
}

$sql = "SELECT * FROM t_collection " . $query . $category . "LIMIT " . mysqli_real_escape_string($db_conn, $startPoint) . ", 20";
$sql = "SELECT * FROM t_collection ".$query.$category."LIMIT ".mysqli_real_escape_string($db_conn, $startPoint).", 20";
if (isset($_GET['debug']) && !empty($_GET['debug']) && $_GET['debug'] == 'awfj23th1hgewjgojgqpow3f0j3tq') {
echo $sql;
exit();
}
$res = \funcs\Functions::query($db_conn, $sql);
$res = \funcs\Functions::query($db_conn, $sql);

while ($row = mysqli_fetch_assoc($res)) {
if ($row['torrent_info_hash'] !== '') {
Expand All @@ -75,8 +75,8 @@
);
}
if (isset($_GET["pretty"]) && $_GET["pretty"] == "true") {
echo json_encode($data, JSON_PRETTY_PRINT);
}
else {
echo json_encode($data);
}
echo json_encode($data, JSON_PRETTY_PRINT);
}
else {
echo json_encode($data);
}
20 changes: 10 additions & 10 deletions cron/create_dump.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
// GENERATE MYSQL DUMP
// Generates a daily MySQL dump for importing.

$tableName = 't_collection';
$db_name = 'kat_db';
$tableName = 't_collection';
$db_name = 'kat_db';
$db_user = "root";
$db_pass = '';
$backup_file = "exports/daily_dump_".date("Y-m-d").".sql";
$cmd = "mysqldump --insert-ignore --skip-add-drop-table --no-create-info -u $db_user -p$db_pass $db_name $tableName > $backup_file";
if (!file_exists($backup_file . ".gz")) {
$backup_file = "exports/daily_dump_".date("Y-m-d").".sql";
$cmd = "mysqldump --insert-ignore --skip-add-drop-table --no-create-info -u $db_user -p$db_pass $db_name $tableName > $backup_file";
if (!file_exists($backup_file.".gz")) {
exec($cmd);
}

Expand All @@ -19,7 +19,7 @@ function scan_dir($dir = "exports") {
$files = array();
foreach (scandir($dir) as $file) {
if (in_array($file, $ignored)) continue;
$files[$file] = filemtime($dir . '/' . $file);
$files[$file] = filemtime($dir.'/'.$file);
}

arsort($files);
Expand All @@ -33,11 +33,11 @@ function scan_dir($dir = "exports") {
foreach ($dir_files as $file) {
if (substr($file, -4) === ".sql") {
// Name of the gz file we're creating
$gzfile = "./exports/" . $file . ".gz";
$gzfile = "./exports/".$file.".gz";

$error = false;
if ($fp_out = gzopen($gzfile, "wb9")) {
if ($fp_in = fopen("./exports/" . $file, 'rb')) {
if ($fp_in = fopen("./exports/".$file, 'rb')) {
while (!feof($fp_in))
gzwrite($fp_out, fread($fp_in, 1024 * 512));
fclose($fp_in);
Expand All @@ -53,10 +53,10 @@ function scan_dir($dir = "exports") {
echo "error\n";
}

unlink("./exports/" . $file);
unlink("./exports/".$file);
}
}

if (count($dir_files) > 2) {
unlink ("exports/" . $dir_files[3]);
unlink("exports/".$dir_files[3]);
}
2 changes: 1 addition & 1 deletion cron/exports/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function scan_dir($dir = ".") {
$files = array();
foreach (scandir($dir) as $file) {
if (in_array($file, $ignored)) continue;
$files[$file] = filemtime($dir . '/' . $file);
$files[$file] = filemtime($dir.'/'.$file);
}

arsort($files);
Expand Down
Loading

0 comments on commit 7dfb943

Please sign in to comment.