Преглед изворни кода

fix code errors (syntax only)
code formatting

causefx пре 8 година
родитељ
комит
48681ecfda
2 измењених фајлова са 142 додато и 136 уклоњено
  1. 22 12
      api/functions/api-functions.php
  2. 120 124
      api/functions/config-functions.php

+ 22 - 12
api/functions/api-functions.php

@@ -1,7 +1,12 @@
-<?php
+<?php /** @noinspection SqlResolve */
+/** @noinspection SqlResolve */
+/** @noinspection SqlResolve */
+/** @noinspection SqlResolve */
+/** @noinspection SyntaxError */
 function login($array)
 {
 	// Grab username and Password from login form
+	$username = $password = '';
 	foreach ($array['data'] as $items) {
 		foreach ($items as $key => $value) {
 			if ($key == 'name') {
@@ -31,6 +36,7 @@ function login($array)
 					$authSuccess = $function($username, $password);
 				}
 				break;
+			/** @noinspection PhpMissingBreakStatementInspection */
 			case 'both':
 				if (function_exists($function)) {
 					$authSuccess = $function($username, $password);
@@ -47,6 +53,7 @@ function login($array)
 		if ($authSuccess) {
 			// Make sure user exists in database
 			$userExists = false;
+			$passwordMatches = false;
 			$token = (is_array($authSuccess) && isset($authSuccess['token']) ? $authSuccess['token'] : '');
 			if ($result['username']) {
 				$userExists = true;
@@ -99,7 +106,7 @@ function createDB($path, $filename)
 			'database' => $path . $filename,
 		]);
 		// Create Users
-		$users = $createDB->query('CREATE TABLE `users` (
+		$createDB->query('CREATE TABLE `users` (
     		`id`	INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
     		`username`	TEXT UNIQUE,
     		`password`	TEXT,
@@ -113,21 +120,21 @@ function createDB($path, $filename)
     		`auth_service`	TEXT DEFAULT \'internal\'
     	);');
 		// Create Tokens
-		$jwt = $createDB->query('CREATE TABLE `tokens` (
+		$createDB->query('CREATE TABLE `tokens` (
     		`id`	INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
     		`token`	TEXT UNIQUE,
     		`user_id`	INTEGER,
             `created` DATE,
             `expires` DATE
     	);');
-		$groups = $createDB->query('CREATE TABLE `groups` (
+		$createDB->query('CREATE TABLE `groups` (
     		`id`	INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
     		`group`	TEXT UNIQUE,
             `group_id`	INTEGER,
     		`image`	TEXT,
             `default` INTEGER
     	);');
-		$categories = $createDB->query('CREATE TABLE `categories` (
+		$createDB->query('CREATE TABLE `categories` (
     		`id`	INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
             `order`	INTEGER,
     		`category`	TEXT UNIQUE,
@@ -136,7 +143,7 @@ function createDB($path, $filename)
             `default` INTEGER
     	);');
 		// Create Tabs
-		$tabs = $createDB->query('CREATE TABLE `tabs` (
+		$createDB->query('CREATE TABLE `tabs` (
     		`id`	INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
     		`order`	INTEGER,
     		`category_id`	INTEGER,
@@ -153,13 +160,13 @@ function createDB($path, $filename)
     		`ping_url`	TEXT
     	);');
 		// Create Options
-		$options = $createDB->query('CREATE TABLE `options` (
+		$createDB->query('CREATE TABLE `options` (
     		`id`	INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
     		`name`	TEXT UNIQUE,
     		`value`	TEXT
     	);');
 		// Create Invites
-		$invites = $createDB->query('CREATE TABLE `invites` (
+		$createDB->query('CREATE TABLE `invites` (
     		`id`	INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
     		`code`	TEXT UNIQUE,
     		`date`	TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
@@ -456,7 +463,7 @@ function adminEditGroup($array)
 			}
 			break;
 		default:
-			# code...
+			return false;
 			break;
 	}
 }
@@ -537,7 +544,7 @@ function adminEditUser($array)
 			}
 			break;
 		default:
-			# code...
+			return false;
 			break;
 	}
 }
@@ -727,7 +734,7 @@ function editTabs($array)
 			}
 			break;
 		default:
-			# code...
+			return false;
 			break;
 	}
 }
@@ -827,7 +834,7 @@ function editCategories($array)
 			}
 			break;
 		default:
-			# code...
+			return false;
 			break;
 	}
 }
@@ -925,6 +932,7 @@ function allTabs()
 			return false;
 		}
 	}
+	return false;
 }
 
 function allGroups()
@@ -941,6 +949,7 @@ function allGroups()
 			return false;
 		}
 	}
+	return false;
 }
 
 function loadTabs()
@@ -970,4 +979,5 @@ function loadTabs()
 			return false;
 		}
 	}
+	return false;
 }

+ 120 - 124
api/functions/config-functions.php

@@ -1,148 +1,144 @@
 <?php
-
 // Create config file in the return syntax
 function createConfig($array, $path = null, $nest = 0)
 {
-    $path = ($path) ? $path : $GLOBALS['userConfigPath'];
-    // Define Initial Value
-    $output = array();
-
-    // Sort Items
-    ksort($array);
-
-    // Update the current config version
-    if (!$nest) {
-        // Inject Current Version
-        $output[] = "\t'configVersion' => '".(isset($array['apply_CONFIG_VERSION'])?$array['apply_CONFIG_VERSION']:$GLOBALS['installedVersion'])."'";
-    }
-    unset($array['configVersion']);
-    unset($array['apply_CONFIG_VERSION']);
-
-    // Process Settings
-    foreach ($array as $k => $v) {
-        $allowCommit = true;
-        switch (gettype($v)) {
-            case 'boolean':
-                $item = ($v?'true':'false');
-                break;
-            case 'integer':
-            case 'double':
-            case 'integer':
-            case 'NULL':
-                $item = $v;
-                break;
-            case 'string':
-                $item = "'".str_replace(array('\\',"'"), array('\\\\',"\'"), $v)."'";
-                break;
-            case 'array':
-                $item = createConfig($v, false, $nest+1);
-                break;
-            default:
-                $allowCommit = false;
-        }
-
-        if ($allowCommit) {
-            $output[] = str_repeat("\t", $nest+1)."'$k' => $item";
-        }
-    }
-
-    // Build output
-    $output = (!$nest?"<?php\nreturn ":'')."array(\n".implode(",\n", $output)."\n".str_repeat("\t", $nest).')'.(!$nest?';':'');
-
-    if (!$nest && $path) {
-        $pathDigest = pathinfo($path);
-
-        @mkdir($pathDigest['dirname'], 0770, true);
-
-        if (file_exists($path)) {
-            rename($path, $pathDigest['dirname'].'/'.$pathDigest['filename'].'.bak.php');
-        }
-
-        $file = fopen($path, 'w');
-        fwrite($file, $output);
-        fclose($file);
-        if (file_exists($path)) {
-            return true;
-        }
-        // writeLog("error", "config was unable to write");
-        return false;
-    } else {
-        // writeLog("success", "config was updated with new values");
-        return $output;
-    }
+	$path = ($path) ? $path : $GLOBALS['userConfigPath'];
+	// Define Initial Value
+	$output = array();
+	// Sort Items
+	ksort($array);
+	// Update the current config version
+	if (!$nest) {
+		// Inject Current Version
+		$output[] = "\t'configVersion' => '" . (isset($array['apply_CONFIG_VERSION']) ? $array['apply_CONFIG_VERSION'] : $GLOBALS['installedVersion']) . "'";
+	}
+	unset($array['configVersion']);
+	unset($array['apply_CONFIG_VERSION']);
+	// Process Settings
+	foreach ($array as $k => $v) {
+		$allowCommit = true;
+		$item = '';
+		switch (gettype($v)) {
+			case 'boolean':
+				$item = ($v ? 'true' : 'false');
+				break;
+			case 'integer':
+			case 'double':
+			case 'NULL':
+				$item = $v;
+				break;
+			case 'string':
+				$item = "'" . str_replace(array('\\', "'"), array('\\\\', "\'"), $v) . "'";
+				break;
+			case 'array':
+				$item = createConfig($v, false, $nest + 1);
+				break;
+			default:
+				$allowCommit = false;
+		}
+		if ($allowCommit) {
+			$output[] = str_repeat("\t", $nest + 1) . "'$k' => $item";
+		}
+	}
+	// Build output
+	$output = (!$nest ? "<?php\nreturn " : '') . "array(\n" . implode(",\n", $output) . "\n" . str_repeat("\t", $nest) . ')' . (!$nest ? ';' : '');
+	if (!$nest && $path) {
+		$pathDigest = pathinfo($path);
+		@mkdir($pathDigest['dirname'], 0770, true);
+		if (file_exists($path)) {
+			rename($path, $pathDigest['dirname'] . '/' . $pathDigest['filename'] . '.bak.php');
+		}
+		$file = fopen($path, 'w');
+		fwrite($file, $output);
+		fclose($file);
+		if (file_exists($path)) {
+			return true;
+		}
+		// writeLog("error", "config was unable to write");
+		return false;
+	} else {
+		// writeLog("success", "config was updated with new values");
+		return $output;
+	}
 }
+
 // Commit new values to the configuration
 function updateConfig($new, $current = false)
 {
-    // Get config if not supplied
-    if ($current === false) {
-        $current = loadConfig();
-    } elseif (is_string($current) && is_file($current)) {
-        $current = loadConfig($current);
-    }
-    // Inject Parts
-    foreach ($new as $k => $v) {
-        $current[$k] = $v;
-    }
-    // Return Create
-    return createConfig($current);
+	// Get config if not supplied
+	if ($current === false) {
+		$current = loadConfig();
+	} elseif (is_string($current) && is_file($current)) {
+		$current = loadConfig($current);
+	}
+	// Inject Parts
+	foreach ($new as $k => $v) {
+		$current[$k] = $v;
+	}
+	// Return Create
+	return createConfig($current);
 }
+
 function configLazy()
 {
-    // Load config or default
-    if (file_exists($GLOBALS['userConfigPath'])) {
-        $config = fillDefaultConfig(loadConfig($GLOBALS['userConfigPath']));
-    } else {
-        $config = loadConfig($GLOBALS['defaultConfigPath']);
-    }
-    if (is_array($config)) {
-        defineConfig($config);
-    }
-    return $config;
+	// Load config or default
+	if (file_exists($GLOBALS['userConfigPath'])) {
+		$config = fillDefaultConfig(loadConfig($GLOBALS['userConfigPath']));
+	} else {
+		$config = loadConfig($GLOBALS['defaultConfigPath']);
+	}
+	if (is_array($config)) {
+		defineConfig($config);
+	}
+	return $config;
 }
+
 function loadConfig($path = null)
 {
-    $path = ($path) ? $path : $GLOBALS['userConfigPath'];
-    if (!is_file($path)) {
-        return null;
-    } else {
-        return (array) call_user_func(function () use ($path) {
-            return include($path);
-        });
-    }
+	$path = ($path) ? $path : $GLOBALS['userConfigPath'];
+	if (!is_file($path)) {
+		return null;
+	} else {
+		return (array)call_user_func(function () use ($path) {
+			return include($path);
+		});
+	}
 }
+
 function fillDefaultConfig($array)
 {
-    $path = $GLOBALS['defaultConfigPath'];
-    if (is_string($path)) {
-        $loadedDefaults = loadConfig($path);
-    } else {
-        $loadedDefaults = $path;
-    }
-    // Include all plugin config files
-    foreach (glob(dirname(__DIR__, 1).DIRECTORY_SEPARATOR.'plugins' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . "*.php") as $filename) {
-        $loadedDefaults = array_merge($loadedDefaults, loadConfig($filename));
-    }
-    return (is_array($loadedDefaults) ? fillDefaultConfig_recurse($array, $loadedDefaults) : false);
+	$path = $GLOBALS['defaultConfigPath'];
+	if (is_string($path)) {
+		$loadedDefaults = loadConfig($path);
+	} else {
+		$loadedDefaults = $path;
+	}
+	// Include all plugin config files
+	foreach (glob(dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . "*.php") as $filename) {
+		$loadedDefaults = array_merge($loadedDefaults, loadConfig($filename));
+	}
+	return (is_array($loadedDefaults) ? fillDefaultConfig_recurse($array, $loadedDefaults) : false);
 }
+
 function fillDefaultConfig_recurse($current, $defaults)
 {
-    foreach ($defaults as $k => $v) {
-        if (!isset($current[$k])) {
-            $current[$k] = $v;
-        } elseif (is_array($current[$k]) && is_array($v)) {
-            $current[$k] = fillDefaultConfig_recurse($current[$k], $v);
-        }
-    }
-    return $current;
+	foreach ($defaults as $k => $v) {
+		if (!isset($current[$k])) {
+			$current[$k] = $v;
+		} elseif (is_array($current[$k]) && is_array($v)) {
+			$current[$k] = fillDefaultConfig_recurse($current[$k], $v);
+		}
+	}
+	return $current;
 }
+
 function defineConfig($array, $anyCase = true, $nest_prefix = false)
 {
-    foreach ($array as $k => $v) {
-        if (is_scalar($v) && !defined($nest_prefix.$k)) {
-            $GLOBALS[$nest_prefix.$k] = $v;
-        } elseif (is_array($v)) {
-            defineConfig($v, $anyCase, $nest_prefix.$k.'_');
-        }
-    }
+	foreach ($array as $k => $v) {
+		if (is_scalar($v) && !defined($nest_prefix . $k)) {
+			$GLOBALS[$nest_prefix . $k] = $v;
+		} elseif (is_array($v)) {
+			defineConfig($v, $anyCase, $nest_prefix . $k . '_');
+		}
+	}
 }