Browse Source

Miscellaneous changes to bring public repo in line with private

This consists mostly of commits I somehow skipped over and didn't patch
into the public repo
spaghetti 8 years ago
parent
commit
e51d6963b4

+ 3
- 3
classes/config.template View File

@@ -1,6 +1,6 @@
1 1
 <?php
2 2
 if (version_compare(PHP_VERSION, '7.0.0', '<')) {
3
-  die("Gazelle requires PHP 7.0 or later to function properly");
3
+  die("Gazelle requires PHP 7.0.0 or later to function properly");
4 4
 }
5 5
 //date_default_timezone_set('EST');
6 6
 
@@ -79,8 +79,8 @@ define('DONOR_INVITES',     2);
79 79
 define('FEATURE_EMAIL_REENABLE',     true);
80 80
 define('FEATURE_SEND_EMAIL',         true);  //Attempt to send email from the site
81 81
 define('FEATURE_IRC',                true);  //Attempt to send messages to IRC
82
-define('FEATURE_ENFORCE_LOCATIONS',  true);  //Require users to verify login from unknown devices
83
-define('FEATURE_SET_ENC_KEY_PUBLIC', false); //Allow the site encryption key to be set without an account
82
+define('FEATURE_ENFORCE_LOCATIONS',  true);  //Require users to verify login from unknown locations
83
+define('FEATURE_SET_ENC_KEY_PUBLIC', false); //Allow the site encryption key to be set without an account (Should only be used for initial setup)
84 84
 
85 85
 // User class IDs needed for automatic promotions. Found in the 'permissions' table
86 86
 // Name of class  Class ID (NOT level)

+ 22
- 7
classes/mysql.class.php View File

@@ -222,17 +222,32 @@ class DB_MYSQL {
222 222
     }
223 223
     $QueryStartTime = microtime(true);
224 224
     $this->connect();
225
-    // In the event of a MySQL deadlock, we sleep allowing MySQL time to unlock, then attempt again for a maximum of 5 tries
226
-    for ($i = 1; $i < 6; $i++) {
225
+
226
+    if (DEBUG_MODE) {
227 227
       $this->QueryID = mysqli_query($this->LinkID, $Query);
228
-      if (!in_array(mysqli_errno($this->LinkID), array(1213, 1205))) {
229
-        break;
228
+
229
+      // in DEBUG_MODE, return the full trace on a SQL error (super useful for debugging).
230
+      // do not attempt to retry to query
231
+      if (!$this->QueryID) {
232
+        echo '<pre>' . mysqli_error($this->LinkID) . '<br><br>';
233
+        debug_print_backtrace();
234
+        echo '</pre>';
235
+        die();
230 236
       }
231
-      $Debug->analysis('Non-Fatal Deadlock:', $Query, 3600 * 24);
232
-      trigger_error("Database deadlock, attempt $i");
237
+    } else {
238
+      // In the event of a MySQL deadlock, we sleep allowing MySQL time to unlock, then attempt again for a maximum of 5 tries
239
+      for ($i = 1; $i < 6; $i++) {
240
+        $this->QueryID = mysqli_query($this->LinkID, $Query);
241
+        if (!in_array(mysqli_errno($this->LinkID), array(1213, 1205))) {
242
+          break;
243
+        }
244
+        $Debug->analysis('Non-Fatal Deadlock:', $Query, 3600 * 24);
245
+        trigger_error("Database deadlock, attempt $i");
233 246
 
234
-      sleep($i * rand(2, 5)); // Wait longer as attempts increase
247
+        sleep($i * rand(2, 5)); // Wait longer as attempts increase
248
+      }
235 249
     }
250
+
236 251
     $QueryEndTime = microtime(true);
237 252
     $this->Queries[] = array($Query, ($QueryEndTime - $QueryStartTime) * 1000, null);
238 253
     $this->Time += ($QueryEndTime - $QueryStartTime) * 1000;

+ 2
- 2
classes/torrents.class.php View File

@@ -708,12 +708,12 @@ class Torrents {
708 708
       if ($Data['FreeLeechType'] == '3') {
709 709
         $QueryID = G::$DB->get_query_id();
710 710
         G::$DB->query("
711
-          SELECT GREATEST(NOW(), ExpiryTime)
711
+          SELECT UNIX_TIMESTAMP(ExpiryTime)
712 712
           FROM shop_freeleeches
713 713
           WHERE TorrentID = ".$Data['ID']);
714 714
         if (G::$DB->has_results()) {
715 715
           $ExpiryTime = G::$DB->next_record(MYSQLI_NUM, false)[0];
716
-          $Info[] = ($HTMLy ? Format::torrent_label('Freeleech!') : 'Freeleech!') . ($HTMLy ? " <strong>(" : " (") . str_replace(['week','day','hour','min','Just now','s',' '],['w','d','h','m','0m'],time_diff($ExpiryTime, 1, false)) . ($HTMLy ? ")</strong>" : ")");
716
+          $Info[] = ($HTMLy ? Format::torrent_label('Freeleech!') : 'Freeleech!') . ($HTMLy ? " <strong>(" : " (") . str_replace(['week','day','hour','min','Just now','s',' '],['w','d','h','m','0m'],time_diff(max($ExpiryTime, time()), 1, false)) . ($HTMLy ? ")</strong>" : ")");
717 717
         } else {
718 718
           $Info[] = $HTMLy ? Format::torrent_label('Freeleech!') : 'Freeleech!';
719 719
         }

+ 10
- 1
classes/tracker.class.php View File

@@ -23,6 +23,11 @@ class Tracker {
23 23
     }
24 24
 
25 25
     $MaxAttempts = 3;
26
+    // don't wait around if we're debugging
27
+    if (DEBUG_MODE) {
28
+      $MaxAttempts = 1;
29
+    }
30
+
26 31
     $Err = false;
27 32
     if (self::send_request($Get, $MaxAttempts, $Err) === false) {
28 33
       send_irc("PRIVMSG #tracker :$MaxAttempts $Err $Get");
@@ -130,7 +135,11 @@ class Tracker {
130 135
       if ($Sleep) {
131 136
         sleep($Sleep);
132 137
       }
133
-      $Sleep = 6;
138
+
139
+      // spend some time retrying if we're not in DEBUG_MODE
140
+      if (!DEBUG_MODE) {
141
+        $Sleep = 6;
142
+      }
134 143
 
135 144
       // Send request
136 145
       $File = fsockopen(TRACKER_HOST, TRACKER_PORT, $ErrorNum, $ErrorString);

+ 1
- 0
sections/artist/artist.php View File

@@ -301,6 +301,7 @@ foreach ($TorrentList as $Group) {
301 301
     }
302 302
   } else {
303 303
     list($TorrentID, $Torrent) = each($Torrents);
304
+    if (!$TorrentID) { continue; }
304 305
 
305 306
     $TorrentTags = new Tags($TagList, false);
306 307
 

+ 3
- 0
sections/better/index.php View File

@@ -5,6 +5,9 @@ if (isset($_GET['method'])) {
5 5
     case 'screenshots':
6 6
       include(SERVER_ROOT.'/sections/better/screenshots.php');
7 7
       break;
8
+    case 'covers':
9
+      include(SERVER_ROOT.'/sections/better/covers.php');
10
+      break;
8 11
     case 'encode':
9 12
       include(SERVER_ROOT.'/sections/better/encode.php');
10 13
       break;

+ 13
- 0
sections/reportsv2/takereport.php View File

@@ -132,6 +132,19 @@ $DB->query("
132 132
 
133 133
 $ReportID = $DB->inserted_id();
134 134
 
135
+$DB->query("
136
+  SELECT UserID
137
+  FROM torrents
138
+  WHERE ID = $TorrentID");
139
+list($UploaderID) = $DB->next_record();
140
+$DB->query("
141
+  SELECT Name, NameRJ, NameJP
142
+  FROM torrents_group
143
+  WHERE ID = $GroupID");
144
+list($GroupNameEng, $GroupNameRJ, $GroupNameJP) = $DB->next_record();
145
+$GroupName = $GroupNameEng ? $GroupNameEng : ($GroupNameRJ ? $GroupNameRJ : $GroupNameJP);
146
+
147
+Misc::send_pm($UploaderID, 0, "Torrent Reported: $GroupName", "Your torrent, \"[url=".site_url()."torrents.php?torrentid=$TorrentID]".$GroupName."[/url]\", was reported for the reason \"".$ReportType['title']."\".\n\nThe reporter also said: \"$Extra\"\n\nIf you think this report was in error, please contact staff. Failure to challenge some types of reports in a timely manner will be regarded as a lack of defense and may result in the torrent being deleted.");
135 148
 
136 149
 $Cache->delete_value("reports_torrent_$TorrentID");
137 150
 

+ 1
- 1
sections/requests/take_unfill.php View File

@@ -18,7 +18,7 @@ $DB->query("
18 18
     u.Uploaded,
19 19
     u.BonusPoints,
20 20
     r.GroupID,
21
-    t.UserID,
21
+    t.UserID
22 22
   FROM requests AS r
23 23
     LEFT JOIN torrents AS t ON t.ID = TorrentID
24 24
     LEFT JOIN users_main AS u ON u.ID = FillerID

+ 32
- 26
sections/tools/data/user_flow.php View File

@@ -5,44 +5,31 @@ if (!check_perms('site_view_flow')) {
5 5
 
6 6
 //Timeline generation
7 7
 if (!isset($_GET['page'])) {
8
-  if (!list($Labels, $InFlow, $OutFlow, $Max) = $Cache->get_value('users_timeline')) {
8
+  if (!list($Labels, $InFlow, $OutFlow) = $Cache->get_value('users_timeline')) {
9 9
     $DB->query("
10
-      SELECT DATE_FORMAT(JoinDate, '%b \'%y') AS Month, COUNT(UserID)
10
+      SELECT DATE_FORMAT(JoinDate, \"%b %y\") AS Month, COUNT(UserID)
11 11
       FROM users_info
12 12
       GROUP BY Month
13 13
       ORDER BY JoinDate DESC
14
-      LIMIT 1, 12");
14
+      LIMIT 1, 11");
15 15
     $TimelineIn = array_reverse($DB->to_array());
16 16
     $DB->query("
17
-      SELECT DATE_FORMAT(BanDate, '%b \'%y') AS Month, COUNT(UserID)
17
+      SELECT DATE_FORMAT(BanDate, \"%b %y\") AS Month, COUNT(UserID)
18 18
       FROM users_info
19 19
       WHERE BanDate > 0
20 20
       GROUP BY Month
21 21
       ORDER BY BanDate DESC
22
-      LIMIT 1, 12");
22
+      LIMIT 1, 11");
23 23
     $TimelineOut = array_reverse($DB->to_array());
24
+
25
+    $Labels = array();
24 26
     foreach ($TimelineIn as $Month) {
25
-      list($Label, $Amount) = $Month;
26
-      if ($Amount > $Max) {
27
-        $Max = $Amount;
28
-      }
29
-    }
30
-    foreach ($TimelineOut as $Month) {
31
-      list($Label, $Amount) = $Month;
32
-      if ($Amount > $Max) {
33
-        $Max = $Amount;
34
-      }
35
-    }
36
-    foreach ($TimelineIn as $Month) {
37
-      list($Label, $Amount) = $Month;
38
-      $Labels[] = $Label;
39
-      $InFlow[] = number_format(($Amount / $Max) * 100, 4);
27
+      list($Labels[], $InFlow[]) = $Month;
40 28
     }
41 29
     foreach ($TimelineOut as $Month) {
42
-      list($Label, $Amount) = $Month;
43
-      $OutFlow[] = number_format(($Amount / $Max) * 100, 4);
30
+      list(, $OutFlow[]) = $Month;
44 31
     }
45
-    $Cache->cache_value('users_timeline', array($Labels, $InFlow, $OutFlow, $Max), mktime(0, 0, 0, date('n') + 1, 2));
32
+    $Cache->cache_value('users_timeline', array($Labels, $InFlow, $OutFlow), mktime(0, 0, 0, date('n') + 1, 2));
46 33
   }
47 34
 }
48 35
 //End timeline generation
@@ -112,13 +99,32 @@ $RS = $DB->query("
112 99
 $DB->query('SELECT FOUND_ROWS()');
113 100
 list($Results) = $DB->next_record();
114 101
 
115
-View::show_header('User Flow');
102
+View::show_header('User Flow', 'chart');
116 103
 $DB->set_query_id($RS);
117 104
 ?>
118 105
 <div class="thin">
119 106
 <?  if (!isset($_GET['page'])) { ?>
120
-  <div class="box pad">
121
-    <img src="https://chart.googleapis.com/chart?cht=lc&amp;chs=820x160&amp;chco=000D99,99000D&amp;chg=0,-1,1,1&amp;chxt=y,x&amp;chxs=0,h&amp;chxl=1:|<?=implode('|', $Labels)?>&amp;chxr=0,0,<?=$Max?>&amp;chd=t:<?=implode(',', $InFlow)?>|<?=implode(',', $OutFlow)?>&amp;chls=2,4,0&amp;chdl=New+Registrations|Disabled+Users&amp;chf=bg,s,FFFFFF00" alt="User Flow vs. Time" />
107
+  <div class="box pad center">
108
+    <canvas class="chart" id="chart_user_timeline"></canvas>
109
+    <script>
110
+      new Chart($('#chart_user_timeline').raw().getContext('2d'), {
111
+        type: 'line',
112
+        data: {
113
+          labels: <? print '["'.implode('","',$Labels).'"]'; ?>,
114
+          datasets: [ {
115
+            label: "New Registrations",
116
+            backgroundColor: "rgba(0,0,255,0.2)",
117
+            borderColor: "rgba(0,0,255,0.8)",
118
+            data: <? print "[".implode(",",$InFlow)."]"; ?>
119
+          }, {
120
+            label: "Disabled Users",
121
+            backgroundColor: "rgba(255,0,0,0.2)",
122
+            borderColor: "rgba(255,0,0,0.8)",
123
+            data: <? print "[".implode(",",$OutFlow)."]"; ?>
124
+          }]
125
+        }
126
+      })
127
+    </script>
122 128
   </div>
123 129
 <?  } ?>
124 130
   <div class="linkbox">

+ 4
- 4
sections/torrents/details.php View File

@@ -515,12 +515,12 @@ foreach ($TorrentList as $Torrent) {
515 515
   // Freleechizer
516 516
   if ($FreeLeechType == '3') {
517 517
     $DB->query("
518
-      SELECT GREATEST(NOW(), ExpiryTime)
518
+      SELECT UNIX_TIMESTAMP(ExpiryTime)
519 519
       FROM shop_freeleeches
520 520
       WHERE TorrentID = $TorrentID");
521 521
     if ($DB->has_results()) {
522 522
       $ExpiryTime = $DB->next_record(MYSQLI_NUM, false)[0];
523
-      $ExtraInfo .= " <strong>(" . str_replace(['week','day','hour','min','Just now','s',' '],['w','d','h','m','0m'],time_diff($ExpiryTime, 1, false)) . ")</strong>";
523
+      $ExtraInfo .= " <strong>(" . str_replace(['week','day','hour','min','Just now','s',' '],['w','d','h','m','0m'],time_diff(max($ExpiryTime, time()), 1, false)) . ")</strong>";
524 524
     }
525 525
   }
526 526
   if ($PersonalFL) { $ExtraInfo.=$AddExtra. Format::torrent_label('Personal Freeleech!'); $AddExtra=' / '; }
@@ -698,7 +698,7 @@ if (count($Collages) > 0) {
698 698
 ?>
699 699
     <table class="box collage_table" id="collages">
700 700
       <tr class="colhead">
701
-        <td width="85%"><a href="#">&uarr;</a>&nbsp;This album is in <?=number_format(count($Collages))?> collage<?=((count($Collages) > 1) ? 's' : '')?><?=$SeeAll?></td>
701
+        <td width="85%"><a href="#">&uarr;</a>&nbsp;This content is in <?=number_format(count($Collages))?> collection<?=((count($Collages) > 1) ? 's' : '')?><?=$SeeAll?></td>
702 702
         <td># torrents</td>
703 703
       </tr>
704 704
 <?  foreach ($Indices as $i) {
@@ -749,7 +749,7 @@ if (count($PersonalCollages) > 0) {
749 749
 ?>
750 750
     <table class="box collage_table" id="personal_collages">
751 751
       <tr class="colhead">
752
-        <td width="85%"><a href="#">&uarr;</a>&nbsp;This album is in <?=number_format(count($PersonalCollages))?> personal collage<?=((count($PersonalCollages) > 1) ? 's' : '')?><?=$SeeAll?></td>
752
+        <td width="85%"><a href="#">&uarr;</a>&nbsp;This content is in <?=number_format(count($PersonalCollages))?> personal collection<?=((count($PersonalCollages) > 1) ? 's' : '')?><?=$SeeAll?></td>
753 753
         <td># torrents</td>
754 754
       </tr>
755 755
 <?  foreach ($Indices as $i) {

+ 9
- 1
static/styles/global.css View File

@@ -11,6 +11,10 @@
11 11
   font-size: 110%;
12 12
 }
13 13
 
14
+.thin {
15
+  box-sizing: border-box;
16
+}
17
+
14 18
 .flex_input_container {
15 19
   display: flex;
16 20
 }
@@ -55,7 +59,11 @@ h2 .group_cat {
55 59
   background-size: 16px 16px;
56 60
 }
57 61
 
58
-pre br {
62
+code {
63
+  white-space: pre;
64
+}
65
+
66
+pre > br, code > br {
59 67
   line-height: 0px;
60 68
   display: none;
61 69
 }

Loading…
Cancel
Save