@@ -654,9 +654,9 @@ |
||
| 654 | 654 | |
| 655 | 655 | public function isCheckuser() |
| 656 | 656 | { |
| 657 | - if($this->isCheckuserCache === null) { |
|
| 658 | - $this->isCheckuserCache = $this->checkuser == 1 || $this->oauthCanCheckUser(); |
|
| 659 | - } |
|
| 657 | + if($this->isCheckuserCache === null) { |
|
| 658 | + $this->isCheckuserCache = $this->checkuser == 1 || $this->oauthCanCheckUser(); |
|
| 659 | + } |
|
| 660 | 660 | |
| 661 | 661 | return $this->isCheckuserCache; |
| 662 | 662 | } |
@@ -654,7 +654,7 @@ |
||
| 654 | 654 | |
| 655 | 655 | public function isCheckuser() |
| 656 | 656 | { |
| 657 | - if($this->isCheckuserCache === null) { |
|
| 657 | + if ($this->isCheckuserCache === null) { |
|
| 658 | 658 | $this->isCheckuserCache = $this->checkuser == 1 || $this->oauthCanCheckUser(); |
| 659 | 659 | } |
| 660 | 660 | |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if (isset($_SERVER['REQUEST_METHOD'])) { |
| 4 | - die(); |
|
| 4 | + die(); |
|
| 5 | 5 | } // Web clients die. |
| 6 | 6 | |
| 7 | 7 | ini_set('display_errors', 1); |
@@ -17,19 +17,19 @@ discard block |
||
| 17 | 17 | $locationProvider = new IpLocationProvider($database, $locationProviderApiKey); |
| 18 | 18 | |
| 19 | 19 | while (true) { |
| 20 | - echo "Beginning txn\n"; |
|
| 21 | - $database->beginTransaction(); |
|
| 20 | + echo "Beginning txn\n"; |
|
| 21 | + $database->beginTransaction(); |
|
| 22 | 22 | |
| 23 | - try { |
|
| 24 | - // fetch a bunch of un-geolocated IPs from the database. |
|
| 25 | - // note we have to parse the forwardedip field in the database so we can test against the geolocation table. |
|
| 26 | - // This guarantees we get ten unlocated IPs back, unless there actually aren't 10 available. |
|
| 27 | - // Alternatives include downloading a small set of forwarded IPs, splitting it in PHP, constructing an IN() |
|
| 28 | - // clause dynamically, sending that back to the database to check if there are geolocation entries, then repeating |
|
| 29 | - // until we have 10 to process - and the fact that we'd have to potentially retrieve all IPs from the database |
|
| 30 | - // before we find any at all. This way keeps all of that legwork in the database, at the cost of a more complex |
|
| 31 | - // query. |
|
| 32 | - $statement = $database->query(<<<SQL |
|
| 23 | + try { |
|
| 24 | + // fetch a bunch of un-geolocated IPs from the database. |
|
| 25 | + // note we have to parse the forwardedip field in the database so we can test against the geolocation table. |
|
| 26 | + // This guarantees we get ten unlocated IPs back, unless there actually aren't 10 available. |
|
| 27 | + // Alternatives include downloading a small set of forwarded IPs, splitting it in PHP, constructing an IN() |
|
| 28 | + // clause dynamically, sending that back to the database to check if there are geolocation entries, then repeating |
|
| 29 | + // until we have 10 to process - and the fact that we'd have to potentially retrieve all IPs from the database |
|
| 30 | + // before we find any at all. This way keeps all of that legwork in the database, at the cost of a more complex |
|
| 31 | + // query. |
|
| 32 | + $statement = $database->query(<<<SQL |
|
| 33 | 33 | SELECT p.prox |
| 34 | 34 | FROM ( |
| 35 | 35 | SELECT trim(substring_index(substring_index(r.forwardedip, ',', n.n), ',', -1)) prox |
@@ -46,38 +46,38 @@ discard block |
||
| 46 | 46 | WHERE NOT EXISTS (SELECT 1 FROM geolocation g WHERE g.address = p.prox) |
| 47 | 47 | LIMIT 10; |
| 48 | 48 | SQL |
| 49 | - ); |
|
| 49 | + ); |
|
| 50 | 50 | |
| 51 | - $missingIps = $statement->fetchAll(PDO::FETCH_COLUMN); |
|
| 51 | + $missingIps = $statement->fetchAll(PDO::FETCH_COLUMN); |
|
| 52 | 52 | |
| 53 | - $count = count($missingIps); |
|
| 54 | - if ($count === 0) { |
|
| 55 | - echo ". Found nothing to do.\n"; |
|
| 56 | - break; |
|
| 57 | - } |
|
| 53 | + $count = count($missingIps); |
|
| 54 | + if ($count === 0) { |
|
| 55 | + echo ". Found nothing to do.\n"; |
|
| 56 | + break; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - echo ". Picked {$count} IP addresses\n"; |
|
| 59 | + echo ". Picked {$count} IP addresses\n"; |
|
| 60 | 60 | |
| 61 | - foreach ($missingIps as $ip) { |
|
| 62 | - echo ". . Getting location for {$ip}...\n"; |
|
| 63 | - $data = json_encode($locationProvider->getIpLocation($ip)); |
|
| 64 | - echo ". . . {$data}\n"; |
|
| 65 | - } |
|
| 61 | + foreach ($missingIps as $ip) { |
|
| 62 | + echo ". . Getting location for {$ip}...\n"; |
|
| 63 | + $data = json_encode($locationProvider->getIpLocation($ip)); |
|
| 64 | + echo ". . . {$data}\n"; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - echo ". IP location fetch complete.\n"; |
|
| 68 | - $database->commit(); |
|
| 69 | - echo ". Committed txn.\n"; |
|
| 70 | - } catch (Exception $ex) { |
|
| 71 | - echo ". Encountered exception: " . $ex->getMessage(). "\n"; |
|
| 72 | - $database->rollBack(); |
|
| 73 | - echo ". Rolled back txn\n"; |
|
| 74 | - throw $ex; |
|
| 75 | - } finally { |
|
| 76 | - if($database->hasActiveTransaction()){ |
|
| 77 | - $database->rollBack(); |
|
| 78 | - echo ". Rolled back txn\n"; |
|
| 79 | - } |
|
| 80 | - } |
|
| 67 | + echo ". IP location fetch complete.\n"; |
|
| 68 | + $database->commit(); |
|
| 69 | + echo ". Committed txn.\n"; |
|
| 70 | + } catch (Exception $ex) { |
|
| 71 | + echo ". Encountered exception: " . $ex->getMessage(). "\n"; |
|
| 72 | + $database->rollBack(); |
|
| 73 | + echo ". Rolled back txn\n"; |
|
| 74 | + throw $ex; |
|
| 75 | + } finally { |
|
| 76 | + if($database->hasActiveTransaction()){ |
|
| 77 | + $database->rollBack(); |
|
| 78 | + echo ". Rolled back txn\n"; |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | echo "Done.\n"; |
@@ -68,12 +68,12 @@ |
||
| 68 | 68 | $database->commit(); |
| 69 | 69 | echo ". Committed txn.\n"; |
| 70 | 70 | } catch (Exception $ex) { |
| 71 | - echo ". Encountered exception: " . $ex->getMessage(). "\n"; |
|
| 71 | + echo ". Encountered exception: " . $ex->getMessage() . "\n"; |
|
| 72 | 72 | $database->rollBack(); |
| 73 | 73 | echo ". Rolled back txn\n"; |
| 74 | 74 | throw $ex; |
| 75 | 75 | } finally { |
| 76 | - if($database->hasActiveTransaction()){ |
|
| 76 | + if ($database->hasActiveTransaction()) { |
|
| 77 | 77 | $database->rollBack(); |
| 78 | 78 | echo ". Rolled back txn\n"; |
| 79 | 79 | } |
@@ -67,13 +67,15 @@ |
||
| 67 | 67 | echo ". IP location fetch complete.\n"; |
| 68 | 68 | $database->commit(); |
| 69 | 69 | echo ". Committed txn.\n"; |
| 70 | - } catch (Exception $ex) { |
|
| 70 | + } |
|
| 71 | + catch (Exception $ex) { |
|
| 71 | 72 | echo ". Encountered exception: " . $ex->getMessage(). "\n"; |
| 72 | 73 | $database->rollBack(); |
| 73 | 74 | echo ". Rolled back txn\n"; |
| 74 | 75 | throw $ex; |
| 75 | - } finally { |
|
| 76 | - if($database->hasActiveTransaction()){ |
|
| 76 | + } |
|
| 77 | + finally { |
|
| 78 | + if($database->hasActiveTransaction()) { |
|
| 77 | 79 | $database->rollBack(); |
| 78 | 80 | echo ". Rolled back txn\n"; |
| 79 | 81 | } |
@@ -10,8 +10,7 @@ |
||
| 10 | 10 | |
| 11 | 11 | $db = gGetDb( ); |
| 12 | 12 | |
| 13 | -$db->transactionally(function() use ($db) |
|
| 14 | -{ |
|
| 13 | +$db->transactionally(function() use ($db) { |
|
| 15 | 14 | global $cDataClearIp, $cDataClearEmail, $dataclear_interval, $enableEmailConfirm; |
| 16 | 15 | |
| 17 | 16 | $query = $db->prepare("UPDATE request SET ip = :ip, forwardedip = null, email = :mail, useragent = '' WHERE date < DATE_SUB(curdate(), INTERVAL $dataclear_interval) AND status = 'Closed';"); |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | /** Initialises the PHP Session */ |
| 30 | 30 | function initialiseSession() { |
| 31 | - session_start(); |
|
| 31 | + session_start(); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | "requests" => $requests, |
| 161 | 161 | "total" => $totalRequests, |
| 162 | 162 | "api" => $v['api'], |
| 163 | - "type" => $type); |
|
| 163 | + "type" => $type); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | global $smarty; |
@@ -27,7 +27,8 @@ |
||
| 27 | 27 | $session = new session(); |
| 28 | 28 | |
| 29 | 29 | /** Initialises the PHP Session */ |
| 30 | -function initialiseSession() { |
|
| 30 | +function initialiseSession() |
|
| 31 | +{ |
|
| 31 | 32 | session_start(); |
| 32 | 33 | } |
| 33 | 34 | |
@@ -2035,41 +2035,41 @@ |
||
| 2035 | 2035 | }); |
| 2036 | 2036 | } |
| 2037 | 2037 | elseif ($action == "listall") { |
| 2038 | - global $availableRequestStates, $enableEmailConfirm; |
|
| 2038 | + global $availableRequestStates, $enableEmailConfirm; |
|
| 2039 | 2039 | |
| 2040 | 2040 | if (isset($_GET['status']) && isset($availableRequestStates[$_GET['status']])) { |
| 2041 | 2041 | $type = $_GET['status']; // safe, we've verified it's sane in the above if statement. |
| 2042 | 2042 | |
| 2043 | - $database = gGetDb(); |
|
| 2043 | + $database = gGetDb(); |
|
| 2044 | 2044 | |
| 2045 | - if ($enableEmailConfirm == 1) { |
|
| 2046 | - $query = "SELECT * FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
|
| 2047 | - } else { |
|
| 2048 | - $query = "SELECT * FROM request WHERE status = :type;"; |
|
| 2049 | - } |
|
| 2045 | + if ($enableEmailConfirm == 1) { |
|
| 2046 | + $query = "SELECT * FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
|
| 2047 | + } else { |
|
| 2048 | + $query = "SELECT * FROM request WHERE status = :type;"; |
|
| 2049 | + } |
|
| 2050 | 2050 | |
| 2051 | - $statement = $database->prepare($query); |
|
| 2051 | + $statement = $database->prepare($query); |
|
| 2052 | 2052 | |
| 2053 | - $statement->bindValue(":type", $type); |
|
| 2054 | - $statement->execute(); |
|
| 2053 | + $statement->bindValue(":type", $type); |
|
| 2054 | + $statement->execute(); |
|
| 2055 | 2055 | |
| 2056 | - $requests = $statement->fetchAll(PDO::FETCH_CLASS, "Request"); |
|
| 2057 | - foreach ($requests as $req) { |
|
| 2058 | - /** @var Request $req */ |
|
| 2059 | - $req->setDatabase($database); |
|
| 2060 | - } |
|
| 2056 | + $requests = $statement->fetchAll(PDO::FETCH_CLASS, "Request"); |
|
| 2057 | + foreach ($requests as $req) { |
|
| 2058 | + /** @var Request $req */ |
|
| 2059 | + $req->setDatabase($database); |
|
| 2060 | + } |
|
| 2061 | 2061 | |
| 2062 | - global $smarty; |
|
| 2063 | - $smarty->assign("requests", $requests); |
|
| 2064 | - $smarty->assign("showStatus", false); |
|
| 2065 | - $html = $smarty->fetch("mainpage/requesttable.tpl"); |
|
| 2066 | - echo $html; |
|
| 2067 | - } else { |
|
| 2068 | - echo defaultpage(); |
|
| 2069 | - } |
|
| 2062 | + global $smarty; |
|
| 2063 | + $smarty->assign("requests", $requests); |
|
| 2064 | + $smarty->assign("showStatus", false); |
|
| 2065 | + $html = $smarty->fetch("mainpage/requesttable.tpl"); |
|
| 2066 | + echo $html; |
|
| 2067 | + } else { |
|
| 2068 | + echo defaultpage(); |
|
| 2069 | + } |
|
| 2070 | 2070 | |
| 2071 | - BootstrapSkin::displayInternalFooter(); |
|
| 2072 | - die(); |
|
| 2071 | + BootstrapSkin::displayInternalFooter(); |
|
| 2072 | + die(); |
|
| 2073 | 2073 | } |
| 2074 | 2074 | # If the action specified does not exist, goto the default page. |
| 2075 | 2075 | else { |
@@ -152,8 +152,7 @@ discard block |
||
| 152 | 152 | |
| 153 | 153 | $database = gGetDb(); |
| 154 | 154 | |
| 155 | - $database->transactionally(function() use ($database, $useOauthSignup) |
|
| 156 | - { |
|
| 155 | + $database->transactionally(function() use ($database, $useOauthSignup) { |
|
| 157 | 156 | |
| 158 | 157 | $newUser = new User(); |
| 159 | 158 | $newUser->setDatabase($database); |
@@ -481,8 +480,7 @@ discard block |
||
| 481 | 480 | |
| 482 | 481 | $database = gGetDb(); |
| 483 | 482 | |
| 484 | - $database->transactionally(function() use ($database) |
|
| 485 | - { |
|
| 483 | + $database->transactionally(function() use ($database) { |
|
| 486 | 484 | global $smarty; |
| 487 | 485 | |
| 488 | 486 | $message = InterfaceMessage::getById($_GET['edit'], $database); |
@@ -570,8 +568,7 @@ discard block |
||
| 570 | 568 | |
| 571 | 569 | $database = gGetDb(); |
| 572 | 570 | |
| 573 | - $database->transactionally(function() use ($database, $baseurl) |
|
| 574 | - { |
|
| 571 | + $database->transactionally(function() use ($database, $baseurl) { |
|
| 575 | 572 | $template = new WelcomeTemplate(); |
| 576 | 573 | $template->setDatabase($database); |
| 577 | 574 | $template->setUserCode($_POST['usercode']); |
@@ -656,8 +653,7 @@ discard block |
||
| 656 | 653 | die(); |
| 657 | 654 | } |
| 658 | 655 | |
| 659 | - $database->transactionally(function() use($database, $template) |
|
| 660 | - { |
|
| 656 | + $database->transactionally(function() use($database, $template) { |
|
| 661 | 657 | $tid = $template->getId(); |
| 662 | 658 | |
| 663 | 659 | $database |
@@ -693,8 +689,7 @@ discard block |
||
| 693 | 689 | } |
| 694 | 690 | |
| 695 | 691 | if (isset($_POST['submit'])) { |
| 696 | - $database->transactionally(function() use($database, $template) |
|
| 697 | - { |
|
| 692 | + $database->transactionally(function() use($database, $template) { |
|
| 698 | 693 | $template->setUserCode($_POST['usercode']); |
| 699 | 694 | $template->setBotCode($_POST['botcode']); |
| 700 | 695 | $template->save(); |
@@ -825,8 +820,7 @@ discard block |
||
| 825 | 820 | |
| 826 | 821 | $currentUsername = User::getCurrent()->getUsername(); |
| 827 | 822 | |
| 828 | - $database->transactionally(function() use ($database, $ban, $duration, $currentUsername) |
|
| 829 | - { |
|
| 823 | + $database->transactionally(function() use ($database, $ban, $duration, $currentUsername) { |
|
| 830 | 824 | $ban->setDatabase($database); |
| 831 | 825 | $ban->setActive(1); |
| 832 | 826 | $ban->setType($_POST['type']); |
@@ -891,8 +885,7 @@ discard block |
||
| 891 | 885 | else { |
| 892 | 886 | $database = gGetDb(); |
| 893 | 887 | |
| 894 | - $database->transactionally(function() use ($database, $ban) |
|
| 895 | - { |
|
| 888 | + $database->transactionally(function() use ($database, $ban) { |
|
| 896 | 889 | $ban->setActive(0); |
| 897 | 890 | $ban->save(); |
| 898 | 891 | |
@@ -1041,8 +1034,7 @@ discard block |
||
| 1041 | 1034 | } |
| 1042 | 1035 | |
| 1043 | 1036 | $database = gGetDb(); |
| 1044 | - $database->transactionally(function() use ($database, $request) |
|
| 1045 | - { |
|
| 1037 | + $database->transactionally(function() use ($database, $request) { |
|
| 1046 | 1038 | global $availableRequestStates; |
| 1047 | 1039 | |
| 1048 | 1040 | $request->setReserved(0); |
@@ -1192,7 +1184,8 @@ discard block |
||
| 1192 | 1184 | $emailTemplate = EmailTemplate::getById($gem, gGetDb()); |
| 1193 | 1185 | if ($emailTemplate instanceof EmailTemplate) { |
| 1194 | 1186 | $isForCreated = $emailTemplate->getDefaultAction() === EmailTemplate::CREATED; |
| 1195 | - } else { |
|
| 1187 | + } |
|
| 1188 | + else { |
|
| 1196 | 1189 | $isForCreated = false; |
| 1197 | 1190 | } |
| 1198 | 1191 | |
@@ -1461,8 +1454,7 @@ discard block |
||
| 1461 | 1454 | elseif ($action == "reserve") { |
| 1462 | 1455 | $database = gGetDb(); |
| 1463 | 1456 | |
| 1464 | - $database->transactionally(function() use ($database) |
|
| 1465 | - { |
|
| 1457 | + $database->transactionally(function() use ($database) { |
|
| 1466 | 1458 | $request = Request::getById($_GET['resid'], $database); |
| 1467 | 1459 | |
| 1468 | 1460 | if ($request == false) { |
@@ -1565,8 +1557,7 @@ discard block |
||
| 1565 | 1557 | if ($reservedUser->getId() != User::getCurrent()->getId()) { |
| 1566 | 1558 | if (User::getCurrent()->isAdmin()) { |
| 1567 | 1559 | if (isset($_GET['confirm']) && $_GET['confirm'] == 1) { |
| 1568 | - $database->transactionally(function() use($database, $request) |
|
| 1569 | - { |
|
| 1560 | + $database->transactionally(function() use($database, $request) { |
|
| 1570 | 1561 | $request->setReserved(0); |
| 1571 | 1562 | $request->save(); |
| 1572 | 1563 | |
@@ -1591,8 +1582,7 @@ discard block |
||
| 1591 | 1582 | } |
| 1592 | 1583 | } |
| 1593 | 1584 | else { |
| 1594 | - $database->transactionally(function() use ($database, $request) |
|
| 1595 | - { |
|
| 1585 | + $database->transactionally(function() use ($database, $request) { |
|
| 1596 | 1586 | $request->setReserved(0); |
| 1597 | 1587 | $request->save(); |
| 1598 | 1588 | |
@@ -1785,8 +1775,7 @@ discard block |
||
| 1785 | 1775 | |
| 1786 | 1776 | if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
| 1787 | 1777 | $database = gGetDb(); |
| 1788 | - $database->transactionally(function() use ($database, $comment, $baseurl) |
|
| 1789 | - { |
|
| 1778 | + $database->transactionally(function() use ($database, $comment, $baseurl) { |
|
| 1790 | 1779 | |
| 1791 | 1780 | $comment->setComment($_POST['newcomment']); |
| 1792 | 1781 | $comment->setVisibility($_POST['visibility']); |
@@ -1834,8 +1823,7 @@ discard block |
||
| 1834 | 1823 | die(); |
| 1835 | 1824 | } |
| 1836 | 1825 | |
| 1837 | - $database->transactionally(function() use ($database, $user, $requestObject, $curuser) |
|
| 1838 | - { |
|
| 1826 | + $database->transactionally(function() use ($database, $user, $requestObject, $curuser) { |
|
| 1839 | 1827 | $updateStatement = $database->prepare("UPDATE request SET reserved = :userid WHERE id = :request LIMIT 1;"); |
| 1840 | 1828 | $updateStatement->bindValue(":userid", $user->getId()); |
| 1841 | 1829 | $updateStatement->bindValue(":request", $requestObject->getId()); |
@@ -1863,8 +1851,7 @@ discard block |
||
| 1863 | 1851 | } |
| 1864 | 1852 | if (isset($_POST['submit'])) { |
| 1865 | 1853 | $database = gGetDb(); |
| 1866 | - $database->transactionally(function() use ($database) |
|
| 1867 | - { |
|
| 1854 | + $database->transactionally(function() use ($database) { |
|
| 1868 | 1855 | global $baseurl; |
| 1869 | 1856 | |
| 1870 | 1857 | $emailTemplate = new EmailTemplate(); |
@@ -1942,8 +1929,7 @@ discard block |
||
| 1942 | 1929 | die(); |
| 1943 | 1930 | } |
| 1944 | 1931 | |
| 1945 | - $database->transactionally(function() use ($database, $emailTemplate) |
|
| 1946 | - { |
|
| 1932 | + $database->transactionally(function() use ($database, $emailTemplate) { |
|
| 1947 | 1933 | $emailTemplate->save(); |
| 1948 | 1934 | |
| 1949 | 1935 | Logger::editedEmail($database, $emailTemplate); |
@@ -2008,8 +1994,7 @@ discard block |
||
| 2008 | 1994 | } |
| 2009 | 1995 | elseif ($action == "oauthattach") { |
| 2010 | 1996 | $database = gGetDb(); |
| 2011 | - $database->transactionally(function() use ($database) |
|
| 2012 | - { |
|
| 1997 | + $database->transactionally(function() use ($database) { |
|
| 2013 | 1998 | try { |
| 2014 | 1999 | global $oauthConsumerToken, $oauthSecretToken, $oauthBaseUrl, $oauthBaseUrlInternal; |
| 2015 | 2000 | |
@@ -2044,7 +2029,8 @@ discard block |
||
| 2044 | 2029 | |
| 2045 | 2030 | if ($enableEmailConfirm == 1) { |
| 2046 | 2031 | $query = "SELECT * FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
| 2047 | - } else { |
|
| 2032 | + } |
|
| 2033 | + else { |
|
| 2048 | 2034 | $query = "SELECT * FROM request WHERE status = :type;"; |
| 2049 | 2035 | } |
| 2050 | 2036 | |
@@ -2064,7 +2050,8 @@ discard block |
||
| 2064 | 2050 | $smarty->assign("showStatus", false); |
| 2065 | 2051 | $html = $smarty->fetch("mainpage/requesttable.tpl"); |
| 2066 | 2052 | echo $html; |
| 2067 | - } else { |
|
| 2053 | + } |
|
| 2054 | + else { |
|
| 2068 | 2055 | echo defaultpage(); |
| 2069 | 2056 | } |
| 2070 | 2057 | |