@@ -45,8 +45,8 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | if ($config->getUseOnMemoryDB()) { |
| 47 | 47 | try { |
| 48 | - return new PDO("sqlite::memory:",$options); |
|
| 49 | - } catch (Exception $e){ |
|
| 48 | + return new PDO("sqlite::memory:", $options); |
|
| 49 | + } catch (Exception $e) { |
|
| 50 | 50 | throw new Exception("Could not create a db connection. Check permissions, configuration, and documentation. ".$e->getMessage()); |
| 51 | 51 | } |
| 52 | 52 | } |
@@ -193,11 +193,11 @@ discard block |
||
| 193 | 193 | * @param $config Configuration |
| 194 | 194 | */ |
| 195 | 195 | public static function checkHitTable($pdo, $config) { |
| 196 | - try{ |
|
| 196 | + try { |
|
| 197 | 197 | $db_hit_table = $config->getHitTableName(); |
| 198 | 198 | $stmt = $pdo->prepare("SELECT * FROM $db_hit_table WHERE 1==0"); |
| 199 | 199 | $stmt->execute(); |
| 200 | - } catch(Exception $e) { |
|
| 200 | + } catch (Exception $e) { |
|
| 201 | 201 | return false; |
| 202 | 202 | } |
| 203 | 203 | return true; |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | * @param $config Configuration |
| 210 | 210 | * |
| 211 | 211 | */ |
| 212 | - public static function updateCount($pdo, $config, $options =[]) { |
|
| 212 | + public static function updateCount($pdo, $config, $options = []) { |
|
| 213 | 213 | |
| 214 | 214 | $db_hit_table = $config->getHitTableName(); |
| 215 | 215 | $db_options_table = $config->getOptionsTableName(); |
@@ -222,10 +222,10 @@ discard block |
||
| 222 | 222 | |
| 223 | 223 | if (array_key_exists('url', $options)) { |
| 224 | 224 | $url = $options['url']; |
| 225 | - } else if (array_key_exists('HTTP_HOST',$_SERVER)) { |
|
| 225 | + } else if (array_key_exists('HTTP_HOST', $_SERVER)) { |
|
| 226 | 226 | $url = "http://".$_SERVER['HTTP_HOST']; |
| 227 | - if (array_key_exists('REQUEST_URI',$_SERVER)) { |
|
| 228 | - $url=$url.$_SERVER['REQUEST_URI']; |
|
| 227 | + if (array_key_exists('REQUEST_URI', $_SERVER)) { |
|
| 228 | + $url = $url.$_SERVER['REQUEST_URI']; |
|
| 229 | 229 | } |
| 230 | 230 | } else { |
| 231 | 231 | $url = "No Info"; |
@@ -243,14 +243,14 @@ discard block |
||
| 243 | 243 | |
| 244 | 244 | $stmt = $pdo->prepare("UPDATE $db_hit_table SET count = count + 1 WHERE id = ?"); |
| 245 | 245 | $stmt->execute([$id]); |
| 246 | - if ($stmt->rowCount() == 0) { |
|
| 246 | + if ($stmt->rowCount()==0) { |
|
| 247 | 247 | $stmt = $pdo->prepare("INSERT INTO $db_hit_table (id, count) VALUES (?, 1)"); |
| 248 | 248 | $stmt->execute([$id]); |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | $stmt = $pdo->prepare("UPDATE $db_url_table SET count = count + 1 WHERE id = ? and url = ?"); |
| 252 | 252 | $stmt->execute([$id, $url]); |
| 253 | - if ($stmt->rowCount() == 0) { |
|
| 253 | + if ($stmt->rowCount()==0) { |
|
| 254 | 254 | $stmt = $pdo->prepare("INSERT INTO $db_url_table (id, url, count) VALUES (?, ?, 1)"); |
| 255 | 255 | $stmt->execute([$id, $url]); |
| 256 | 256 | } |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | } |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | - if ($store_time||$store_user) { |
|
| 289 | + if ($store_time || $store_user) { |
|
| 290 | 290 | $stmt = $pdo->prepare("INSERT INTO $db_options_table (id, time, user) VALUES (?, ?, ?)"); |
| 291 | 291 | $stmt->execute([$id, time(), $user]); |
| 292 | 292 | } |
@@ -305,8 +305,8 @@ discard block |
||
| 305 | 305 | |
| 306 | 306 | $dbtable = $config->getUrlTableName(); |
| 307 | 307 | $stmt = $pdo->prepare("SELECT id,url,count FROM $dbtable WHERE url = '$url'"); |
| 308 | - if($stmt->execute()){ |
|
| 309 | - while($row = $stmt->fetch()){ |
|
| 308 | + if ($stmt->execute()) { |
|
| 309 | + while ($row = $stmt->fetch()) { |
|
| 310 | 310 | $resp[] = $row['id']; |
| 311 | 311 | } |
| 312 | 312 | } |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | $stmt = $pdo->prepare("SELECT id,count FROM $dbtable"); |
| 330 | 330 | if ($stmt->execute()) { |
| 331 | 331 | while ($row = $stmt->fetch()) { |
| 332 | - $resp[] = [$row['id'],$row['count']]; |
|
| 332 | + $resp[] = [$row['id'], $row['count']]; |
|
| 333 | 333 | } |
| 334 | 334 | } |
| 335 | 335 | |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | |
| 364 | 364 | $sql = "SELECT id,url,count FROM $dbtable"; |
| 365 | 365 | if (count($tquery) > 0) { |
| 366 | - $sql = $sql." WHERE ".join(" AND ",$tquery); |
|
| 366 | + $sql = $sql." WHERE ".join(" AND ", $tquery); |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | $stmt = $pdo->prepare($sql); |
@@ -384,9 +384,9 @@ discard block |
||
| 384 | 384 | * @param $config Configuration |
| 385 | 385 | * |
| 386 | 386 | */ |
| 387 | - public static function findIdByTimeUser($pdo, $config, $by = []){ |
|
| 387 | + public static function findIdByTimeUser($pdo, $config, $by = []) { |
|
| 388 | 388 | $resp = []; |
| 389 | - try{ |
|
| 389 | + try { |
|
| 390 | 390 | $dbtable = $config->getOptionsTableName(); |
| 391 | 391 | $qdata = []; |
| 392 | 392 | $tquery = []; |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | |
| 408 | 408 | $sql = "SELECT id,time,user FROM $dbtable"; |
| 409 | 409 | if (count($tquery) > 0) { |
| 410 | - $sql = $sql." WHERE ".join(" AND ",$tquery); |
|
| 410 | + $sql = $sql." WHERE ".join(" AND ", $tquery); |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | $stmt = $pdo->prepare($sql); |
@@ -443,7 +443,7 @@ discard block |
||
| 443 | 443 | } else if (array_key_exists('url', $by)) { |
| 444 | 444 | $qdata = [$by['url']]; |
| 445 | 445 | $tquery = "SELECT f.* FROM $dbFromtable f,$dbUrltable u where f.from_id = u.id and u.url = ?"; |
| 446 | - } else if (array_key_exists('id',$by)) { |
|
| 446 | + } else if (array_key_exists('id', $by)) { |
|
| 447 | 447 | $qdata = [$by['id']]; |
| 448 | 448 | $tquery = "SELECT f.* FROM $dbFromtable f where f.from_id = ?"; |
| 449 | 449 | } else { |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | $stmt = $pdo->prepare($tquery); |
| 455 | 455 | if ($stmt->execute($qdata)) { |
| 456 | 456 | while ($row = $stmt->fetch()) { |
| 457 | - $resp[] = [$row['id'],$row['from_id'],$row['count']]; |
|
| 457 | + $resp[] = [$row['id'], $row['from_id'], $row['count']]; |
|
| 458 | 458 | } |
| 459 | 459 | } |
| 460 | 460 | |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | $stmt = $pdo->prepare("SELECT h.id, u.url, h.count FROM $dbHitTable h, $dbUrlTable u WHERE h.id=u.id"); |
| 482 | 482 | if ($stmt->execute()) { |
| 483 | 483 | while ($row = $stmt->fetch()) { |
| 484 | - $resp[] = [$row[0], $row[1], $row[2],]; |
|
| 484 | + $resp[] = [$row[0], $row[1], $row[2], ]; |
|
| 485 | 485 | } |
| 486 | 486 | } |
| 487 | 487 | |
@@ -505,7 +505,7 @@ discard block |
||
| 505 | 505 | $stmt = $pdo->prepare("SELECT o.id, o.time, o.user FROM $dbOptionsTable o"); |
| 506 | 506 | if ($stmt->execute()) { |
| 507 | 507 | while ($row = $stmt->fetch()) { |
| 508 | - $resp[] = ['id'=>$row[0], 'time'=>$row[1], 'user'=>$row[2],]; |
|
| 508 | + $resp[] = ['id'=>$row[0], 'time'=>$row[1], 'user'=>$row[2], ]; |
|
| 509 | 509 | } |
| 510 | 510 | } |
| 511 | 511 | |