Browse Source

Upload files to 'classes'

Stortebeker 6 years ago
parent
commit
81c37da0ca
5 changed files with 1423 additions and 1342 deletions
  1. 486
    463
      classes/debug.class.php
  2. 636
    599
      classes/donations.class.php
  3. 161
    153
      classes/donationsbitcoin.class.php
  4. 70
    65
      classes/donationsview.class.php
  5. 70
    62
      classes/feed.class.php

+ 486
- 463
classes/debug.class.php
File diff suppressed because it is too large
View File


+ 636
- 599
classes/donations.class.php
File diff suppressed because it is too large
View File


+ 161
- 153
classes/donationsbitcoin.class.php View File

@@ -1,186 +1,194 @@
1
-<?
2
-class DonationsBitcoin {
3
-  /**
4
-   * Ask bitcoind for a list of all addresses that have received bitcoins
5
-   *
6
-   * @return array (BitcoinAddress => Amount, ...)
7
-   */
8
-  public static function get_received() {
9
-    if (defined('BITCOIN_RPC_URL')) {
10
-      $Donations = BitcoinRpc::listreceivedbyaddress();
11
-    }
12
-    if (empty($Donations)) {
13
-      return [];
14
-    }
15
-    $BTCUsers = [];
16
-    foreach ($Donations as $Account) {
17
-      $BTCUsers[$Account->address] = $Account->amount;
1
+<?php
2
+class DonationsBitcoin
3
+{
4
+    /**
5
+     * Ask bitcoind for a list of all addresses that have received bitcoins
6
+     *
7
+     * @return array (BitcoinAddress => Amount, ...)
8
+     */
9
+    public static function get_received()
10
+    {
11
+        if (defined('BITCOIN_RPC_URL')) {
12
+            $Donations = BitcoinRpc::listreceivedbyaddress();
13
+        }
14
+        if (empty($Donations)) {
15
+            return [];
16
+        }
17
+        $BTCUsers = [];
18
+        foreach ($Donations as $Account) {
19
+            $BTCUsers[$Account->address] = $Account->amount;
20
+        }
21
+        return $BTCUsers;
18 22
     }
19
-    return $BTCUsers;
20
-  }
21 23
 
22
-  /**
23
-   * Ask bitcoind for the current account balance
24
-   *
25
-   * @return float balance
26
-   */
27
-  public static function get_balance() {
28
-    if (defined('BITCOIN_RPC_URL')) {
29
-      return BitcoinRpc::getbalance();
24
+    /**
25
+     * Ask bitcoind for the current account balance
26
+     *
27
+     * @return float balance
28
+     */
29
+    public static function get_balance()
30
+    {
31
+        if (defined('BITCOIN_RPC_URL')) {
32
+            return BitcoinRpc::getbalance();
33
+        }
30 34
     }
31
-  }
32 35
 
33
-  /**
34
-   * Get a user's existing bitcoin address or generate a new one
35
-   *
36
-   * @param int $UserID
37
-   * @param bool $GenAddress whether to create a new address if it doesn't exist
38
-   * @return false if no address exists and $GenAddress is false
39
-   *         string bitcoin address otherwise
40
-   */
41
-  public static function get_address($UserID, $GenAddress = false) {
42
-    $UserID = (int)$UserID;
43
-    $QueryID = G::$DB->get_query_id();
44
-    G::$DB->query("
36
+    /**
37
+     * Get a user's existing bitcoin address or generate a new one
38
+     *
39
+     * @param int $UserID
40
+     * @param bool $GenAddress whether to create a new address if it doesn't exist
41
+     * @return false if no address exists and $GenAddress is false
42
+     *         string bitcoin address otherwise
43
+     */
44
+    public static function get_address($UserID, $GenAddress = false)
45
+    {
46
+        $UserID = (int)$UserID;
47
+        $QueryID = G::$DB->get_query_id();
48
+        G::$DB->query("
45 49
       SELECT BitcoinAddress
46 50
       FROM users_info
47 51
       WHERE UserID = '$UserID'");
48
-    list($Addr) = G::$DB->next_record();
49
-    G::$DB->set_query_id($QueryID);
52
+        list($Addr) = G::$DB->next_record();
53
+        G::$DB->set_query_id($QueryID);
50 54
 
51
-    if (!empty($Addr)) {
52
-      return $Addr;
53
-    } elseif ($GenAddress) {
54
-      if (defined('BITCOIN_RPC_URL')) {
55
-        $NewAddr = BitcoinRpc::getnewaddress();
56
-      }
57
-      if (empty($NewAddr)) {
58
-        error(0);
59
-      }
60
-      $QueryID = G::$DB->get_query_id();
61
-      G::$DB->query("
55
+        if (!empty($Addr)) {
56
+            return $Addr;
57
+        } elseif ($GenAddress) {
58
+            if (defined('BITCOIN_RPC_URL')) {
59
+                $NewAddr = BitcoinRpc::getnewaddress();
60
+            }
61
+            if (empty($NewAddr)) {
62
+                error(0);
63
+            }
64
+            $QueryID = G::$DB->get_query_id();
65
+            G::$DB->query("
62 66
         UPDATE users_info
63 67
         SET BitcoinAddress = '".db_string($NewAddr)."'
64 68
         WHERE UserID = '$UserID'
65 69
           AND BitcoinAddress IS NULL");
66
-      G::$DB->set_query_id($QueryID);
67
-      return $NewAddr;
68
-    } else {
69
-      return false;
70
+            G::$DB->set_query_id($QueryID);
71
+            return $NewAddr;
72
+        } else {
73
+            return false;
74
+        }
70 75
     }
71
-  }
72 76
 
73
-  /**
74
-   * Ask bitcoind for the total amount of bitcoins received
75
-   *
76
-   * @return float amount
77
-   */
78
-  public static function get_total_received() {
79
-    if (defined('BITCOIN_RPC_URL')) {
80
-      $Accounts = BitcoinRpc::listreceivedbyaccount();
81
-    }
82
-    if (empty($Accounts)) {
83
-      return 0.0;
84
-    }
85
-    foreach ($Accounts as $Account) {
86
-      if ($Account->account == '') {
87
-        return $Account->amount;
88
-      }
77
+    /**
78
+     * Ask bitcoind for the total amount of bitcoins received
79
+     *
80
+     * @return float amount
81
+     */
82
+    public static function get_total_received()
83
+    {
84
+        if (defined('BITCOIN_RPC_URL')) {
85
+            $Accounts = BitcoinRpc::listreceivedbyaccount();
86
+        }
87
+        if (empty($Accounts)) {
88
+            return 0.0;
89
+        }
90
+        foreach ($Accounts as $Account) {
91
+            if ($Account->account == '') {
92
+                return $Account->amount;
93
+            }
94
+        }
95
+        return 0.0;
89 96
     }
90
-    return 0.0;
91
-  }
92 97
 
93
-  /**
94
-   * Translate bitcoin addresses to user IDs
95
-   *
96
-   * @param array $Addresses list of bitcoin addresses
97
-   * @return array (BitcoinAddress => UserID, ...)
98
-   */
99
-  public static function get_userids($Addresses) {
100
-    if (!is_array($Addresses) || empty($Addresses)) {
101
-      return false;
102
-    }
103
-    $QueryID = G::$DB->get_query_id();
104
-    G::$DB->query("
98
+    /**
99
+     * Translate bitcoin addresses to user IDs
100
+     *
101
+     * @param array $Addresses list of bitcoin addresses
102
+     * @return array (BitcoinAddress => UserID, ...)
103
+     */
104
+    public static function get_userids($Addresses)
105
+    {
106
+        if (!is_array($Addresses) || empty($Addresses)) {
107
+            return false;
108
+        }
109
+        $QueryID = G::$DB->get_query_id();
110
+        G::$DB->query("
105 111
       SELECT BitcoinAddress, UserID
106 112
       FROM users_info
107 113
       WHERE BitcoinAddress IN ('" . implode("', '", $Addresses) . "')");
108
-    if (G::$DB->has_results()) {
109
-      $UserIDs = G::$DB->to_pair(0, 1);
110
-    } else {
111
-      $UserIDs = [];
114
+        if (G::$DB->has_results()) {
115
+            $UserIDs = G::$DB->to_pair(0, 1);
116
+        } else {
117
+            $UserIDs = [];
118
+        }
119
+        G::$DB->set_query_id($QueryID);
120
+        return $UserIDs;
112 121
     }
113
-    G::$DB->set_query_id($QueryID);
114
-    return $UserIDs;
115
-  }
116 122
 
117
-  /**
118
-   * Find and process new donations since the last time this function was called.
119
-   */
120
-  public static function find_new_donations() {
121
-    global $Debug;
122
-    if (($OldAmount = G::$Cache->get_value('btc_total_received')) === false) {
123
-      $QueryID = G::$DB->get_query_id();
124
-      G::$DB->query("
123
+    /**
124
+     * Find and process new donations since the last time this function was called.
125
+     */
126
+    public static function find_new_donations()
127
+    {
128
+        global $Debug;
129
+        if (($OldAmount = G::$Cache->get_value('btc_total_received')) === false) {
130
+            $QueryID = G::$DB->get_query_id();
131
+            G::$DB->query("
125 132
         SELECT IFNULL(SUM(Amount), 0)
126 133
         FROM donations_bitcoin");
127
-      list($OldAmount) = G::$DB->next_record(MYSQLI_NUM, false);
128
-      G::$DB->set_query_id($QueryID);
129
-    }
130
-    $NewAmount = self::get_total_received();
131
-    if ($NewAmount < $OldAmount) {
132
-      // This shouldn't happen. Perhaps bitcoind was restarted recently
133
-      // or the block index was removed. Either way, try again later
134
-      send_irc('PRIVMSG ' . LAB_CHAN . " :Bad bitcoin donation data (is $NewAmount, was $OldAmount). If this persists, something is probably wrong");
135
-      return false;
136
-    }
137
-    if ($NewAmount > $OldAmount) {
138
-      // I really wish we didn't have to do it like this
139
-      $QueryID = G::$DB->get_query_id();
140
-      G::$DB->query("
134
+            list($OldAmount) = G::$DB->next_record(MYSQLI_NUM, false);
135
+            G::$DB->set_query_id($QueryID);
136
+        }
137
+        $NewAmount = self::get_total_received();
138
+        if ($NewAmount < $OldAmount) {
139
+            // This shouldn't happen. Perhaps bitcoind was restarted recently
140
+            // or the block index was removed. Either way, try again later
141
+            send_irc('PRIVMSG ' . LAB_CHAN . " :Bad bitcoin donation data (is $NewAmount, was $OldAmount). If this persists, something is probably wrong");
142
+            return false;
143
+        }
144
+        if ($NewAmount > $OldAmount) {
145
+            // I really wish we didn't have to do it like this
146
+            $QueryID = G::$DB->get_query_id();
147
+            G::$DB->query("
141 148
         SELECT BitcoinAddress, SUM(Amount)
142 149
         FROM donations_bitcoin
143 150
         GROUP BY BitcoinAddress");
144
-      $OldDonations = G::$DB->to_pair(0, 1, false);
145
-      G::$DB->set_query_id($QueryID);
146
-      $NewDonations = self::get_received();
147
-      foreach ($NewDonations as $Address => &$Amount) {
148
-        if (isset($OldDonations[$Address])) {
149
-          if ($Amount == $OldDonations[$Address]) { // Direct comparison should be fine as everything comes from bitcoind
150
-            unset($NewDonations[$Address]);
151
-            continue;
152
-          }
153
-          $Debug->log_var(array('old' => $OldDonations[$Address], 'new' => $Amount), "New donations from $Address");
154
-          // PHP doesn't do fixed-point math, and json_decode has already botched the precision
155
-          // so let's just round this off to satoshis and pray that we're on a 64 bit system
156
-          $Amount = round($Amount - $OldDonations[$Address], 8);
151
+            $OldDonations = G::$DB->to_pair(0, 1, false);
152
+            G::$DB->set_query_id($QueryID);
153
+            $NewDonations = self::get_received();
154
+            foreach ($NewDonations as $Address => &$Amount) {
155
+                if (isset($OldDonations[$Address])) {
156
+                    if ($Amount == $OldDonations[$Address]) { // Direct comparison should be fine as everything comes from bitcoind
157
+                        unset($NewDonations[$Address]);
158
+                        continue;
159
+                    }
160
+                    $Debug->log_var(array('old' => $OldDonations[$Address], 'new' => $Amount), "New donations from $Address");
161
+                    // PHP doesn't do fixed-point math, and json_decode has already botched the precision
162
+                    // so let's just round this off to satoshis and pray that we're on a 64 bit system
163
+                    $Amount = round($Amount - $OldDonations[$Address], 8);
164
+                }
165
+                $NewDonations[$Address] = $Amount;
166
+            }
167
+            $Debug->log_var($NewDonations, '$NewDonations');
168
+            foreach (self::get_userids(array_keys($NewDonations)) as $Address => $UserID) {
169
+                Donations::regular_donate($UserID, $NewDonations[$Address], 'Bitcoin Parser', '', 'BTC');
170
+                self::store_donation($Address, $NewDonations[$Address]);
171
+            }
172
+            G::$Cache->cache_value('btc_total_received', $NewAmount, 0);
157 173
         }
158
-        $NewDonations[$Address] = $Amount;
159
-      }
160
-      $Debug->log_var($NewDonations, '$NewDonations');
161
-      foreach (self::get_userids(array_keys($NewDonations)) as $Address => $UserID) {
162
-        Donations::regular_donate($UserID, $NewDonations[$Address], 'Bitcoin Parser', '', 'BTC');
163
-        self::store_donation($Address, $NewDonations[$Address]);
164
-      }
165
-      G::$Cache->cache_value('btc_total_received', $NewAmount, 0);
166 174
     }
167
-  }
168 175
 
169
-  /**
170
-   * Record a donation in the database
171
-   *
172
-   * @param string $Address bitcoin address
173
-   * @param double $Amount amount of bitcoins transferred
174
-   */
175
-  public static function store_donation($Address, $Amount) {
176
-    if (!is_numeric($Amount) || $Amount <= 0) {
177
-      // Panic!
178
-      return false;
179
-    }
180
-    G::$DB->query("
176
+    /**
177
+     * Record a donation in the database
178
+     *
179
+     * @param string $Address bitcoin address
180
+     * @param double $Amount amount of bitcoins transferred
181
+     */
182
+    public static function store_donation($Address, $Amount)
183
+    {
184
+        if (!is_numeric($Amount) || $Amount <= 0) {
185
+            // Panic!
186
+            return false;
187
+        }
188
+        G::$DB->query("
181 189
       INSERT INTO donations_bitcoin
182 190
         (BitcoinAddress, Amount)
183 191
       VALUES
184 192
         ('$Address', $Amount)");
185
-  }
186
-}
193
+    }
194
+}

+ 70
- 65
classes/donationsview.class.php View File

@@ -1,8 +1,10 @@
1
-<?
1
+<?php
2 2
 
3
-class DonationsView {
4
-  public static function render_mod_donations($UserID) {
5
-?>
3
+class DonationsView
4
+{
5
+    public static function render_mod_donations($UserID)
6
+    {
7
+        ?>
6 8
     <table class="layout box" id="donation_box">
7 9
       <tr class="colhead">
8 10
         <td colspan="2">
@@ -55,24 +57,26 @@ class DonationsView {
55 57
         </td>
56 58
       </tr>
57 59
     </table>
58
-<?
59
-  }
60
+        <?php
61
+    }
60 62
 
61
-  public static function render_donor_stats($UserID) {
62
-    $OwnProfile = G::$LoggedUser['ID'] == $UserID;
63
-    if (check_perms("users_mod") || $OwnProfile || Donations::is_visible($UserID)) {
64
-?>
63
+    public static function render_donor_stats($UserID)
64
+    {
65
+        $OwnProfile = G::$LoggedUser['ID'] == $UserID;
66
+        if (check_perms("users_mod") || $OwnProfile || Donations::is_visible($UserID)) {
67
+            ?>
65 68
       <div class="box box_info box_userinfo_donor_stats">
66 69
         <div class="head colhead_dark">Donor Statistics</div>
67 70
         <ul class="stats nobullet">
68
-<?
69
-      if (Donations::is_donor($UserID)) {
70
-        if (check_perms('users_mod') || $OwnProfile) {
71
-?>
71
+            <?php
72
+            if (Donations::is_donor($UserID)) {
73
+                if (check_perms('users_mod') || $OwnProfile) {
74
+                    ?>
72 75
           <li>
73 76
             Total donor points: <?=Donations::get_total_rank($UserID)?>
74 77
           </li>
75
-<?        } ?>
78
+                    <?php
79
+                } ?>
76 80
           <li>
77 81
             Current donor rank: <?=self::render_rank(Donations::get_rank($UserID), Donations::get_special_rank($UserID), true)?>
78 82
           </li>
@@ -85,40 +89,42 @@ class DonationsView {
85 89
           <li>
86 90
             Rank expires: <?=(Donations::get_rank_expiration($UserID))?>
87 91
           </li>
88
-<?      } else { ?>
92
+                <?php
93
+            } else { ?>
89 94
           <li>
90 95
             This user hasn't donated.
91 96
           </li>
92
-<?      } ?>
97
+            <?php      } ?>
93 98
         </ul>
94 99
       </div>
95
-<?
100
+            <?php
101
+        }
96 102
     }
97
-  }
98 103
 
99
-  public static function render_profile_rewards($EnabledRewards, $ProfileRewards) {
100
-    for ($i = 1; $i <= 4; $i++) {
101
-      if ($EnabledRewards['HasProfileInfo' . $i] && $ProfileRewards['ProfileInfo' . $i]) {
102
-?>
104
+    public static function render_profile_rewards($EnabledRewards, $ProfileRewards)
105
+    {
106
+        for ($i = 1; $i <= 4; $i++) {
107
+            if ($EnabledRewards['HasProfileInfo' . $i] && $ProfileRewards['ProfileInfo' . $i]) {
108
+                ?>
103 109
       <div class="box">
104 110
         <div class="head">
105 111
           <span><?=!empty($ProfileRewards['ProfileInfoTitle' . $i]) ? display_str($ProfileRewards['ProfileInfoTitle' . $i]) : "Extra Profile " . ($i + 1)?></span>
106 112
           <span class="float_right"><a data-toggle-target="#profilediv_<?=$i?>" data-toggle-replace="Show" class="brackets">Hide</a></span>
107 113
         </div>
108 114
         <div class="pad profileinfo" id="profilediv_<?=$i?>">
109
-<?          echo Text::full_format($ProfileRewards['ProfileInfo' . $i]); ?>
115
+                <?php          echo Text::full_format($ProfileRewards['ProfileInfo' . $i]); ?>
110 116
         </div>
111 117
       </div>
112
-<?
113
-      }
118
+                <?php
119
+            }
120
+        }
114 121
     }
115
-  }
116 122
 
117
-  public static function render_donation_history($DonationHistory) {
118
-    if (empty($DonationHistory)) {
119
-      return;
120
-    }
121
-?>
123
+    public static function render_donation_history($DonationHistory)
124
+    {
125
+        if (empty($DonationHistory)) {
126
+            return;
127
+        } ?>
122 128
     <div class="box box2" id="donation_history_box">
123 129
       <div class="head">
124 130
         Donation History <a data-toggle-target="#donation_history" class="brackets" style="float_right">Toggle</a>
@@ -149,7 +155,7 @@ class DonationsView {
149 155
               <strong>Reason</strong>
150 156
             </td>
151 157
           </tr>
152
-<?    foreach ($DonationHistory as $Donation) { ?>
158
+        <?php    foreach ($DonationHistory as $Donation) { ?>
153 159
           <tr class="row">
154 160
             <td>
155 161
               <?=display_str($Donation['Source'])?> (<?=Users::format_username($Donation['AddedBy'])?>)
@@ -173,42 +179,41 @@ class DonationsView {
173 179
               <?=display_str($Donation['Reason'])?>
174 180
             </td>
175 181
           </tr>
176
-<?
177
-    }
178
-?>
182
+            <?php
183
+        } ?>
179 184
           </tbody>
180 185
         </table>
181 186
       </div>
182 187
     </div>
183
-<?
184
-  }
185
-
186
-  public static function render_rank($Rank, $SpecialRank, $ShowOverflow = false) {
187
-    if ($SpecialRank == 3) {
188
-      $Display = '∞ [Diamond]';
189
-    } else {
190
-      $CurrentRank = $Rank >= MAX_RANK ? MAX_RANK : $Rank;
191
-      $Overflow = $Rank - $CurrentRank;
192
-      $Display = $CurrentRank;
193
-      if ($Display == 5 || $Display == 6) {
194
-        $Display--;
195
-      }
196
-      if ($ShowOverflow && $Overflow) {
197
-        $Display .= " (+$Overflow)";
198
-      }
199
-      if ($Rank >= 6) {
200
-        $Display .= ' [Gold]';
201
-      } elseif ($Rank >= 4) {
202
-        $Display .= ' [Silver]';
203
-      } elseif ($Rank >= 3) {
204
-        $Display .= ' [Bronze]';
205
-      } elseif ($Rank >= 2) {
206
-        $Display .= ' [Copper]';
207
-      } elseif ($Rank >= 1) {
208
-        $Display .= ' [Red]';
209
-      }
188
+        <?php
210 189
     }
211
-    echo $Display;
212
-  }
213 190
 
191
+    public static function render_rank($Rank, $SpecialRank, $ShowOverflow = false)
192
+    {
193
+        if ($SpecialRank == 3) {
194
+            $Display = '∞ [Diamond]';
195
+        } else {
196
+            $CurrentRank = $Rank >= MAX_RANK ? MAX_RANK : $Rank;
197
+            $Overflow = $Rank - $CurrentRank;
198
+            $Display = $CurrentRank;
199
+            if ($Display == 5 || $Display == 6) {
200
+                $Display--;
201
+            }
202
+            if ($ShowOverflow && $Overflow) {
203
+                $Display .= " (+$Overflow)";
204
+            }
205
+            if ($Rank >= 6) {
206
+                $Display .= ' [Gold]';
207
+            } elseif ($Rank >= 4) {
208
+                $Display .= ' [Silver]';
209
+            } elseif ($Rank >= 3) {
210
+                $Display .= ' [Bronze]';
211
+            } elseif ($Rank >= 2) {
212
+                $Display .= ' [Copper]';
213
+            } elseif ($Rank >= 1) {
214
+                $Display .= ' [Red]';
215
+            }
216
+        }
217
+        echo $Display;
218
+    }
214 219
 }

+ 70
- 62
classes/feed.class.php View File

@@ -1,71 +1,79 @@
1
-<?
2
-class FEED {
3
-  function open_feed() {
4
-    header("Content-type: application/xml; charset=UTF-8");
5
-    echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n","<rss xmlns:dc=\"http://purl.org/dc/elements/1.1/\" version=\"2.0\">\n\t<channel>\n";
6
-  }
7
-
8
-  function close_feed() {
9
-    echo "\t</channel>\n</rss>";
10
-  }
11
-
12
-  function channel($Title, $Description, $Section = '') {
13
-    $Site = site_url();
14
-    echo "\t\t<title>$Title :: ". SITE_NAME. "</title>\n";
15
-    echo "\t\t<link>$Site$Section</link>\n";
16
-    echo "\t\t<description>$Description</description>\n";
17
-    echo "\t\t<language>en-us</language>\n";
18
-    echo "\t\t<lastBuildDate>". date('r'). "</lastBuildDate>\n";
19
-    echo "\t\t<docs>http://blogs.law.harvard.edu/tech/rss</docs>\n";
20
-    echo "\t\t<generator>Gazelle Feed Class</generator>\n\n";
21
-  }
1
+<?php
2
+class FEED
3
+{
4
+    public function open_feed()
5
+    {
6
+        header("Content-type: application/xml; charset=UTF-8");
7
+        echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n","<rss xmlns:dc=\"http://purl.org/dc/elements/1.1/\" version=\"2.0\">\n\t<channel>\n";
8
+    }
22 9
 
23
-  function item($Title, $Description, $Page, $Creator, $Comments = '', $Category = '', $Date = '') { //Escape with CDATA, otherwise the feed breaks.
24
-    if ($Date == '') {
25
-      $Date = date('r');
26
-    } else {
27
-      $Date = date('r', strtotime($Date));
10
+    public function close_feed()
11
+    {
12
+        echo "\t</channel>\n</rss>";
28 13
     }
29
-    $Site = site_url();
30
-    $Item = "\t\t<item>\n";
31
-    $Item .= "\t\t\t<title><![CDATA[$Title]]></title>\n";
32
-    $Item .= "\t\t\t<description><![CDATA[$Description]]></description>\n";
33
-    $Item .= "\t\t\t<pubDate>$Date</pubDate>\n";
34
-    $Item .= "\t\t\t<link>$Site$Page</link>\n";
35
-    $Item .= "\t\t\t<guid>$Site$Page</guid>\n";
36
-    if ($Comments != '') {
37
-      $Item .= "\t\t\t<comments>$Site$Comments</comments>\n";
14
+
15
+    public function channel($Title, $Description, $Section = '')
16
+    {
17
+        $Site = site_url();
18
+        echo "\t\t<title>$Title :: ". SITE_NAME. "</title>\n";
19
+        echo "\t\t<link>$Site$Section</link>\n";
20
+        echo "\t\t<description>$Description</description>\n";
21
+        echo "\t\t<language>en-us</language>\n";
22
+        echo "\t\t<lastBuildDate>". date('r'). "</lastBuildDate>\n";
23
+        echo "\t\t<docs>http://blogs.law.harvard.edu/tech/rss</docs>\n";
24
+        echo "\t\t<generator>Gazelle Feed Class</generator>\n\n";
38 25
     }
39
-    if ($Category != '') {
40
-      $Item .= "\t\t\t<category><![CDATA[$Category]]></category>\n";
26
+
27
+    public function item($Title, $Description, $Page, $Creator, $Comments = '', $Category = '', $Date = '')
28
+    {
29
+        //Escape with CDATA, otherwise the feed breaks.
30
+        if ($Date == '') {
31
+            $Date = date('r');
32
+        } else {
33
+            $Date = date('r', strtotime($Date));
34
+        }
35
+        $Site = site_url();
36
+        $Item = "\t\t<item>\n";
37
+        $Item .= "\t\t\t<title><![CDATA[$Title]]></title>\n";
38
+        $Item .= "\t\t\t<description><![CDATA[$Description]]></description>\n";
39
+        $Item .= "\t\t\t<pubDate>$Date</pubDate>\n";
40
+        $Item .= "\t\t\t<link>$Site$Page</link>\n";
41
+        $Item .= "\t\t\t<guid>$Site$Page</guid>\n";
42
+        if ($Comments != '') {
43
+            $Item .= "\t\t\t<comments>$Site$Comments</comments>\n";
44
+        }
45
+        if ($Category != '') {
46
+            $Item .= "\t\t\t<category><![CDATA[$Category]]></category>\n";
47
+        }
48
+        $Item .= "\t\t\t<dc:creator>$Creator</dc:creator>\n\t\t</item>\n";
49
+        return $Item;
41 50
     }
42
-    $Item .= "\t\t\t<dc:creator>$Creator</dc:creator>\n\t\t</item>\n";
43
-    return $Item;
44
-  }
45 51
 
46
-  function retrieve($CacheKey, $AuthKey, $PassKey) {
47
-    global $Cache;
48
-    $Entries = $Cache->get_value($CacheKey);
49
-    if (!$Entries) {
50
-      $Entries = [];
51
-    } else {
52
-      foreach ($Entries as $Item) {
53
-        echo str_replace(array('[[PASSKEY]]', '[[AUTHKEY]]'), array(display_str($PassKey), display_str($AuthKey)), $Item);
54
-      }
52
+    public function retrieve($CacheKey, $AuthKey, $PassKey)
53
+    {
54
+        global $Cache;
55
+        $Entries = $Cache->get_value($CacheKey);
56
+        if (!$Entries) {
57
+            $Entries = [];
58
+        } else {
59
+            foreach ($Entries as $Item) {
60
+                echo str_replace(array('[[PASSKEY]]', '[[AUTHKEY]]'), array(display_str($PassKey), display_str($AuthKey)), $Item);
61
+            }
62
+        }
55 63
     }
56
-  }
57 64
 
58
-  function populate($CacheKey, $Item) {
59
-    global $Cache;
60
-    $Entries = $Cache->get_value($CacheKey, true);
61
-    if (!$Entries) {
62
-      $Entries = [];
63
-    } else {
64
-      if (count($Entries) >= 50) {
65
-        array_pop($Entries);
66
-      }
65
+    public function populate($CacheKey, $Item)
66
+    {
67
+        global $Cache;
68
+        $Entries = $Cache->get_value($CacheKey, true);
69
+        if (!$Entries) {
70
+            $Entries = [];
71
+        } else {
72
+            if (count($Entries) >= 50) {
73
+                array_pop($Entries);
74
+            }
75
+        }
76
+        array_unshift($Entries, $Item);
77
+        $Cache->cache_value($CacheKey, $Entries, 0); //inf cache
67 78
     }
68
-    array_unshift($Entries, $Item);
69
-    $Cache->cache_value($CacheKey, $Entries, 0); //inf cache
70
-  }
71 79
 }

Loading…
Cancel
Save