Browse Source

Upload files to 'classes'

Stortebeker 6 years ago
parent
commit
aa58288c55
5 changed files with 416 additions and 380 deletions
  1. 91
    86
      classes/calendar.class.php
  2. 78
    77
      classes/calendarview.class.php
  3. 188
    162
      classes/charts.class.php
  4. 27
    27
      classes/classloader.php
  5. 32
    28
      classes/collages.class.php

+ 91
- 86
classes/calendar.class.php View File

1
-<?
2
-class Calendar {
3
-  public static $Categories = array(1 => "IRC Meeting", "IRC Brainstorm", "Poll Deadline", "Feature Release", "Blog Post", "Announcement", "Featured Album", "Product Release", "Staff Picks", "Forum Brainstorm", "Forum Discussion", "Promotion", "Absence", "Task");
4
-  public static $Importances = array(1 => "Critical", "Important", "Average", "Meh");
5
-  public static $Colors = array(
1
+<?php
2
+class Calendar
3
+{
4
+    public static $Categories = array(1 => "IRC Meeting", "IRC Brainstorm", "Poll Deadline", "Feature Release", "Blog Post", "Announcement", "Featured Album", "Product Release", "Staff Picks", "Forum Brainstorm", "Forum Discussion", "Promotion", "Absence", "Task");
5
+    public static $Importances = array(1 => "Critical", "Important", "Average", "Meh");
6
+    public static $Colors = array(
6
                   "Critical" => "red",
7
                   "Critical" => "red",
7
                   "Important" => "yellow",
8
                   "Important" => "yellow",
8
                   "Average" => "green",
9
                   "Average" => "green",
9
                   "Meh" => "blue");
10
                   "Meh" => "blue");
10
 
11
 
11
-  public static $Teams = array(
12
+    public static $Teams = array(
12
                   0 => "Everyone",
13
                   0 => "Everyone",
13
                   1 => "Staff"
14
                   1 => "Staff"
14
 
15
 
15
                   );
16
                   );
16
 
17
 
17
-  public static function can_view() {
18
-    return check_perms('users_mod')
19
-
20
-      ;
21
-  }
22
-
23
-  private static function get_teams_query() {
24
-    $Teams = array(0);
25
-    $IsMod = check_perms("users_mod");
26
-    if ($IsMod) {
27
-      $Teams[] = 1;
18
+    public static function can_view()
19
+    {
20
+        return check_perms('users_mod');
28
     }
21
     }
29
 
22
 
30
-    return "Team IN (" . implode(",", $Teams) . ") ";
31
-  }
23
+    private static function get_teams_query()
24
+    {
25
+        $Teams = array(0);
26
+        $IsMod = check_perms("users_mod");
27
+        if ($IsMod) {
28
+            $Teams[] = 1;
29
+        }
32
 
30
 
33
-  public static function get_events($Month, $Year) {
34
-    if (empty($Month) || empty($Year)) {
35
-      $Date = getdate();
36
-      $Month = $Date['mon'];
37
-      $Year = $Date['year'];
31
+        return "Team IN (" . implode(",", $Teams) . ") ";
38
     }
32
     }
39
-    $Month = (int)$Month;
40
-    $Year = (int)$Year;
41
 
33
 
42
-    $TeamsSQL = self::get_teams_query();
34
+    public static function get_events($Month, $Year)
35
+    {
36
+        if (empty($Month) || empty($Year)) {
37
+            $Date = getdate();
38
+            $Month = $Date['mon'];
39
+            $Year = $Date['year'];
40
+        }
41
+        $Month = (int)$Month;
42
+        $Year = (int)$Year;
43
+
44
+        $TeamsSQL = self::get_teams_query();
43
 
45
 
44
-    $QueryID = G::$DB->get_query_id();
45
-    G::$DB->query("
46
+        $QueryID = G::$DB->get_query_id();
47
+        G::$DB->query("
46
             SELECT
48
             SELECT
47
               ID, Team, Title, Category, Importance, DAY(StartDate) AS StartDay, DAY(EndDate) AS EndDay
49
               ID, Team, Title, Category, Importance, DAY(StartDate) AS StartDay, DAY(EndDate) AS EndDay
48
             FROM calendar
50
             FROM calendar
52
               YEAR(StartDate) = '$Year'
54
               YEAR(StartDate) = '$Year'
53
             AND
55
             AND
54
               $TeamsSQL");
56
               $TeamsSQL");
55
-    $Events = G::$DB->to_array();
56
-    G::$DB->set_query_id($QueryID);
57
-    return $Events;
58
-  }
59
-
60
-  public static function get_event($ID) {
61
-    $ID = (int)$ID;
62
-    if (empty($ID)) {
63
-      error("Invalid ID");
57
+        $Events = G::$DB->to_array();
58
+        G::$DB->set_query_id($QueryID);
59
+        return $Events;
64
     }
60
     }
65
-    $TeamsSQL = self::get_teams_query();
66
-    $QueryID = G::$DB->get_query_id();
67
-    G::$DB->query("
61
+
62
+    public static function get_event($ID)
63
+    {
64
+        $ID = (int)$ID;
65
+        if (empty($ID)) {
66
+            error("Invalid ID");
67
+        }
68
+        $TeamsSQL = self::get_teams_query();
69
+        $QueryID = G::$DB->get_query_id();
70
+        G::$DB->query("
68
             SELECT
71
             SELECT
69
               ID, Team, Title, Body, Category, Importance, AddedBy, StartDate, EndDate
72
               ID, Team, Title, Body, Category, Importance, AddedBy, StartDate, EndDate
70
             FROM calendar
73
             FROM calendar
72
               ID = '$ID'
75
               ID = '$ID'
73
             AND
76
             AND
74
               $TeamsSQL");
77
               $TeamsSQL");
75
-    $Event = G::$DB->next_record(MYSQLI_ASSOC);
76
-    G::$DB->set_query_id($QueryID);
77
-    return $Event;
78
-  }
79
-
80
-  public static function create_event($Title, $Body, $Category, $Importance, $Team, $UserID, $StartDate, $EndDate = null) {
81
-    if (empty($Title) || empty($Body) || !is_number($Category) || !is_number($Importance)  || !is_number($Team) || empty($StartDate)) {
82
-      error("Error adding event");
78
+        $Event = G::$DB->next_record(MYSQLI_ASSOC);
79
+        G::$DB->set_query_id($QueryID);
80
+        return $Event;
83
     }
81
     }
84
-    $Title = db_string($Title);
85
-    $Body = db_string($Body);
86
-    $Category = (int)$Category;
87
-    $Importance = (int)$Importance;
88
-    $UserID = (int)$UserID;
89
-    $Team = (int)$Team;
90
-    $StartDate = db_string($StartDate);
91
-    $EndDate = db_string($EndDate);
92
 
82
 
93
-    $QueryID = G::$DB->get_query_id();
94
-    G::$DB->query("
83
+    public static function create_event($Title, $Body, $Category, $Importance, $Team, $UserID, $StartDate, $EndDate = null)
84
+    {
85
+        if (empty($Title) || empty($Body) || !is_number($Category) || !is_number($Importance)  || !is_number($Team) || empty($StartDate)) {
86
+            error("Error adding event");
87
+        }
88
+        $Title = db_string($Title);
89
+        $Body = db_string($Body);
90
+        $Category = (int)$Category;
91
+        $Importance = (int)$Importance;
92
+        $UserID = (int)$UserID;
93
+        $Team = (int)$Team;
94
+        $StartDate = db_string($StartDate);
95
+        $EndDate = db_string($EndDate);
96
+
97
+        $QueryID = G::$DB->get_query_id();
98
+        G::$DB->query("
95
             INSERT INTO calendar
99
             INSERT INTO calendar
96
               (Title, Body, Category, Importance, Team, StartDate, EndDate, AddedBy)
100
               (Title, Body, Category, Importance, Team, StartDate, EndDate, AddedBy)
97
             VALUES
101
             VALUES
98
               ('$Title', '$Body', '$Category', '$Importance', '$Team', '$StartDate', '$EndDate', '$UserID')");
102
               ('$Title', '$Body', '$Category', '$Importance', '$Team', '$StartDate', '$EndDate', '$UserID')");
99
-    G::$DB->set_query_id($QueryID);
100
-    send_irc("PRIVMSG " . ADMIN_CHAN . " :!mod New calendar event created! Event: $Title; Starts: $StartDate; Ends: $EndDate.");
101
-  }
102
-
103
-  public static function update_event($ID, $Title, $Body, $Category, $Importance, $Team, $StartDate, $EndDate = null) {
104
-    if (!is_number($ID) || empty($Title) || empty($Body) || !is_number($Category) || !is_number($Importance) || !is_number($Team) || empty($StartDate)) {
105
-      error("Error updating event");
103
+        G::$DB->set_query_id($QueryID);
104
+        send_irc("PRIVMSG " . ADMIN_CHAN . " :!mod New calendar event created! Event: $Title; Starts: $StartDate; Ends: $EndDate.");
106
     }
105
     }
107
-    $ID = (int)$ID;
108
-    $Title = db_string($Title);
109
-    $Body = db_string($Body);
110
-    $Category = (int)$Category;
111
-    $Importance = (int)$Importance;
112
-    $Team = (int)$Team;
113
-    $StartDate = db_string($StartDate);
114
-    $EndDate = db_string($EndDate);
115
-    $QueryID = G::$DB->get_query_id();
116
-    G::$DB->query("
106
+
107
+    public static function update_event($ID, $Title, $Body, $Category, $Importance, $Team, $StartDate, $EndDate = null)
108
+    {
109
+        if (!is_number($ID) || empty($Title) || empty($Body) || !is_number($Category) || !is_number($Importance) || !is_number($Team) || empty($StartDate)) {
110
+            error("Error updating event");
111
+        }
112
+        $ID = (int)$ID;
113
+        $Title = db_string($Title);
114
+        $Body = db_string($Body);
115
+        $Category = (int)$Category;
116
+        $Importance = (int)$Importance;
117
+        $Team = (int)$Team;
118
+        $StartDate = db_string($StartDate);
119
+        $EndDate = db_string($EndDate);
120
+        $QueryID = G::$DB->get_query_id();
121
+        G::$DB->query("
117
             UPDATE calendar
122
             UPDATE calendar
118
             SET
123
             SET
119
               Title = '$Title',
124
               Title = '$Title',
125
               EndDate = '$EndDate'
130
               EndDate = '$EndDate'
126
             WHERE
131
             WHERE
127
               ID = '$ID'");
132
               ID = '$ID'");
128
-    G::$DB->set_query_id($QueryID);
129
-  }
130
-
131
-  public static function remove_event($ID) {
132
-    $ID = (int)$ID;
133
-    if (!empty($ID)) {
134
-      $QueryID = G::$DB->get_query_id();
135
-      G::$DB->query("DELETE FROM calendar WHERE ID = '$ID'");
136
-      G::$DB->set_query_id($QueryID);
133
+        G::$DB->set_query_id($QueryID);
137
     }
134
     }
138
-  }
139
 
135
 
136
+    public static function remove_event($ID)
137
+    {
138
+        $ID = (int)$ID;
139
+        if (!empty($ID)) {
140
+            $QueryID = G::$DB->get_query_id();
141
+            G::$DB->query("DELETE FROM calendar WHERE ID = '$ID'");
142
+            G::$DB->set_query_id($QueryID);
143
+        }
144
+    }
140
 }
145
 }

+ 78
- 77
classes/calendarview.class.php View File

1
-<?
1
+<?php
2
 
2
 
3
-class CalendarView {
4
-  private static $Days = array('S', 'M', 'T', 'W', 'T', 'F', 'S');
5
-  private static $Headings = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
6
-  private static $Events;
3
+class CalendarView
4
+{
5
+    private static $Days = array('S', 'M', 'T', 'W', 'T', 'F', 'S');
6
+    private static $Headings = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
7
+    private static $Events;
7
 
8
 
8
-  public static function render_title($Month, $Year) {
9
-    if (!is_numeric($Month) || !is_numeric($Year)) {
10
-      error(404);
11
-    }
12
-    $NextMonth = $Month % 12 == 0 ? 1 : $Month + 1;
13
-    $PreviousMonth = $Month == 1 ? 12 : $Month - 1;
14
-    $NextYear = $Year;
15
-    if ($NextMonth == 1) {
16
-      $NextYear++;
17
-    }
18
-    $PreviousYear = $Year;
19
-    if ($PreviousMonth == 12) {
20
-      $PreviousYear--;
21
-    }
22
-?>
9
+    public static function render_title($Month, $Year)
10
+    {
11
+        if (!is_numeric($Month) || !is_numeric($Year)) {
12
+            error(404);
13
+        }
14
+        $NextMonth = $Month % 12 == 0 ? 1 : $Month + 1;
15
+        $PreviousMonth = $Month == 1 ? 12 : $Month - 1;
16
+        $NextYear = $Year;
17
+        if ($NextMonth == 1) {
18
+            $NextYear++;
19
+        }
20
+        $PreviousYear = $Year;
21
+        if ($PreviousMonth == 12) {
22
+            $PreviousYear--;
23
+        } ?>
23
     <h1 class="center">
24
     <h1 class="center">
24
       <a href="tools.php?action=calendar&amp;month=<?=$PreviousMonth?>&amp;year=<?=$PreviousYear?>">&lt;</a>
25
       <a href="tools.php?action=calendar&amp;month=<?=$PreviousMonth?>&amp;year=<?=$PreviousYear?>">&lt;</a>
25
-      <?=date("F", mktime(0, 0, 0, $Month, 10)) . " $Year"?>
26
+        <?=date("F", mktime(0, 0, 0, $Month, 10)) . " $Year"?>
26
       <a href="tools.php?action=calendar&amp;month=<?=$NextMonth?>&amp;year=<?=$NextYear?>">&gt;</a>
27
       <a href="tools.php?action=calendar&amp;month=<?=$NextMonth?>&amp;year=<?=$NextYear?>">&gt;</a>
27
     </h1>
28
     </h1>
28
     <input type="hidden" id="month" value="<?=$Month?>" />
29
     <input type="hidden" id="month" value="<?=$Month?>" />
29
     <input type="hidden" id="year" value="<?=$Year?>" />
30
     <input type="hidden" id="year" value="<?=$Year?>" />
30
-<?
31
-  }
31
+        <?php
32
+    }
32
 
33
 
33
-  private static function get_events_on($Day, $Events) {
34
-    // Linear search, Lol.
35
-    $Results = [];
36
-    foreach ($Events as $Event) {
37
-      if ($Event['StartDay'] == $Day || ($Event['StartDay'] <= $Day && $Event['EndDay'] >= $Day)) {
38
-        $Results[] = $Event;
39
-      }
34
+    private static function get_events_on($Day, $Events)
35
+    {
36
+        // Linear search, Lol.
37
+        $Results = [];
38
+        foreach ($Events as $Event) {
39
+            if ($Event['StartDay'] == $Day || ($Event['StartDay'] <= $Day && $Event['EndDay'] >= $Day)) {
40
+                $Results[] = $Event;
41
+            }
42
+        }
43
+        return $Results;
40
     }
44
     }
41
-    return $Results;
42
-  }
43
 
45
 
44
 
46
 
45
-  private static function render_events_day($Day, $Events) {
46
-    $Events = self::get_events_on($Day, $Events);
47
-    foreach ($Events as $Event) {
48
-      $Color = Calendar::$Colors[Calendar::$Importances[$Event['Importance']]];
49
-      $Category = Calendar::$Categories[$Event['Category']];
50
-      $Tooltip = $Event['Title'] . " - " . Calendar::$Categories[$Event['Category']] . " - " . Calendar::$Importances[$Event['Importance']];
51
-?>
47
+    private static function render_events_day($Day, $Events)
48
+    {
49
+        $Events = self::get_events_on($Day, $Events);
50
+        foreach ($Events as $Event) {
51
+            $Color = Calendar::$Colors[Calendar::$Importances[$Event['Importance']]];
52
+            $Category = Calendar::$Categories[$Event['Category']];
53
+            $Tooltip = $Event['Title'] . " - " . Calendar::$Categories[$Event['Category']] . " - " . Calendar::$Importances[$Event['Importance']]; ?>
52
       <p><a href="#" class="event_day tooltip" title="<?=$Tooltip?>" data-gazelle-id="<?=$Event['ID']?>" style="color: <?=$Color?>;"><?=Format::cut_string($Event['Title'], 8, true)?></a></p>
54
       <p><a href="#" class="event_day tooltip" title="<?=$Tooltip?>" data-gazelle-id="<?=$Event['ID']?>" style="color: <?=$Color?>;"><?=Format::cut_string($Event['Title'], 8, true)?></a></p>
53
-<?
55
+            <?php
56
+        }
54
     }
57
     }
55
-  }
56
 
58
 
57
-  public static function render_calendar($Month, $Year, $Events) {
58
-    $RunningDay = date('w', mktime(0, 0, 0, $Month, 1, $Year));
59
-    $DaysInMonth = date('t', mktime(0 ,0 ,0, $Month, 1, $Year));
60
-    $DaysThisWeek = 1;
61
-    $DayCounter = 0;
62
-    $DatesArray = [];
63
-?>
59
+    public static function render_calendar($Month, $Year, $Events)
60
+    {
61
+        $RunningDay = date('w', mktime(0, 0, 0, $Month, 1, $Year));
62
+        $DaysInMonth = date('t', mktime(0, 0, 0, $Month, 1, $Year));
63
+        $DaysThisWeek = 1;
64
+        $DayCounter = 0;
65
+        $DatesArray = []; ?>
64
 
66
 
65
     <table class="calendar">
67
     <table class="calendar">
66
       <tr>
68
       <tr>
67
-<?    foreach (self::$Headings as $Heading) { ?>
69
+        <?php    foreach (self::$Headings as $Heading) { ?>
68
         <td class="calendar-row calendar-heading">
70
         <td class="calendar-row calendar-heading">
69
           <strong><?=$Heading?></strong>
71
           <strong><?=$Heading?></strong>
70
         </td>
72
         </td>
71
-<?    } ?>
73
+        <?php    } ?>
72
       </tr>
74
       </tr>
73
       <tr class="calendar-row">
75
       <tr class="calendar-row">
74
 
76
 
75
-<?    for ($x = 0; $x < $RunningDay; $x++) { ?>
77
+        <?php    for ($x = 0; $x < $RunningDay; $x++) { ?>
76
         <td class="calendar-day-np"></td>
78
         <td class="calendar-day-np"></td>
77
-<?
78
-      $DaysThisWeek++;
79
-    }
79
+            <?php
80
+              $DaysThisWeek++;
81
+        }
80
 
82
 
81
-    for ($i = 1; $i <= $DaysInMonth; $i++) {
82
-?>
83
+        for ($i = 1; $i <= $DaysInMonth; $i++) {
84
+            ?>
83
         <td class="calendar-day">
85
         <td class="calendar-day">
84
           <div class="day-events">
86
           <div class="day-events">
85
-<?            self::render_events_day($i, $Events); ?>
87
+            <?php            self::render_events_day($i, $Events); ?>
86
           </div>
88
           </div>
87
           <div class="day-number">
89
           <div class="day-number">
88
             <?=$i?>
90
             <?=$i?>
89
           </div>
91
           </div>
90
         </td>
92
         </td>
91
-<?      if ($RunningDay == 6) { ?>
93
+            <?php      if ($RunningDay == 6) { ?>
92
       </tr>
94
       </tr>
93
-<?        if (($DayCounter + 1) != $DaysInMonth) { ?>
95
+                <?php        if (($DayCounter + 1) != $DaysInMonth) { ?>
94
       <tr class="calendar-row">
96
       <tr class="calendar-row">
95
-<?
97
+                    <?php
98
+                }
99
+                    $RunningDay = -1;
100
+                    $DaysThisWeek = 0;
101
+            }
102
+            $DaysThisWeek++;
103
+            $RunningDay++;
104
+            $DayCounter++;
96
         }
105
         }
97
-        $RunningDay = -1;
98
-        $DaysThisWeek = 0;
99
-      }
100
-      $DaysThisWeek++;
101
-      $RunningDay++;
102
-      $DayCounter++;
103
-    }
104
 
106
 
105
-    if ($DaysThisWeek < 8) {
106
-      for ($x = 1; $x <= (8 - $DaysThisWeek); $x++) {
107
-?>
107
+        if ($DaysThisWeek < 8) {
108
+            for ($x = 1; $x <= (8 - $DaysThisWeek); $x++) {
109
+                ?>
108
         <td class="calendar-day-np"></td>
110
         <td class="calendar-day-np"></td>
109
-<?
110
-      }
111
-    }
112
-?>
111
+                <?php
112
+            }
113
+        } ?>
113
       </tr>
114
       </tr>
114
 
115
 
115
     </table>
116
     </table>
116
-<?
117
-    echo $Calendar;
118
-  }
117
+        <?php
118
+        echo $Calendar;
119
+    }
119
 }
120
 }

+ 188
- 162
classes/charts.class.php View File

1
-<?
2
-class GOOGLE_CHARTS {
3
-  protected $URL = 'https://chart.googleapis.com/chart';
4
-  protected $Labels = [];
5
-  protected $Data = [];
6
-  protected $Options = [];
7
-
8
-  public function __construct($Type, $Width, $Height, $Options) {
9
-    if ($Width * $Height > 300000 || $Height > 1000 || $Width > 1000) {
10
-      trigger_error('Tried to make chart too large.');
1
+<?php
2
+class GOOGLE_CHARTS
3
+{
4
+    protected $URL = 'https://chart.googleapis.com/chart';
5
+    protected $Labels = [];
6
+    protected $Data = [];
7
+    protected $Options = [];
8
+
9
+    public function __construct($Type, $Width, $Height, $Options)
10
+    {
11
+        if ($Width * $Height > 300000 || $Height > 1000 || $Width > 1000) {
12
+            trigger_error('Tried to make chart too large.');
13
+        }
14
+        $this->URL .= "?cht=$Type&amp;chs={$Width}x$Height";
15
+        $this->Options = $Options;
11
     }
16
     }
12
-    $this->URL .= "?cht=$Type&amp;chs={$Width}x$Height";
13
-    $this->Options = $Options;
14
-  }
15
 
17
 
16
-  protected function encode($Number) {
17
-    if ($Number == -1) {
18
-      return '__';
18
+    protected function encode($Number)
19
+    {
20
+        if ($Number == -1) {
21
+            return '__';
22
+        }
23
+        $CharKey = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.';
24
+        return $CharKey[floor($Number / 64)].$CharKey[floor($Number % 64)];
19
     }
25
     }
20
-    $CharKey = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.';
21
-    return $CharKey[floor($Number / 64)].$CharKey[floor($Number % 64)];
22
-  }
23
-
24
-  public function color($Colors) {
25
-    $this->URL .= '&amp;chco='.$Colors;
26
-  }
27
 
26
 
28
-  public function lines($Thickness, $Solid = 1, $Blank = 0) {
29
-    $this->URL .= "&amp;chls=$Thickness,$Solid,$Blank";
30
-  }
27
+    public function color($Colors)
28
+    {
29
+        $this->URL .= '&amp;chco='.$Colors;
30
+    }
31
 
31
 
32
-  public function title($Title, $Color = '', $Size = '') {
33
-    $this->URL .= '&amp;chtt='.str_replace(array(' ', "\n"), array('+', '|'), $Title);
34
-    if (!empty($Color)) {
35
-      $this->URL .= '&amp;chts='.$Color;
32
+    public function lines($Thickness, $Solid = 1, $Blank = 0)
33
+    {
34
+        $this->URL .= "&amp;chls=$Thickness,$Solid,$Blank";
36
     }
35
     }
37
-    if (!empty($Size)) {
38
-      $this->URL .= ','.$Size;
36
+
37
+    public function title($Title, $Color = '', $Size = '')
38
+    {
39
+        $this->URL .= '&amp;chtt='.str_replace(array(' ', "\n"), array('+', '|'), $Title);
40
+        if (!empty($Color)) {
41
+            $this->URL .= '&amp;chts='.$Color;
42
+        }
43
+        if (!empty($Size)) {
44
+            $this->URL .= ','.$Size;
45
+        }
39
     }
46
     }
40
-  }
41
 
47
 
42
-  public function legend($Items, $Placement = '') {
43
-    $this->URL .= '&amp;chdl='.str_replace(' ', '+', implode('|', $Items));
44
-    if (!empty($Placement)) {
45
-      if (!in_array($Placement, array('b', 't', 'r', 'l', 'bv', 'tv'))) {
46
-        trigger_error('Invalid legend placement.');
47
-      }
48
-      $this->URL .= '&amp;chdlp='.$Placement;
48
+    public function legend($Items, $Placement = '')
49
+    {
50
+        $this->URL .= '&amp;chdl='.str_replace(' ', '+', implode('|', $Items));
51
+        if (!empty($Placement)) {
52
+            if (!in_array($Placement, array('b', 't', 'r', 'l', 'bv', 'tv'))) {
53
+                trigger_error('Invalid legend placement.');
54
+            }
55
+            $this->URL .= '&amp;chdlp='.$Placement;
56
+        }
49
     }
57
     }
50
-  }
51
 
58
 
52
-  public function add($Label, $Data) {
53
-    if ($Label !== false) {
54
-      $this->Labels[] = $Label;
59
+    public function add($Label, $Data)
60
+    {
61
+        if ($Label !== false) {
62
+            $this->Labels[] = $Label;
63
+        }
64
+        $this->Data[] = $Data;
55
     }
65
     }
56
-    $this->Data[] = $Data;
57
-  }
58
 
66
 
59
-  public function grid_lines($SpacingX = 0, $SpacingY = -1, $Solid = 1, $Blank = 1) {
60
-    //Can take 2 more parameters for offset, but we're not bothering with that right now
61
-    $this->URL .= "&amp;chg=$SpacingX,$SpacingY,$Solid,$Blank";
62
-  }
67
+    public function grid_lines($SpacingX = 0, $SpacingY = -1, $Solid = 1, $Blank = 1)
68
+    {
69
+        //Can take 2 more parameters for offset, but we're not bothering with that right now
70
+        $this->URL .= "&amp;chg=$SpacingX,$SpacingY,$Solid,$Blank";
71
+    }
63
 
72
 
64
-  public function transparent() {
65
-    $this->URL .= '&amp;chf=bg,s,FFFFFF00';
66
-  }
73
+    public function transparent()
74
+    {
75
+        $this->URL .= '&amp;chf=bg,s,FFFFFF00';
76
+    }
67
 
77
 
68
 
78
 
69
-  public function url() {
70
-    return $this->URL;
71
-  }
79
+    public function url()
80
+    {
81
+        return $this->URL;
82
+    }
72
 }
83
 }
73
 
84
 
74
-class AREA_GRAPH extends GOOGLE_CHARTS {
75
-  public function __construct ($Width, $Height, $Options = []) {
76
-    parent::__construct('lc', $Width, $Height, $Options);
77
-  }
85
+class AREA_GRAPH extends GOOGLE_CHARTS
86
+{
87
+    public function __construct($Width, $Height, $Options = [])
88
+    {
89
+        parent::__construct('lc', $Width, $Height, $Options);
90
+    }
78
 
91
 
79
-  public function color ($Color) {
80
-    $this->URL .= '&amp;chco='.$Color.'&amp;chm=B,'.$Color.'50,0,0,0';
81
-  }
92
+    public function color($Color)
93
+    {
94
+        $this->URL .= '&amp;chco='.$Color.'&amp;chm=B,'.$Color.'50,0,0,0';
95
+    }
82
 
96
 
83
-  public function generate() {
84
-    $Max = max($this->Data);
85
-    $Min = ((isset($this->Options['Break'])) ? $Min = min($this->Data) : 0);
86
-    $Data = [];
87
-    foreach ($this->Data as $Value) {
88
-      $Data[] = $this->encode((($Value - $Min) / ($Max - $Min)) * 4095);
97
+    public function generate()
98
+    {
99
+        $Max = max($this->Data);
100
+        $Min = ((isset($this->Options['Break'])) ? $Min = min($this->Data) : 0);
101
+        $Data = [];
102
+        foreach ($this->Data as $Value) {
103
+            $Data[] = $this->encode((($Value - $Min) / ($Max - $Min)) * 4095);
104
+        }
105
+        $this->URL .= "&amp;chxt=y,x&amp;chxs=0,h&amp;chxl=1:|".implode('|', $this->Labels).'&amp;chxr=0,'.$Min.','.($Max - $Min).'&amp;chd=e:'.implode('', $Data);
89
     }
106
     }
90
-    $this->URL .= "&amp;chxt=y,x&amp;chxs=0,h&amp;chxl=1:|".implode('|', $this->Labels).'&amp;chxr=0,'.$Min.','.($Max - $Min).'&amp;chd=e:'.implode('', $Data);
91
-  }
92
 }
107
 }
93
 
108
 
94
-class PIE_CHART extends GOOGLE_CHARTS {
95
-  public function __construct ($Width, $Height, $Options = []) {
96
-    $Type = ((isset($this->Options['3D'])) ? 'p3' : 'p');
97
-    parent::__construct($Type, $Width, $Height, $Options);
98
-  }
99
-
100
-  public function generate() {
101
-    $Sum = array_sum($this->Data);
102
-    $Other = isset($this->Options['Other']);
103
-    $Sort = isset($this->Options['Sort']);
104
-    $LabelPercent = isset($this->Options['Percentage']);
105
-
106
-    if ($Sort && !empty($this->Labels)) {
107
-      array_multisort($this->Data, SORT_DESC, $this->Labels);
108
-    } elseif ($Sort) {
109
-      sort($this->Data);
110
-      $this->Data = array_reverse($this->Data);
111
-    }
112
-
113
-    $Data = [];
114
-    $Labels = $this->Labels;
115
-    $OtherPercentage = 0.00;
116
-    $OtherData = 0;
117
-
118
-    foreach ($this->Data as $Key => $Value) {
119
-      $ThisPercentage = number_format(($Value / $Sum) * 100, 2);
120
-      $ThisData = ($Value / $Sum) * 4095;
121
-      if ($Other && $ThisPercentage < 1) {
122
-        $OtherPercentage += $ThisPercentage;
123
-        $OtherData += $ThisData;
124
-        unset($Data[$Key]);
125
-        unset($Labels[$Key]);
126
-        continue;
127
-      }
128
-      if ($LabelPercent) {
129
-        $Labels[$Key] .= ' ('.$ThisPercentage.'%)';
130
-      }
131
-      $Data[] = $this->encode($ThisData);
132
-    }
133
-    if ($OtherPercentage > 0) {
134
-      $OtherLabel = 'Other';
135
-      if ($LabelPercent) {
136
-        $OtherLabel .= ' ('.$OtherPercentage.'%)';
137
-      }
138
-      $Labels[] = $OtherLabel;
139
-      $Data[] = $this->encode($OtherData);
140
-    }
141
-    $this->URL .= "&amp;chl=".implode('|', $Labels).'&amp;chd=e:'.implode('', $Data);
142
-  }
109
+class PIE_CHART extends GOOGLE_CHARTS
110
+{
111
+    public function __construct($Width, $Height, $Options = [])
112
+    {
113
+        $Type = ((isset($this->Options['3D'])) ? 'p3' : 'p');
114
+        parent::__construct($Type, $Width, $Height, $Options);
115
+    }
116
+
117
+    public function generate()
118
+    {
119
+        $Sum = array_sum($this->Data);
120
+        $Other = isset($this->Options['Other']);
121
+        $Sort = isset($this->Options['Sort']);
122
+        $LabelPercent = isset($this->Options['Percentage']);
123
+
124
+        if ($Sort && !empty($this->Labels)) {
125
+            array_multisort($this->Data, SORT_DESC, $this->Labels);
126
+        } elseif ($Sort) {
127
+            sort($this->Data);
128
+            $this->Data = array_reverse($this->Data);
129
+        }
130
+
131
+        $Data = [];
132
+        $Labels = $this->Labels;
133
+        $OtherPercentage = 0.00;
134
+        $OtherData = 0;
135
+
136
+        foreach ($this->Data as $Key => $Value) {
137
+            $ThisPercentage = number_format(($Value / $Sum) * 100, 2);
138
+            $ThisData = ($Value / $Sum) * 4095;
139
+            if ($Other && $ThisPercentage < 1) {
140
+                $OtherPercentage += $ThisPercentage;
141
+                $OtherData += $ThisData;
142
+                unset($Data[$Key]);
143
+                unset($Labels[$Key]);
144
+                continue;
145
+            }
146
+            if ($LabelPercent) {
147
+                $Labels[$Key] .= ' ('.$ThisPercentage.'%)';
148
+            }
149
+            $Data[] = $this->encode($ThisData);
150
+        }
151
+        if ($OtherPercentage > 0) {
152
+            $OtherLabel = 'Other';
153
+            if ($LabelPercent) {
154
+                $OtherLabel .= ' ('.$OtherPercentage.'%)';
155
+            }
156
+            $Labels[] = $OtherLabel;
157
+            $Data[] = $this->encode($OtherData);
158
+        }
159
+        $this->URL .= "&amp;chl=".implode('|', $Labels).'&amp;chd=e:'.implode('', $Data);
160
+    }
143
 }
161
 }
144
 
162
 
145
 
163
 
146
-class LOG_BAR_GRAPH extends GOOGLE_CHARTS {
147
-  //TODO: Finish.
148
-  public function __construct ($Base, $Width, $Height, $Options = []) {
149
-    parent::__construct('lc', $Width, $Height, $Options);
150
-  }
164
+class LOG_BAR_GRAPH extends GOOGLE_CHARTS
165
+{
166
+    //TODO: Finish.
167
+    public function __construct($Base, $Width, $Height, $Options = [])
168
+    {
169
+        parent::__construct('lc', $Width, $Height, $Options);
170
+    }
151
 
171
 
152
-  public function color ($Color) {
153
-    $this->URL .= '&amp;chco='.$Color.'&amp;chm=B,'.$Color.'50,0,0,0';
154
-  }
172
+    public function color($Color)
173
+    {
174
+        $this->URL .= '&amp;chco='.$Color.'&amp;chm=B,'.$Color.'50,0,0,0';
175
+    }
155
 
176
 
156
-  public function generate() {
157
-    $Max = max($this->Data);
158
-    $Min = ((isset($this->Options['Break'])) ? $Min = min($this->Data) : 0);
159
-    $Data = [];
160
-    foreach ($this->Data as $Value) {
161
-      $Data[] = $this->encode((($Value - $Min) / ($Max - $Min)) * 4095);
177
+    public function generate()
178
+    {
179
+        $Max = max($this->Data);
180
+        $Min = ((isset($this->Options['Break'])) ? $Min = min($this->Data) : 0);
181
+        $Data = [];
182
+        foreach ($this->Data as $Value) {
183
+            $Data[] = $this->encode((($Value - $Min) / ($Max - $Min)) * 4095);
184
+        }
185
+        $this->URL .= "&amp;chxt=y,x&amp;chxs=0,h&amp;chxl=1:|".implode('|', $this->Labels).'&amp;chxr=0,'.$Min.','.($Max-$Min).'&amp;chd=e:'.implode('', $Data);
162
     }
186
     }
163
-    $this->URL .= "&amp;chxt=y,x&amp;chxs=0,h&amp;chxl=1:|".implode('|', $this->Labels).'&amp;chxr=0,'.$Min.','.($Max-$Min).'&amp;chd=e:'.implode('', $Data);
164
-  }
165
 }
187
 }
166
 
188
 
167
-class POLL_GRAPH extends GOOGLE_CHARTS {
168
-  public function __construct () {
169
-    $this->URL .= '?cht=bhg';
170
-  }
171
-
172
-  public function add($Label, $Data) {
173
-    if ($Label !== false) {
174
-      $this->Labels[] = Format::cut_string($Label, 35);
175
-    }
176
-    $this->Data[] = $Data;
177
-  }
178
-
179
-  public function generate() {
180
-    $Count = count($this->Data);
181
-    $Height = (30 * $Count) + 20;
182
-    $Max = max($this->Data);
183
-    $Sum = array_sum($this->Data);
184
-    $Increment = ($Max / $Sum) * 25; // * 100% / 4divisions
185
-    $Data = [];
186
-    $Labels = [];
187
-    foreach ($this->Data as $Key => $Value) {
188
-      $Data[] = $this->encode(($Value / $Max) * 4095);
189
-      $Labels[] = '@t'.str_replace(array(' ', ','),array('+', '\,'), $this->Labels[$Key]).',000000,1,'.round((($Key + 1) / $Count) - (12 / $Height), 2).':0,12';
190
-    }
191
-    $this->URL .= "&amp;chbh=25,0,5&amp;chs=214x$Height&amp;chl=0%|".round($Increment, 1)."%|".round($Increment * 2, 1)."%|".round($Increment * 3, 1)."%|".round($Increment * 4, 1)."%&amp;chm=".implode('|', $Labels).'&amp;chd=e:'.implode('', $Data);
192
-  }
189
+class POLL_GRAPH extends GOOGLE_CHARTS
190
+{
191
+    public function __construct()
192
+    {
193
+        $this->URL .= '?cht=bhg';
194
+    }
195
+
196
+    public function add($Label, $Data)
197
+    {
198
+        if ($Label !== false) {
199
+            $this->Labels[] = Format::cut_string($Label, 35);
200
+        }
201
+        $this->Data[] = $Data;
202
+    }
203
+
204
+    public function generate()
205
+    {
206
+        $Count = count($this->Data);
207
+        $Height = (30 * $Count) + 20;
208
+        $Max = max($this->Data);
209
+        $Sum = array_sum($this->Data);
210
+        $Increment = ($Max / $Sum) * 25; // * 100% / 4divisions
211
+        $Data = [];
212
+        $Labels = [];
213
+        foreach ($this->Data as $Key => $Value) {
214
+            $Data[] = $this->encode(($Value / $Max) * 4095);
215
+            $Labels[] = '@t'.str_replace(array(' ', ','), array('+', '\,'), $this->Labels[$Key]).',000000,1,'.round((($Key + 1) / $Count) - (12 / $Height), 2).':0,12';
216
+        }
217
+        $this->URL .= "&amp;chbh=25,0,5&amp;chs=214x$Height&amp;chl=0%|".round($Increment, 1)."%|".round($Increment * 2, 1)."%|".round($Increment * 3, 1)."%|".round($Increment * 4, 1)."%&amp;chm=".implode('|', $Labels).'&amp;chd=e:'.implode('', $Data);
218
+    }
193
 }
219
 }

+ 27
- 27
classes/classloader.php View File

1
-<?
1
+<?php
2
 /**
2
 /**
3
  * Load classes automatically when they're needed
3
  * Load classes automatically when they're needed
4
  *
4
  *
5
  * @param string $ClassName class name
5
  * @param string $ClassName class name
6
  */
6
  */
7
 spl_autoload_register(function ($ClassName) {
7
 spl_autoload_register(function ($ClassName) {
8
-  $FilePath = SERVER_ROOT . '/classes/' . strtolower($ClassName) . '.class.php';
9
-  if (!file_exists($FilePath)) {
10
-    // TODO: Rename the following classes to conform with the code guidelines
11
-    switch ($ClassName) {
12
-      case 'MASS_USER_BOOKMARKS_EDITOR':
13
-        $FileName = 'mass_user_bookmarks_editor.class';
14
-        break;
15
-      case 'MASS_USER_TORRENTS_EDITOR':
16
-        $FileName = 'mass_user_torrents_editor.class';
17
-        break;
18
-      case 'MASS_USER_TORRENTS_TABLE_VIEW':
19
-        $FileName = 'mass_user_torrents_table_view.class';
20
-          break;
21
-      case 'TEXTAREA_PREVIEW':
22
-        $FileName = 'textarea_preview.class';
23
-        break;
24
-      case 'TORRENT':
25
-      case 'BENCODE_DICT':
26
-      case 'BENCODE_LIST':
27
-        $FileName = 'torrent.class';
28
-        break;
29
-      default:
30
-        die("Couldn't import class $ClassName");
8
+    $FilePath = SERVER_ROOT . '/classes/' . strtolower($ClassName) . '.class.php';
9
+    if (!file_exists($FilePath)) {
10
+        // TODO: Rename the following classes to conform with the code guidelines
11
+        switch ($ClassName) {
12
+            case 'MASS_USER_BOOKMARKS_EDITOR':
13
+                $FileName = 'mass_user_bookmarks_editor.class';
14
+                break;
15
+            case 'MASS_USER_TORRENTS_EDITOR':
16
+                $FileName = 'mass_user_torrents_editor.class';
17
+                break;
18
+            case 'MASS_USER_TORRENTS_TABLE_VIEW':
19
+                $FileName = 'mass_user_torrents_table_view.class';
20
+                break;
21
+            case 'TEXTAREA_PREVIEW':
22
+                $FileName = 'textarea_preview.class';
23
+                break;
24
+            case 'TORRENT':
25
+            case 'BENCODE_DICT':
26
+            case 'BENCODE_LIST':
27
+                $FileName = 'torrent.class';
28
+                break;
29
+            default:
30
+                die("Couldn't import class $ClassName");
31
+        }
32
+        $FilePath = SERVER_ROOT . "/classes/$FileName.php";
31
     }
33
     }
32
-    $FilePath = SERVER_ROOT . "/classes/$FileName.php";
33
-  }
34
-  require_once($FilePath);
34
+    require_once($FilePath);
35
 });
35
 });

+ 32
- 28
classes/collages.class.php View File

1
-<?
2
-class Collages {
3
-  public static function increase_subscriptions($CollageID) {
4
-    $QueryID = G::$DB->get_query_id();
5
-    G::$DB->query("
1
+<?php
2
+class Collages
3
+{
4
+    public static function increase_subscriptions($CollageID)
5
+    {
6
+        $QueryID = G::$DB->get_query_id();
7
+        G::$DB->query("
6
       UPDATE collages
8
       UPDATE collages
7
       SET Subscribers = Subscribers + 1
9
       SET Subscribers = Subscribers + 1
8
       WHERE ID = '$CollageID'");
10
       WHERE ID = '$CollageID'");
9
-    G::$DB->set_query_id($QueryID);
10
-  }
11
+        G::$DB->set_query_id($QueryID);
12
+    }
11
 
13
 
12
-  public static function decrease_subscriptions($CollageID) {
13
-    $QueryID = G::$DB->get_query_id();
14
-    G::$DB->query("
14
+    public static function decrease_subscriptions($CollageID)
15
+    {
16
+        $QueryID = G::$DB->get_query_id();
17
+        G::$DB->query("
15
       UPDATE collages
18
       UPDATE collages
16
       SET Subscribers = IF(Subscribers < 1, 0, Subscribers - 1)
19
       SET Subscribers = IF(Subscribers < 1, 0, Subscribers - 1)
17
       WHERE ID = '$CollageID'");
20
       WHERE ID = '$CollageID'");
18
-    G::$DB->set_query_id($QueryID);
19
-  }
21
+        G::$DB->set_query_id($QueryID);
22
+    }
20
 
23
 
21
-  public static function create_personal_collage() {
22
-    G::$DB->query("
24
+    public static function create_personal_collage()
25
+    {
26
+        G::$DB->query("
23
       SELECT
27
       SELECT
24
         COUNT(ID)
28
         COUNT(ID)
25
       FROM collages
29
       FROM collages
26
       WHERE UserID = '" . G::$LoggedUser['ID'] . "'
30
       WHERE UserID = '" . G::$LoggedUser['ID'] . "'
27
         AND CategoryID = '0'
31
         AND CategoryID = '0'
28
         AND Deleted = '0'");
32
         AND Deleted = '0'");
29
-    list($CollageCount) = G::$DB->next_record();
33
+        list($CollageCount) = G::$DB->next_record();
30
 
34
 
31
-    if ($CollageCount >= G::$LoggedUser['Permissions']['MaxCollages']) {
32
-      // TODO: fix this, the query was for COUNT(ID), so I highly doubt that this works... - Y
33
-      list($CollageID) = G::$DB->next_record();
34
-      header('Location: collage.php?id='.$CollageID);
35
-      die();
36
-    }
37
-    $NameStr = db_string(G::$LoggedUser['Username'] . "'s personal collage" . ($CollageCount > 0 ? ' no. ' . ($CollageCount + 1) : ''));
38
-    $Description = db_string('Personal collage for ' . G::$LoggedUser['Username'] . '. The first 5 albums will appear on his or her [url=' . site_url() . 'user.php?id= ' . G::$LoggedUser['ID'] . ']profile[/url].');
39
-    G::$DB->query("
35
+        if ($CollageCount >= G::$LoggedUser['Permissions']['MaxCollages']) {
36
+            // TODO: fix this, the query was for COUNT(ID), so I highly doubt that this works... - Y
37
+            list($CollageID) = G::$DB->next_record();
38
+            header('Location: collage.php?id='.$CollageID);
39
+            die();
40
+        }
41
+        $NameStr = db_string(G::$LoggedUser['Username'] . "'s personal collage" . ($CollageCount > 0 ? ' no. ' . ($CollageCount + 1) : ''));
42
+        $Description = db_string('Personal collage for ' . G::$LoggedUser['Username'] . '. The first 5 albums will appear on his or her [url=' . site_url() . 'user.php?id= ' . G::$LoggedUser['ID'] . ']profile[/url].');
43
+        G::$DB->query("
40
       INSERT INTO collages
44
       INSERT INTO collages
41
         (Name, Description, CategoryID, UserID)
45
         (Name, Description, CategoryID, UserID)
42
       VALUES
46
       VALUES
43
         ('$NameStr', '$Description', '0', " . G::$LoggedUser['ID'] . ")");
47
         ('$NameStr', '$Description', '0', " . G::$LoggedUser['ID'] . ")");
44
-    $CollageID = G::$DB->inserted_id();
45
-    header('Location: collage.php?id='.$CollageID);
46
-    die();
47
-  }
48
+        $CollageID = G::$DB->inserted_id();
49
+        header('Location: collage.php?id='.$CollageID);
50
+        die();
51
+    }
48
 }
52
 }

Loading…
Cancel
Save