Browse Source

Quick sanity check (textareas eventually replaced)

pjc 5 years ago
parent
commit
85e44697df

+ 561
- 559
classes/text.class.php
File diff suppressed because it is too large
View File


+ 161
- 143
classes/textarea_preview.class.php View File

1
 <?php
1
 <?php
2
+
2
 /**
3
 /**
3
  * This super class is used to manage the ammount of textareas there are and to
4
  * This super class is used to manage the ammount of textareas there are and to
4
  * generate the required JavaScript that enables the previews to work.
5
  * generate the required JavaScript that enables the previews to work.
5
  */
6
  */
6
-class TEXTAREA_PREVIEW_SUPER {
7
+class TEXTAREA_PREVIEW_SUPER
8
+{
9
+  
7
   /**
10
   /**
8
    * @static
11
    * @static
9
    * @var int $Textareas Total number of textareas created
12
    * @var int $Textareas Total number of textareas created
10
    */
13
    */
11
-  protected static $Textareas = 0;
12
-
13
-  /**
14
-   * @static
15
-   * @var array $_ID Array of textarea IDs
16
-   */
17
-  protected static $_ID = [];
18
-
19
-  /**
20
-   * @static
21
-   * @var bool For use in JavaScript method
22
-   */
23
-  private static $Exectuted = false;
24
-
25
-  /**
26
-   * This method should only run once with $all as true and should be placed
27
-   * in the header or footer.
28
-   *
29
-   * If $all is true, it includes TextareaPreview and jQuery
30
-   *
31
-   * jQuery is required for this to work, include it in the headers.
32
-   *
33
-   * @static
34
-   * @param bool $all Output all required scripts, otherwise just do iterator()
35
-   * @example <pre><?php TEXT_PREVIEW::JavaScript(); ?></pre>
36
-   * @return void
37
-   */
38
-  public static function JavaScript ($all = true) {
39
-    if (self::$Textareas === 0) {
40
-      return;
41
-    }
42
-    if (self::$Exectuted === false && $all) {
43
-      View::parse('generic/textarea/script.phtml');
14
+    protected static $Textareas = 0;
15
+
16
+    /**
17
+     * @static
18
+     * @var array $_ID Array of textarea IDs
19
+     */
20
+    protected static $_ID = [];
21
+
22
+    /**
23
+     * @static
24
+     * @var bool For use in JavaScript method
25
+     */
26
+    private static $Exectuted = false;
27
+
28
+    /**
29
+     * This method should only run once with $all as true and should be placed
30
+     * in the header or footer.
31
+     *
32
+     * If $all is true, it includes TextareaPreview and jQuery
33
+     *
34
+     * jQuery is required for this to work, include it in the headers.
35
+     *
36
+     * @static
37
+     * @param bool $all Output all required scripts, otherwise just do iterator()
38
+     * @example <pre><?php TEXT_PREVIEW::JavaScript(); ?></pre>
39
+     * @return void
40
+     */
41
+    public static function JavaScript($all = true)
42
+    {
43
+        if (self::$Textareas === 0) {
44
+            return;
45
+        }
46
+        if (self::$Exectuted === false && $all) {
47
+            View::parse('generic/textarea/script.phtml');
48
+        }
49
+
50
+        self::$Exectuted = true;
51
+        self::iterator();
44
     }
52
     }
45
 
53
 
46
-    self::$Exectuted = true;
47
-    self::iterator();
48
-  }
49
-
50
-  /**
51
-   * This iterator generates JavaScript to initialize each JavaScript
52
-   * TextareaPreview object.
53
-   *
54
-   * It will generate a numeric or custom ID related to the textarea.
55
-   * @static
56
-   * @return void
57
-   */
58
-  private static function iterator() {
59
-    $script = [];
60
-    for ($i = 0; $i < self::$Textareas; $i++) {
61
-      if (isset(self::$_ID[$i]) && is_string(self::$_ID[$i])) {
62
-        $a = sprintf('%d, "%s"', $i, self::$_ID[$i]);
63
-      } else {
64
-        $a = $i;
65
-      }
66
-      $script[] = sprintf('[%s]', $a);
67
-    }
68
-    if (!empty($script)) {
69
-      View::parse('generic/textarea/script_factory.phtml', array('script' => join(', ', $script)));
54
+    /**
55
+     * This iterator generates JavaScript to initialize each JavaScript
56
+     * TextareaPreview object.
57
+     *
58
+     * It will generate a numeric or custom ID related to the textarea.
59
+     * @static
60
+     * @return void
61
+     */
62
+    private static function iterator()
63
+    {
64
+        $script = [];
65
+        for ($i = 0; $i < self::$Textareas; $i++) {
66
+            if (isset(self::$_ID[$i]) && is_string(self::$_ID[$i])) {
67
+                $a = sprintf('%d, "%s"', $i, self::$_ID[$i]);
68
+            } else {
69
+                $a = $i;
70
+            }
71
+            $script[] = sprintf('[%s]', $a);
72
+        }
73
+        if (!empty($script)) {
74
+            View::parse('generic/textarea/script_factory.phtml', array('script' => join(', ', $script)));
75
+        }
70
     }
76
     }
71
-  }
72
 }
77
 }
73
 
78
 
74
 /**
79
 /**
110
  * </div>
115
  * </div>
111
  * </pre>
116
  * </pre>
112
  */
117
  */
113
-class TEXTAREA_PREVIEW extends TEXTAREA_PREVIEW_SUPER {
114
-  /**
115
-   * @var int Unique ID
116
-   */
117
-  private $id;
118
+class TEXTAREA_PREVIEW extends TEXTAREA_PREVIEW_SUPER
119
+{
118
 
120
 
119
   /**
121
   /**
120
-   * Flag for preview output
121
-   * @var bool $preview
122
-   */
123
-  private $preview = false;
124
-
125
-  /**
126
-   * String table
127
-   * @var string Buffer
128
-   */
129
-  private $buffer = null;
130
-
131
-  /**
132
-   * This method creates a textarea
133
-   *
134
-   * @param string $Name     name attribute
135
-   * @param string $ID       id attribute
136
-   * @param string $Value    default text attribute
137
-   * @param string $Cols     cols attribute
138
-   * @param string $Rows     rows attribute
139
-   * @param bool   $Preview  add the preview divs near the textarea
140
-   * @param bool   $Buttons  add the edit/preview buttons near the textarea
141
-   * @param bool   $Buffer   doesn't output the textarea, use getBuffer()
142
-   * @param array  $ExtraAttributes  array of attribute="value"
143
-   *
144
-   * If false for $Preview, $Buttons, or $Buffer, use the appropriate
145
-   * methods to add the those elements manually. Alternatively, use getID
146
-   * to create your own.
147
-   *
148
-   * It's important to have the right IDs as they make the JS function properly.
122
+   * @var int Unique ID
149
    */
123
    */
150
-  public function __construct($Name, $ID = '', $Value = '', $Cols = 50, $Rows = 10,
151
-    $Preview = true, $Buttons = true, $Buffer = false,
152
-    array $ExtraAttributes = []
124
+    private $id;
125
+
126
+    /**
127
+     * Flag for preview output
128
+     * @var bool $preview
129
+     */
130
+    private $preview = false;
131
+
132
+    /**
133
+     * String table
134
+     * @var string Buffer
135
+     */
136
+    private $buffer = null;
137
+
138
+    /**
139
+     * This method creates a textarea
140
+     *
141
+     * @param string $Name     name attribute
142
+     * @param string $ID       id attribute
143
+     * @param string $Value    default text attribute
144
+     * @param string $Cols     cols attribute
145
+     * @param string $Rows     rows attribute
146
+     * @param bool   $Preview  add the preview divs near the textarea
147
+     * @param bool   $Buttons  add the edit/preview buttons near the textarea
148
+     * @param bool   $Buffer   doesn't output the textarea, use getBuffer()
149
+     * @param array  $ExtraAttributes  array of attribute="value"
150
+     *
151
+     * If false for $Preview, $Buttons, or $Buffer, use the appropriate
152
+     * methods to add the those elements manually. Alternatively, use getID
153
+     * to create your own.
154
+     *
155
+     * It's important to have the right IDs as they make the JS function properly.
156
+     */
157
+    public function __construct(
158
+      $Name,
159
+      $ID = '',
160
+      $Value = '',
161
+      $Cols = 50,
162
+      $Rows = 10,
163
+      $Preview = true,
164
+      $Buttons = true,
165
+      $Buffer = false,
166
+      array $ExtraAttributes = []
153
   ) {
167
   ) {
154
-    $this->id = parent::$Textareas;
155
-    parent::$Textareas += 1;
156
-    array_push(parent::$_ID, $ID);
168
+        $this->id = parent::$Textareas;
169
+        parent::$Textareas += 1;
170
+        array_push(parent::$_ID, $ID);
157
 
171
 
158
-    if (empty($ID)) {
159
-      $ID = 'quickpost_' . $this->id;
160
-    }
172
+        if (empty($ID)) {
173
+            $ID = 'quickpost_' . $this->id;
174
+        }
161
 
175
 
162
-    if (!empty($ExtraAttributes)) {
163
-      $Attributes = ' ' . implode(' ', $ExtraAttributes);
164
-    } else {
165
-      $Attributes = '';
166
-    }
176
+        if (!empty($ExtraAttributes)) {
177
+            $Attributes = ' ' . implode(' ', $ExtraAttributes);
178
+        } else {
179
+            $Attributes = '';
180
+        }
167
 
181
 
168
-    if ($Preview === true) {
169
-      $this->preview();
170
-    }
182
+        if ($Preview === true) {
183
+            $this->preview();
184
+        }
171
 
185
 
172
-    $this->buffer = View::parse('generic/textarea/textarea.phtml', array(
186
+        $this->buffer = View::parse('generic/textarea/textarea.phtml', array(
173
       'ID' => $ID,
187
       'ID' => $ID,
174
       'NID' => $this->id,
188
       'NID' => $this->id,
175
       'Name' => &$Name,
189
       'Name' => &$Name,
179
       'Attributes' => &$Attributes
193
       'Attributes' => &$Attributes
180
     ), $Buffer);
194
     ), $Buffer);
181
 
195
 
182
-    if ($Buttons === true) {
183
-      $this->buttons();
196
+        if ($Buttons === true) {
197
+            $this->buttons();
198
+        }
184
     }
199
     }
185
-  }
186
 
200
 
187
-  /**
188
-   * Outputs the divs required for previewing the AJAX content
189
-   * Will only output once
190
-   */
191
-  public function preview() {
192
-    if (!$this->preview) {
193
-      View::parse('generic/textarea/preview.phtml', array('ID' => $this->id));
201
+    /**
202
+     * Outputs the divs required for previewing the AJAX content
203
+     * Will only output once
204
+     */
205
+    public function preview()
206
+    {
207
+        if (!$this->preview) {
208
+            View::parse('generic/textarea/preview.phtml', array('ID' => $this->id));
209
+        }
210
+        $this->preview = true;
194
     }
211
     }
195
-    $this->preview = true;
196
-  }
197
 
212
 
198
-  /**
199
-   * Outputs the preview and edit buttons
200
-   * Can be called many times to place buttons in different areas
201
-   */
202
-  public function buttons() {
203
-    View::parse('generic/textarea/buttons.phtml', array('ID' => $this->id));
204
-  }
213
+    /**
214
+     * Outputs the preview and edit buttons
215
+     * Can be called many times to place buttons in different areas
216
+     */
217
+    public function buttons()
218
+    {
219
+        View::parse('generic/textarea/buttons.phtml', array('ID' => $this->id));
220
+    }
205
 
221
 
206
-  /**
207
-   * Returns the textarea's numeric ID.
208
-   */
209
-  public function getID() {
210
-    return $this->id;
211
-  }
222
+    /**
223
+     * Returns the textarea's numeric ID.
224
+     */
225
+    public function getID()
226
+    {
227
+        return $this->id;
228
+    }
212
 
229
 
213
-  /**
214
-   * Returns textarea string when buffer is enabled in the constructor
215
-   * @return string
216
-   */
217
-  public function getBuffer() {
218
-    return $this->buffer;
219
-  }
230
+    /**
231
+     * Returns textarea string when buffer is enabled in the constructor
232
+     * @return string
233
+     */
234
+    public function getBuffer()
235
+    {
236
+        return $this->buffer;
237
+    }
220
 }
238
 }

+ 61
- 61
sections/ajax/forum/forum.php View File

1
-<?
2
-
1
+<?php
3
 
2
 
4
 /**********|| Page to show individual forums || ********************************\
3
 /**********|| Page to show individual forums || ********************************\
5
 
4
 
15
 // Check for lame SQL injection attempts
14
 // Check for lame SQL injection attempts
16
 $ForumID = $_GET['forumid'];
15
 $ForumID = $_GET['forumid'];
17
 if (!is_number($ForumID)) {
16
 if (!is_number($ForumID)) {
18
-  print json_encode(array('status' => 'failure'));
19
-  die();
17
+    print json_encode(array('status' => 'failure'));
18
+    die();
20
 }
19
 }
21
 
20
 
22
 if (isset($_GET['pp'])) {
21
 if (isset($_GET['pp'])) {
23
-  $PerPage = intval($_GET['pp']);
22
+    $PerPage = intval($_GET['pp']);
24
 } elseif (isset($LoggedUser['PostsPerPage'])) {
23
 } elseif (isset($LoggedUser['PostsPerPage'])) {
25
-  $PerPage = $LoggedUser['PostsPerPage'];
24
+    $PerPage = $LoggedUser['PostsPerPage'];
26
 } else {
25
 } else {
27
-  $PerPage = POSTS_PER_PAGE;
26
+    $PerPage = POSTS_PER_PAGE;
28
 }
27
 }
29
 
28
 
30
 list($Page, $Limit) = Format::page_limit(TOPICS_PER_PAGE);
29
 list($Page, $Limit) = Format::page_limit(TOPICS_PER_PAGE);
33
 
32
 
34
 // Caching anything beyond the first page of any given forum is just wasting ram
33
 // Caching anything beyond the first page of any given forum is just wasting ram
35
 // users are more likely to search then to browse to page 2
34
 // users are more likely to search then to browse to page 2
36
-if ($Page == 1) {
37
-  list($Forum,,,$Stickies) = $Cache->get_value("forums_$ForumID");
35
+if ($Page === 1) {
36
+    list($Forum, , , $Stickies) = $Cache->get_value("forums_$ForumID");
38
 }
37
 }
39
 if (!isset($Forum) || !is_array($Forum)) {
38
 if (!isset($Forum) || !is_array($Forum)) {
40
-  $DB->query("
39
+    $DB->query("
41
     SELECT
40
     SELECT
42
       ID,
41
       ID,
43
       Title,
42
       Title,
52
     WHERE ForumID = '$ForumID'
51
     WHERE ForumID = '$ForumID'
53
     ORDER BY IsSticky DESC, LastPostTime DESC
52
     ORDER BY IsSticky DESC, LastPostTime DESC
54
     LIMIT $Limit"); // Can be cached until someone makes a new post
53
     LIMIT $Limit"); // Can be cached until someone makes a new post
55
-  $Forum = $DB->to_array('ID',MYSQLI_ASSOC, false);
56
-  if ($Page == 1) {
57
-    $DB->query("
54
+    $Forum = $DB->to_array('ID', MYSQLI_ASSOC, false);
55
+    if ($Page === 1) {
56
+        $DB->query("
58
       SELECT COUNT(ID)
57
       SELECT COUNT(ID)
59
       FROM forums_topics
58
       FROM forums_topics
60
       WHERE ForumID = '$ForumID'
59
       WHERE ForumID = '$ForumID'
61
         AND IsSticky = '1'");
60
         AND IsSticky = '1'");
62
-    list($Stickies) = $DB->next_record();
63
-    $Cache->cache_value("forums_$ForumID", array($Forum, '', 0, $Stickies), 0);
64
-  }
61
+        list($Stickies) = $DB->next_record();
62
+        $Cache->cache_value("forums_$ForumID", array($Forum, '', 0, $Stickies), 0);
63
+    }
65
 }
64
 }
66
 
65
 
67
 if (!isset($Forums[$ForumID])) {
66
 if (!isset($Forums[$ForumID])) {
68
-  json_die("failure");
67
+    json_die("failure");
69
 }
68
 }
70
 // Make sure they're allowed to look at the page
69
 // Make sure they're allowed to look at the page
71
 if (!check_perms('site_moderate_forums')) {
70
 if (!check_perms('site_moderate_forums')) {
72
-  if (isset($LoggedUser['CustomForums'][$ForumID]) && $LoggedUser['CustomForums'][$ForumID] === 0) {
73
-    json_die("failure", "insufficient permissions to view page");
74
-  }
71
+    if (isset($LoggedUser['CustomForums'][$ForumID]) && $LoggedUser['CustomForums'][$ForumID] === 0) {
72
+        json_die("failure", "insufficient permissions to view page");
73
+    }
75
 }
74
 }
76
 if ($LoggedUser['CustomForums'][$ForumID] != 1 && $Forums[$ForumID]['MinClassRead'] > $LoggedUser['Class']) {
75
 if ($LoggedUser['CustomForums'][$ForumID] != 1 && $Forums[$ForumID]['MinClassRead'] > $LoggedUser['Class']) {
77
-  json_die("failure", "insufficient permissions to view page");
76
+    json_die("failure", "insufficient permissions to view page");
78
 }
77
 }
79
 
78
 
80
 $ForumName = display_str($Forums[$ForumID]['Name']);
79
 $ForumName = display_str($Forums[$ForumID]['Name']);
81
 $JsonSpecificRules = [];
80
 $JsonSpecificRules = [];
82
 foreach ($Forums[$ForumID]['SpecificRules'] as $ThreadIDs) {
81
 foreach ($Forums[$ForumID]['SpecificRules'] as $ThreadIDs) {
83
-  $Thread = Forums::get_thread_info($ThreadIDs);
84
-  $JsonSpecificRules[] = array(
82
+    $Thread = Forums::get_thread_info($ThreadIDs);
83
+    $JsonSpecificRules[] = array(
85
     'threadId' => (int)$ThreadIDs,
84
     'threadId' => (int)$ThreadIDs,
86
     'thread' => display_str($Thread['Title'])
85
     'thread' => display_str($Thread['Title'])
87
   );
86
   );
90
 $Pages = Format::get_pages($Page, $Forums[$ForumID]['NumTopics'], TOPICS_PER_PAGE, 9);
89
 $Pages = Format::get_pages($Page, $Forums[$ForumID]['NumTopics'], TOPICS_PER_PAGE, 9);
91
 
90
 
92
 if (count($Forum) === 0) {
91
 if (count($Forum) === 0) {
93
-  print
92
+    print
94
     json_encode(
93
     json_encode(
95
-      array(
94
+        array(
96
         'status' => 'success',
95
         'status' => 'success',
97
         'forumName' => $ForumName,
96
         'forumName' => $ForumName,
98
         'threads' => []
97
         'threads' => []
99
       )
98
       )
100
     );
99
     );
101
 } else {
100
 } else {
102
-  // forums_last_read_topics is a record of the last post a user read in a topic, and what page that was on
103
-  $DB->query("
101
+    // forums_last_read_topics is a record of the last post a user read in a topic, and what page that was on
102
+    $DB->query("
104
     SELECT
103
     SELECT
105
       l.TopicID,
104
       l.TopicID,
106
       l.PostID,
105
       l.PostID,
116
     WHERE l.TopicID IN(".implode(', ', array_keys($Forum)).')
115
     WHERE l.TopicID IN(".implode(', ', array_keys($Forum)).')
117
       AND l.UserID = \''.$LoggedUser['ID'].'\'');
116
       AND l.UserID = \''.$LoggedUser['ID'].'\'');
118
 
117
 
119
-  // Turns the result set into a multi-dimensional array, with
120
-  // forums_last_read_topics.TopicID as the key.
121
-  // This is done here so we get the benefit of the caching, and we
122
-  // don't have to make a database query for each topic on the page
123
-  $LastRead = $DB->to_array('TopicID');
118
+    // Turns the result set into a multi-dimensional array, with
119
+    // forums_last_read_topics.TopicID as the key.
120
+    // This is done here so we get the benefit of the caching, and we
121
+    // don't have to make a database query for each topic on the page
122
+    $LastRead = $DB->to_array('TopicID');
124
 
123
 
125
-  $JsonTopics = [];
126
-  foreach ($Forum as $Topic) {
127
-    list($TopicID, $Title, $AuthorID, $Locked, $Sticky, $PostCount, $LastID, $LastTime, $LastAuthorID) = array_values($Topic);
124
+    $JsonTopics = [];
125
+    foreach ($Forum as $Topic) {
126
+        list($TopicID, $Title, $AuthorID, $Locked, $Sticky, $PostCount, $LastID, $LastTime, $LastAuthorID) = array_values($Topic);
128
 
127
 
129
-    // handle read/unread posts - the reason we can't cache the whole page
130
-    if ((!$Locked || $Sticky)
128
+        // Handle read/unread posts - the reason we can't cache the whole page
129
+        if ((!$Locked || $Sticky)
131
         && ((empty($LastRead[$TopicID]) || $LastRead[$TopicID]['PostID'] < $LastID)
130
         && ((empty($LastRead[$TopicID]) || $LastRead[$TopicID]['PostID'] < $LastID)
132
           && strtotime($LastTime) > $LoggedUser['CatchupTime'])
131
           && strtotime($LastTime) > $LoggedUser['CatchupTime'])
133
     ) {
132
     ) {
134
-      $Read = 'unread';
135
-    } else {
136
-      $Read = 'read';
137
-    }
138
-    $UserInfo = Users::user_info($AuthorID);
139
-    $AuthorName = $UserInfo['Username'];
140
-    $UserInfo = Users::user_info($LastAuthorID);
141
-    $LastAuthorName = $UserInfo['Username'];
142
-    // Bug fix for no last time available
143
-    if (!$LastTime) { $LastTime = ''; }
144
-
145
-    $JsonTopics[] = array(
133
+            $Read = 'unread';
134
+        } else {
135
+            $Read = 'read';
136
+        }
137
+        $UserInfo = Users::user_info($AuthorID);
138
+        $AuthorName = $UserInfo['Username'];
139
+        $UserInfo = Users::user_info($LastAuthorID);
140
+        $LastAuthorName = $UserInfo['Username'];
141
+        // Bug fix for no last time available
142
+        if (!$LastTime) {
143
+            $LastTime = '';
144
+        }
145
+
146
+        $JsonTopics[] = array(
146
       'topicId' => (int)$TopicID,
147
       'topicId' => (int)$TopicID,
147
       'title' => display_str($Title),
148
       'title' => display_str($Title),
148
       'authorId' => (int)$AuthorID,
149
       'authorId' => (int)$AuthorID,
149
       'authorName' => $AuthorName,
150
       'authorName' => $AuthorName,
150
-      'locked' => $Locked == 1,
151
-      'sticky' => $Sticky == 1,
151
+      'locked' => $Locked === 1,
152
+      'sticky' => $Sticky === 1,
152
       'postCount' => (int)$PostCount,
153
       'postCount' => (int)$PostCount,
153
-      'lastID' => ($LastID == null) ? 0 : (int)$LastID,
154
+      'lastID' => ($LastID === null) ? 0 : (int)$LastID,
154
       'lastTime' => $LastTime,
155
       'lastTime' => $LastTime,
155
-      'lastAuthorId' => ($LastAuthorID == null) ? 0 : (int)$LastAuthorID,
156
-      'lastAuthorName' => ($LastAuthorName == null) ? '' : $LastAuthorName,
157
-      'lastReadPage' => ($LastRead[$TopicID]['Page'] == null) ? 0 : (int)$LastRead[$TopicID]['Page'],
158
-      'lastReadPostId' => ($LastRead[$TopicID]['PostID'] == null) ? 0 : (int)$LastRead[$TopicID]['PostID'],
159
-      'read' => $Read == 'read'
156
+      'lastAuthorId' => ($LastAuthorID === null) ? 0 : (int)$LastAuthorID,
157
+      'lastAuthorName' => ($LastAuthorName === null) ? '' : $LastAuthorName,
158
+      'lastReadPage' => ($LastRead[$TopicID]['Page'] === null) ? 0 : (int)$LastRead[$TopicID]['Page'],
159
+      'lastReadPostId' => ($LastRead[$TopicID]['PostID'] === null) ? 0 : (int)$LastRead[$TopicID]['PostID'],
160
+      'read' => $Read === 'read'
160
     );
161
     );
161
-  }
162
+    }
162
 
163
 
163
-  print
164
+    print
164
     json_encode(
165
     json_encode(
165
-      array(
166
+        array(
166
         'status' => 'success',
167
         'status' => 'success',
167
         'response' => array(
168
         'response' => array(
168
           'forumName' => $ForumName,
169
           'forumName' => $ForumName,
174
       )
175
       )
175
     );
176
     );
176
 }
177
 }
177
-?>

+ 13
- 12
sections/ajax/forum/index.php View File

1
-<?
1
+<?php
2
+
2
 // Already done in /sections/ajax/index.php
3
 // Already done in /sections/ajax/index.php
3
 //enforce_login();
4
 //enforce_login();
4
 
5
 
5
 if (!empty($LoggedUser['DisableForums'])) {
6
 if (!empty($LoggedUser['DisableForums'])) {
6
-  print json_encode(array('status' => 'failure'));
7
-  die();
7
+    print json_encode(array('status' => 'failure'));
8
+    die();
8
 } else {
9
 } else {
9
-  // Replace the old hard-coded forum categories
10
-  $ForumCats = Forums::get_forum_categories();
10
+    // Replace the old hard-coded forum categories
11
+    $ForumCats = Forums::get_forum_categories();
11
 
12
 
12
-  //This variable contains all our lovely forum data
13
-  $Forums = Forums::get_forums();
13
+    // This variable contains all our lovely forum data
14
+    $Forums = Forums::get_forums();
14
 
15
 
15
-  if (empty($_GET['type']) || $_GET['type'] == 'main') {
16
-    include(SERVER_ROOT.'/sections/ajax/forum/main.php');
17
-  } else {
18
-    switch ($_GET['type']) {
16
+    if (empty($_GET['type']) || $_GET['type'] === 'main') {
17
+        include(SERVER_ROOT.'/sections/ajax/forum/main.php');
18
+    } else {
19
+        switch ($_GET['type']) {
19
       case 'viewforum':
20
       case 'viewforum':
20
         include(SERVER_ROOT.'/sections/ajax/forum/forum.php');
21
         include(SERVER_ROOT.'/sections/ajax/forum/forum.php');
21
         break;
22
         break;
26
         print json_encode(array('status' => 'failure'));
27
         print json_encode(array('status' => 'failure'));
27
         break;
28
         break;
28
     }
29
     }
29
-  }
30
+    }
30
 }
31
 }

+ 38
- 38
sections/ajax/forum/main.php View File

1
-<?
1
+<?php
2
 
2
 
3
 if (isset($LoggedUser['PostsPerPage'])) {
3
 if (isset($LoggedUser['PostsPerPage'])) {
4
-  $PerPage = $LoggedUser['PostsPerPage'];
4
+    $PerPage = $LoggedUser['PostsPerPage'];
5
 } else {
5
 } else {
6
-  $PerPage = POSTS_PER_PAGE;
6
+    $PerPage = POSTS_PER_PAGE;
7
 }
7
 }
8
 
8
 
9
-//We have to iterate here because if one is empty it breaks the query
9
+// We have to iterate here because if one is empty it breaks the query
10
 $TopicIDs = [];
10
 $TopicIDs = [];
11
 foreach ($Forums as $Forum) {
11
 foreach ($Forums as $Forum) {
12
-  if (!empty($Forum['LastPostTopicID'])) {
13
-    $TopicIDs[] = $Forum['LastPostTopicID'];
14
-  }
12
+    if (!empty($Forum['LastPostTopicID'])) {
13
+        $TopicIDs[] = $Forum['LastPostTopicID'];
14
+    }
15
 }
15
 }
16
 
16
 
17
-//Now if we have IDs' we run the query
17
+// Now if we have IDs' we run the query
18
 if (!empty($TopicIDs)) {
18
 if (!empty($TopicIDs)) {
19
-  $DB->query("
19
+    $DB->query("
20
     SELECT
20
     SELECT
21
       l.TopicID,
21
       l.TopicID,
22
       l.PostID,
22
       l.PostID,
31
     FROM forums_last_read_topics AS l
31
     FROM forums_last_read_topics AS l
32
     WHERE l.TopicID IN(".implode(',', $TopicIDs).")
32
     WHERE l.TopicID IN(".implode(',', $TopicIDs).")
33
       AND l.UserID = '$LoggedUser[ID]'");
33
       AND l.UserID = '$LoggedUser[ID]'");
34
-  $LastRead = $DB->to_array('TopicID', MYSQLI_ASSOC);
34
+    $LastRead = $DB->to_array('TopicID', MYSQLI_ASSOC);
35
 } else {
35
 } else {
36
-  $LastRead = [];
36
+    $LastRead = [];
37
 }
37
 }
38
 
38
 
39
 $DB->query("
39
 $DB->query("
48
 $JsonCategory = [];
48
 $JsonCategory = [];
49
 $JsonForums = [];
49
 $JsonForums = [];
50
 foreach ($Forums as $Forum) {
50
 foreach ($Forums as $Forum) {
51
-  list($ForumID, $CategoryID, $ForumName, $ForumDescription, $MinRead, $MinWrite, $MinCreate, $NumTopics, $NumPosts, $LastPostID, $LastAuthorID, $LastTopicID, $LastTime, $SpecificRules, $LastTopic, $Locked, $Sticky) = array_values($Forum);
52
-  if ($LoggedUser['CustomForums'][$ForumID] != 1
51
+    list($ForumID, $CategoryID, $ForumName, $ForumDescription, $MinRead, $MinWrite, $MinCreate, $NumTopics, $NumPosts, $LastPostID, $LastAuthorID, $LastTopicID, $LastTime, $SpecificRules, $LastTopic, $Locked, $Sticky) = array_values($Forum);
52
+    if ($LoggedUser['CustomForums'][$ForumID] != 1
53
       && ($MinRead > $LoggedUser['Class']
53
       && ($MinRead > $LoggedUser['Class']
54
       || array_search($ForumID, $RestrictedForums) !== false)
54
       || array_search($ForumID, $RestrictedForums) !== false)
55
   ) {
55
   ) {
56
-    continue;
57
-  }
58
-  $ForumDescription = display_str($ForumDescription);
59
-
60
-  if ($CategoryID != $LastCategoryID) {
61
-    if (!empty($JsonForums) && !empty($JsonCategory)) {
62
-      $JsonCategory['forums'] = $JsonForums;
63
-      $JsonCategories[] = $JsonCategory;
56
+        continue;
64
     }
57
     }
65
-    $LastCategoryID = $CategoryID;
66
-    $JsonCategory = array(
58
+    $ForumDescription = display_str($ForumDescription);
59
+
60
+    if ($CategoryID != $LastCategoryID) {
61
+        if (!empty($JsonForums) && !empty($JsonCategory)) {
62
+            $JsonCategory['forums'] = $JsonForums;
63
+            $JsonCategories[] = $JsonCategory;
64
+        }
65
+        $LastCategoryID = $CategoryID;
66
+        $JsonCategory = array(
67
       'categoryID' => (int)$CategoryID,
67
       'categoryID' => (int)$CategoryID,
68
       'categoryName' => $ForumCats[$CategoryID]
68
       'categoryName' => $ForumCats[$CategoryID]
69
     );
69
     );
70
-    $JsonForums = [];
71
-  }
70
+        $JsonForums = [];
71
+    }
72
 
72
 
73
-  if ((!$Locked || $Sticky)
73
+    if ((!$Locked || $Sticky)
74
       && $LastPostID != 0
74
       && $LastPostID != 0
75
       && ((empty($LastRead[$LastTopicID]) || $LastRead[$LastTopicID]['PostID'] < $LastPostID)
75
       && ((empty($LastRead[$LastTopicID]) || $LastRead[$LastTopicID]['PostID'] < $LastPostID)
76
         && strtotime($LastTime) > $LoggedUser['CatchupTime'])
76
         && strtotime($LastTime) > $LoggedUser['CatchupTime'])
77
   ) {
77
   ) {
78
-    $Read = 'unread';
79
-  } else {
80
-    $Read = 'read';
81
-  }
82
-  $UserInfo = Users::user_info($LastAuthorID);
78
+        $Read = 'unread';
79
+    } else {
80
+        $Read = 'read';
81
+    }
82
+    $UserInfo = Users::user_info($LastAuthorID);
83
 
83
 
84
-  $JsonForums[] = array(
84
+    $JsonForums[] = array(
85
     'forumId' => (int)$ForumID,
85
     'forumId' => (int)$ForumID,
86
     'forumName' => $ForumName,
86
     'forumName' => $ForumName,
87
     'forumDescription' => $ForumDescription,
87
     'forumDescription' => $ForumDescription,
94
     'lastTime' => $LastTime,
94
     'lastTime' => $LastTime,
95
     'specificRules' => $SpecificRules,
95
     'specificRules' => $SpecificRules,
96
     'lastTopic' => display_str($LastTopic),
96
     'lastTopic' => display_str($LastTopic),
97
-    'read' => $Read == 1,
98
-    'locked' => $Locked == 1,
99
-    'sticky' => $Sticky == 1
97
+    'read' => $Read === 1,
98
+    'locked' => $Locked === 1,
99
+    'sticky' => $Sticky === 1
100
   );
100
   );
101
 }
101
 }
102
 // ...And an extra one to catch the last category.
102
 // ...And an extra one to catch the last category.
103
 if (!empty($JsonForums) && !empty($JsonCategory)) {
103
 if (!empty($JsonForums) && !empty($JsonCategory)) {
104
-  $JsonCategory['forums'] = $JsonForums;
105
-  $JsonCategories[] = $JsonCategory;
104
+    $JsonCategory['forums'] = $JsonForums;
105
+    $JsonCategories[] = $JsonCategory;
106
 }
106
 }
107
 
107
 
108
 print json_encode(
108
 print json_encode(
109
-  array(
109
+    array(
110
     'status' => 'success',
110
     'status' => 'success',
111
     'response' => array(
111
     'response' => array(
112
       'categories' => $JsonCategories
112
       'categories' => $JsonCategories

+ 123
- 126
sections/ajax/forum/thread.php View File

1
 <?php
1
 <?php
2
+
2
 // todo: Normalize thread_*_info don't need to waste all that ram on things that are already in other caches
3
 // todo: Normalize thread_*_info don't need to waste all that ram on things that are already in other caches
3
 /**********|| Page to show individual threads || ********************************\
4
 /**********|| Page to show individual threads || ********************************\
4
 
5
 
13
 
14
 
14
 // Check for lame SQL injection attempts
15
 // Check for lame SQL injection attempts
15
 if (!isset($_GET['threadid']) || !is_number($_GET['threadid'])) {
16
 if (!isset($_GET['threadid']) || !is_number($_GET['threadid'])) {
16
-  if (isset($_GET['topicid']) && is_number($_GET['topicid'])) {
17
-    $ThreadID = $_GET['topicid'];
18
-  } elseif (isset($_GET['postid']) && is_number($_GET['postid'])) {
19
-    $DB->query("
17
+    if (isset($_GET['topicid']) && is_number($_GET['topicid'])) {
18
+        $ThreadID = $_GET['topicid'];
19
+    } elseif (isset($_GET['postid']) && is_number($_GET['postid'])) {
20
+        $DB->query("
20
       SELECT TopicID
21
       SELECT TopicID
21
       FROM forums_posts
22
       FROM forums_posts
22
       WHERE ID = $_GET[postid]");
23
       WHERE ID = $_GET[postid]");
23
-    list($ThreadID) = $DB->next_record();
24
-    if ($ThreadID) {
25
-      //Redirect postid to threadid when necessary.
26
-      header("Location: ajax.php?action=forum&type=viewthread&threadid=$ThreadID&postid=$_GET[postid]");
27
-      die();
24
+        list($ThreadID) = $DB->next_record();
25
+        if ($ThreadID) {
26
+            //Redirect postid to threadid when necessary.
27
+            header("Location: ajax.php?action=forum&type=viewthread&threadid=$ThreadID&postid=$_GET[postid]");
28
+            die();
29
+        } else {
30
+            print json_encode(array('status' => 'failure'));
31
+            die();
32
+        }
28
     } else {
33
     } else {
29
-      print json_encode(array('status' => 'failure'));
30
-      die();
34
+        print json_encode(array('status' => 'failure'));
35
+        die();
31
     }
36
     }
32
-  } else {
33
-    print json_encode(array('status' => 'failure'));
34
-    die();
35
-  }
36
 } else {
37
 } else {
37
-  $ThreadID = $_GET['threadid'];
38
+    $ThreadID = $_GET['threadid'];
38
 }
39
 }
39
 
40
 
40
 if (isset($_GET['pp'])) {
41
 if (isset($_GET['pp'])) {
41
-  $PerPage = $_GET['pp'];
42
+    $PerPage = $_GET['pp'];
42
 } elseif (isset($LoggedUser['PostsPerPage'])) {
43
 } elseif (isset($LoggedUser['PostsPerPage'])) {
43
-  $PerPage = $LoggedUser['PostsPerPage'];
44
+    $PerPage = $LoggedUser['PostsPerPage'];
44
 } else {
45
 } else {
45
-  $PerPage = POSTS_PER_PAGE;
46
+    $PerPage = POSTS_PER_PAGE;
46
 }
47
 }
47
 
48
 
48
-
49
-
50
 //---------- Get some data to start processing
49
 //---------- Get some data to start processing
51
 
50
 
52
 // Thread information, constant across all pages
51
 // Thread information, constant across all pages
53
 $ThreadInfo = Forums::get_thread_info($ThreadID, true, true);
52
 $ThreadInfo = Forums::get_thread_info($ThreadID, true, true);
54
 if ($ThreadInfo === null) {
53
 if ($ThreadInfo === null) {
55
-  json_die('failure', 'no such thread exists');
54
+    json_die('failure', 'no such thread exists');
56
 }
55
 }
57
 $ForumID = $ThreadInfo['ForumID'];
56
 $ForumID = $ThreadInfo['ForumID'];
58
 
57
 
59
 // Make sure they're allowed to look at the page
58
 // Make sure they're allowed to look at the page
60
 if (!Forums::check_forumperm($ForumID)) {
59
 if (!Forums::check_forumperm($ForumID)) {
61
-  print json_encode(array('status' => 'failure'));
62
-  die();
60
+    print json_encode(array('status' => 'failure'));
61
+    die();
63
 }
62
 }
64
 
63
 
65
-//Post links utilize the catalogue & key params to prevent issues with custom posts per page
64
+// Post links utilize the catalogue & key params to prevent issues with custom posts per page
66
 if ($ThreadInfo['Posts'] > $PerPage) {
65
 if ($ThreadInfo['Posts'] > $PerPage) {
67
-  if (isset($_GET['post']) && is_number($_GET['post'])) {
68
-    $PostNum = $_GET['post'];
69
-  } elseif (isset($_GET['postid']) && is_number($_GET['postid'])) {
70
-    $DB->query("
66
+    if (isset($_GET['post']) && is_number($_GET['post'])) {
67
+        $PostNum = $_GET['post'];
68
+    } elseif (isset($_GET['postid']) && is_number($_GET['postid'])) {
69
+        $DB->query("
71
       SELECT COUNT(ID)
70
       SELECT COUNT(ID)
72
       FROM forums_posts
71
       FROM forums_posts
73
       WHERE TopicID = $ThreadID
72
       WHERE TopicID = $ThreadID
74
         AND ID <= $_GET[postid]");
73
         AND ID <= $_GET[postid]");
75
-    list($PostNum) = $DB->next_record();
76
-  } else {
77
-    $PostNum = 1;
78
-  }
74
+        list($PostNum) = $DB->next_record();
75
+    } else {
76
+        $PostNum = 1;
77
+    }
79
 } else {
78
 } else {
80
-  $PostNum = 1;
79
+    $PostNum = 1;
81
 }
80
 }
82
 list($Page, $Limit) = Format::page_limit($PerPage, min($ThreadInfo['Posts'], $PostNum));
81
 list($Page, $Limit) = Format::page_limit($PerPage, min($ThreadInfo['Posts'], $PostNum));
83
 if (($Page - 1) * $PerPage > $ThreadInfo['Posts']) {
82
 if (($Page - 1) * $PerPage > $ThreadInfo['Posts']) {
84
-  $Page = ceil($ThreadInfo['Posts'] / $PerPage);
83
+    $Page = ceil($ThreadInfo['Posts'] / $PerPage);
85
 }
84
 }
86
-list($CatalogueID,$CatalogueLimit) = Format::catalogue_limit($Page, $PerPage, THREAD_CATALOGUE);
85
+list($CatalogueID, $CatalogueLimit) = Format::catalogue_limit($Page, $PerPage, THREAD_CATALOGUE);
87
 
86
 
88
 // Cache catalogue from which the page is selected, allows block caches and future ability to specify posts per page
87
 // Cache catalogue from which the page is selected, allows block caches and future ability to specify posts per page
89
 if (!$Catalogue = $Cache->get_value("thread_$ThreadID"."_catalogue_$CatalogueID")) {
88
 if (!$Catalogue = $Cache->get_value("thread_$ThreadID"."_catalogue_$CatalogueID")) {
90
-  $DB->query("
89
+    $DB->query("
91
     SELECT
90
     SELECT
92
       p.ID,
91
       p.ID,
93
       p.AuthorID,
92
       p.AuthorID,
99
     WHERE p.TopicID = '$ThreadID'
98
     WHERE p.TopicID = '$ThreadID'
100
       AND p.ID != '".$ThreadInfo['StickyPostID']."'
99
       AND p.ID != '".$ThreadInfo['StickyPostID']."'
101
     LIMIT $CatalogueLimit");
100
     LIMIT $CatalogueLimit");
102
-  $Catalogue = $DB->to_array(false, MYSQLI_ASSOC);
103
-  if (!$ThreadInfo['IsLocked'] || $ThreadInfo['IsSticky']) {
104
-    $Cache->cache_value("thread_$ThreadID"."_catalogue_$CatalogueID", $Catalogue, 0);
105
-  }
101
+    $Catalogue = $DB->to_array(false, MYSQLI_ASSOC);
102
+    if (!$ThreadInfo['IsLocked'] || $ThreadInfo['IsSticky']) {
103
+        $Cache->cache_value("thread_$ThreadID"."_catalogue_$CatalogueID", $Catalogue, 0);
104
+    }
106
 }
105
 }
107
 $Thread = Format::catalogue_select($Catalogue, $Page, $PerPage, THREAD_CATALOGUE);
106
 $Thread = Format::catalogue_select($Catalogue, $Page, $PerPage, THREAD_CATALOGUE);
108
 
107
 
109
 if ($_GET['updatelastread'] !== '0') {
108
 if ($_GET['updatelastread'] !== '0') {
110
-  $LastPost = end($Thread);
111
-  $LastPost = $LastPost['ID'];
112
-  reset($Thread);
113
-  if ($ThreadInfo['Posts'] <= $PerPage * $Page && $ThreadInfo['StickyPostID'] > $LastPost) {
114
-    $LastPost = $ThreadInfo['StickyPostID'];
115
-  }
116
-  //Handle last read
117
-  if (!$ThreadInfo['IsLocked'] || $ThreadInfo['IsSticky']) {
118
-    $DB->query("
109
+    $LastPost = end($Thread);
110
+    $LastPost = $LastPost['ID'];
111
+    reset($Thread);
112
+    if ($ThreadInfo['Posts'] <= $PerPage * $Page && $ThreadInfo['StickyPostID'] > $LastPost) {
113
+        $LastPost = $ThreadInfo['StickyPostID'];
114
+    }
115
+    // Handle last read
116
+    if (!$ThreadInfo['IsLocked'] || $ThreadInfo['IsSticky']) {
117
+        $DB->query("
119
       SELECT PostID
118
       SELECT PostID
120
       FROM forums_last_read_topics
119
       FROM forums_last_read_topics
121
       WHERE UserID = '$LoggedUser[ID]'
120
       WHERE UserID = '$LoggedUser[ID]'
122
         AND TopicID = '$ThreadID'");
121
         AND TopicID = '$ThreadID'");
123
-    list($LastRead) = $DB->next_record();
124
-    if ($LastRead < $LastPost) {
125
-      $DB->query("
122
+        list($LastRead) = $DB->next_record();
123
+        if ($LastRead < $LastPost) {
124
+            $DB->query("
126
         INSERT INTO forums_last_read_topics
125
         INSERT INTO forums_last_read_topics
127
           (UserID, TopicID, PostID)
126
           (UserID, TopicID, PostID)
128
         VALUES
127
         VALUES
129
           ('$LoggedUser[ID]', '$ThreadID', '".db_string($LastPost)."')
128
           ('$LoggedUser[ID]', '$ThreadID', '".db_string($LastPost)."')
130
         ON DUPLICATE KEY UPDATE
129
         ON DUPLICATE KEY UPDATE
131
           PostID = '$LastPost'");
130
           PostID = '$LastPost'");
131
+        }
132
     }
132
     }
133
-  }
134
 }
133
 }
135
 
134
 
136
-//Handle subscriptions
135
+// Handle subscriptions
137
 $UserSubscriptions = Subscriptions::get_subscriptions();
136
 $UserSubscriptions = Subscriptions::get_subscriptions();
138
 
137
 
139
 if (empty($UserSubscriptions)) {
138
 if (empty($UserSubscriptions)) {
140
-  $UserSubscriptions = [];
139
+    $UserSubscriptions = [];
141
 }
140
 }
142
 
141
 
143
 if (in_array($ThreadID, $UserSubscriptions)) {
142
 if (in_array($ThreadID, $UserSubscriptions)) {
144
-  $Cache->delete_value('subscriptions_user_new_'.$LoggedUser['ID']);
143
+    $Cache->delete_value('subscriptions_user_new_'.$LoggedUser['ID']);
145
 }
144
 }
146
 
145
 
147
 $JsonPoll = [];
146
 $JsonPoll = [];
148
 if ($ThreadInfo['NoPoll'] == 0) {
147
 if ($ThreadInfo['NoPoll'] == 0) {
149
-  if (!list($Question, $Answers, $Votes, $Featured, $Closed) = $Cache->get_value("polls_$ThreadID")) {
150
-    $DB->query("
148
+    if (!list($Question, $Answers, $Votes, $Featured, $Closed) = $Cache->get_value("polls_$ThreadID")) {
149
+        $DB->query("
151
       SELECT Question, Answers, Featured, Closed
150
       SELECT Question, Answers, Featured, Closed
152
       FROM forums_polls
151
       FROM forums_polls
153
       WHERE TopicID = '$ThreadID'");
152
       WHERE TopicID = '$ThreadID'");
154
-    list($Question, $Answers, $Featured, $Closed) = $DB->next_record(MYSQLI_NUM, array(1));
155
-    $Answers = unserialize($Answers);
156
-    $DB->query("
153
+        list($Question, $Answers, $Featured, $Closed) = $DB->next_record(MYSQLI_NUM, array(1));
154
+        $Answers = unserialize($Answers);
155
+        $DB->query("
157
       SELECT Vote, COUNT(UserID)
156
       SELECT Vote, COUNT(UserID)
158
       FROM forums_polls_votes
157
       FROM forums_polls_votes
159
       WHERE TopicID = '$ThreadID'
158
       WHERE TopicID = '$ThreadID'
160
       GROUP BY Vote");
159
       GROUP BY Vote");
161
-    $VoteArray = $DB->to_array(false, MYSQLI_NUM);
160
+        $VoteArray = $DB->to_array(false, MYSQLI_NUM);
162
 
161
 
163
-    $Votes = [];
164
-    foreach ($VoteArray as $VoteSet) {
165
-      list($Key, $Value) = $VoteSet;
166
-      $Votes[$Key] = $Value;
167
-    }
162
+        $Votes = [];
163
+        foreach ($VoteArray as $VoteSet) {
164
+            list($Key, $Value) = $VoteSet;
165
+            $Votes[$Key] = $Value;
166
+        }
168
 
167
 
169
-    foreach (array_keys($Answers) as $i) {
170
-      if (!isset($Votes[$i])) {
171
-        $Votes[$i] = 0;
172
-      }
168
+        foreach (array_keys($Answers) as $i) {
169
+            if (!isset($Votes[$i])) {
170
+                $Votes[$i] = 0;
171
+            }
172
+        }
173
+        $Cache->cache_value("polls_$ThreadID", array($Question, $Answers, $Votes, $Featured, $Closed), 0);
173
     }
174
     }
174
-    $Cache->cache_value("polls_$ThreadID", array($Question, $Answers, $Votes, $Featured, $Closed), 0);
175
-  }
176
 
175
 
177
-  if (!empty($Votes)) {
178
-    $TotalVotes = array_sum($Votes);
179
-    $MaxVotes = max($Votes);
180
-  } else {
181
-    $TotalVotes = 0;
182
-    $MaxVotes = 0;
183
-  }
176
+    if (!empty($Votes)) {
177
+        $TotalVotes = array_sum($Votes);
178
+        $MaxVotes = max($Votes);
179
+    } else {
180
+        $TotalVotes = 0;
181
+        $MaxVotes = 0;
182
+    }
184
 
183
 
185
-  $RevealVoters = in_array($ForumID, FORUMS_TO_REVEAL_VOTERS);
186
-  //Polls lose the you voted arrow thingy
187
-  $DB->query("
184
+    $RevealVoters = in_array($ForumID, FORUMS_TO_REVEAL_VOTERS);
185
+    //Polls lose the you voted arrow thingy
186
+    $DB->query("
188
     SELECT Vote
187
     SELECT Vote
189
     FROM forums_polls_votes
188
     FROM forums_polls_votes
190
     WHERE UserID = '".$LoggedUser['ID']."'
189
     WHERE UserID = '".$LoggedUser['ID']."'
191
       AND TopicID = '$ThreadID'");
190
       AND TopicID = '$ThreadID'");
192
-  list($UserResponse) = $DB->next_record();
193
-  if (!empty($UserResponse) && $UserResponse != 0) {
194
-    $Answers[$UserResponse] = '&raquo; '.$Answers[$UserResponse];
195
-  } else {
196
-    if (!empty($UserResponse) && $RevealVoters) {
197
-      $Answers[$UserResponse] = '&raquo; '.$Answers[$UserResponse];
191
+    list($UserResponse) = $DB->next_record();
192
+    if (!empty($UserResponse) && $UserResponse != 0) {
193
+        $Answers[$UserResponse] = '&raquo; '.$Answers[$UserResponse];
194
+    } else {
195
+        if (!empty($UserResponse) && $RevealVoters) {
196
+            $Answers[$UserResponse] = '&raquo; '.$Answers[$UserResponse];
197
+        }
198
     }
198
     }
199
-  }
200
 
199
 
201
-  $JsonPoll['closed'] = ($Closed == 1);
202
-  $JsonPoll['featured'] = $Featured;
203
-  $JsonPoll['question'] = $Question;
204
-  $JsonPoll['maxVotes'] = (int)$MaxVotes;
205
-  $JsonPoll['totalVotes'] = $TotalVotes;
206
-  $JsonPollAnswers = [];
200
+    $JsonPoll['closed'] = ($Closed == 1);
201
+    $JsonPoll['featured'] = $Featured;
202
+    $JsonPoll['question'] = $Question;
203
+    $JsonPoll['maxVotes'] = (int)$MaxVotes;
204
+    $JsonPoll['totalVotes'] = $TotalVotes;
205
+    $JsonPollAnswers = [];
207
 
206
 
208
-  foreach ($Answers as $i => $Answer) {
209
-    if (!empty($Votes[$i]) && $TotalVotes > 0) {
210
-      $Ratio = $Votes[$i] / $MaxVotes;
211
-      $Percent = $Votes[$i] / $TotalVotes;
212
-    } else {
213
-      $Ratio = 0;
214
-      $Percent = 0;
215
-    }
216
-    $JsonPollAnswers[] = array(
207
+    foreach ($Answers as $i => $Answer) {
208
+        if (!empty($Votes[$i]) && $TotalVotes > 0) {
209
+            $Ratio = $Votes[$i] / $MaxVotes;
210
+            $Percent = $Votes[$i] / $TotalVotes;
211
+        } else {
212
+            $Ratio = 0;
213
+            $Percent = 0;
214
+        }
215
+        $JsonPollAnswers[] = array(
217
       'answer' => $Answer,
216
       'answer' => $Answer,
218
       'ratio' => $Ratio,
217
       'ratio' => $Ratio,
219
       'percent' => $Percent
218
       'percent' => $Percent
220
     );
219
     );
221
-  }
220
+    }
222
 
221
 
223
-  if ($UserResponse !== null || $Closed || $ThreadInfo['IsLocked'] || $LoggedUser['Class'] < $Forums[$ForumID]['MinClassWrite']) {
224
-    $JsonPoll['voted'] = True;
225
-  } else {
226
-    $JsonPoll['voted'] = False;
227
-  }
222
+    if ($UserResponse !== null || $Closed || $ThreadInfo['IsLocked'] || $LoggedUser['Class'] < $Forums[$ForumID]['MinClassWrite']) {
223
+        $JsonPoll['voted'] = true;
224
+    } else {
225
+        $JsonPoll['voted'] = false;
226
+    }
228
 
227
 
229
-  $JsonPoll['answers'] = $JsonPollAnswers;
228
+    $JsonPoll['answers'] = $JsonPollAnswers;
230
 }
229
 }
231
 
230
 
232
-//Sqeeze in stickypost
231
+// Sqeeze in stickypost
233
 if ($ThreadInfo['StickyPostID']) {
232
 if ($ThreadInfo['StickyPostID']) {
234
-  if ($ThreadInfo['StickyPostID'] != $Thread[0]['ID']) {
235
-    array_unshift($Thread, $ThreadInfo['StickyPost']);
236
-  }
237
-  if ($ThreadInfo['StickyPostID'] != $Thread[count($Thread) - 1]['ID']) {
238
-    $Thread[] = $ThreadInfo['StickyPost'];
239
-  }
233
+    if ($ThreadInfo['StickyPostID'] != $Thread[0]['ID']) {
234
+        array_unshift($Thread, $ThreadInfo['StickyPost']);
235
+    }
236
+    if ($ThreadInfo['StickyPostID'] != $Thread[count($Thread) - 1]['ID']) {
237
+        $Thread[] = $ThreadInfo['StickyPost'];
238
+    }
240
 }
239
 }
241
 
240
 
242
 $JsonPosts = [];
241
 $JsonPosts = [];
243
 foreach ($Thread as $Key => $Post) {
242
 foreach ($Thread as $Key => $Post) {
244
-  list($PostID, $AuthorID, $AddedTime, $Body, $EditedUserID, $EditedTime) = array_values($Post);
245
-  list($AuthorID, $Username, $PermissionID, $Paranoia, $Artist, $Donor, $Warned, $Avatar, $Enabled, $UserTitle) = array_values(Users::user_info($AuthorID));
246
-
247
-
243
+    list($PostID, $AuthorID, $AddedTime, $Body, $EditedUserID, $EditedTime) = array_values($Post);
244
+    list($AuthorID, $Username, $PermissionID, $Paranoia, $Artist, $Donor, $Warned, $Avatar, $Enabled, $UserTitle) = array_values(Users::user_info($AuthorID));
248
 
245
 
249
-  $UserInfo = Users::user_info($EditedUserID);
250
-  $JsonPosts[] = [
246
+    $UserInfo = Users::user_info($EditedUserID);
247
+    $JsonPosts[] = [
251
     'postId' => (int)$PostID,
248
     'postId' => (int)$PostID,
252
     'addedTime' => $AddedTime,
249
     'addedTime' => $AddedTime,
253
     'bbBody' => $Body,
250
     'bbBody' => $Body,

Loading…
Cancel
Save