|
This is where all the magic of the show latest threads block happens. Don Seiler used a simple sqlSelect call to fetch the latest non-hidden posts and gave the result to a new instance of PHPWSBB_Forum.
First, we generate a nice SQL statement that does a bit more than Don's simple sqlSelect:
104 function genLatestThreadsSQL($limit) {
105
106 $prefix=$GLOBALS['core']->tbl_prefix;
107
108 $sql = 'SELECT DISTINCT t.id, p.editor, p.owner, ';
109 $sql.= 'p.label, count(q.tid)-1 pcount ';
110 $sql.= "FROM ${prefix}mod_phpwsbb_threads t, ";
111 $sql.= "${prefix}mod_phpwsbb_messages p, ";
112 $sql.= "${prefix}mod_phpwsbb_messages q ";
113 $sql.= 'WHERE p.id=t.lastpost_post_id AND ';
114 $sql.= 'q.tid=t.id AND t.hidden="0" ';
115 $sql.= 'GROUP BY q.tid ';
116 $sql.= 'ORDER BY t.lastpost DESC ';
117 $sql.= "LIMIT $limit";
118
119
120 return($sql);
121
122 }
...it doesn't really matter where in Runtime.php you put this. Then, we'll enhance (or shall I write: completely redo) the original Latest Threads Block method by showing the information gained through the new SQL statement:
126 /**
127 * Displays block with next set of games in it
128 *
129 * @author Don Seiler <don@NOSPAM.seiler.us>
130 */
131 function showLatestThreadsBlock() {
132
133 // Get settings
134
135 $settings = $GLOBALS['core']->sqlSelect('mod_phpwsbb_settings');
136 $showblock = $settings[0]['showlatestthreadsblock'];
137 $blocktitle = $settings[0]['latestthreadsblocktitle'];
138 $limit = $settings[0]['maxlatestthreads'];
139 $allow_anon_view = $settings[0]['allow_anon_view'];
140 $bboffline = $settings[0]['bboffline'];
141
142
143 if ($bboffline && !$_SESSION['OBJ_user']->isDeity())
144 return;
145
146 if(!$showblock)
147 return;
148
149
150 if(!$allow_anon_view && !$_SESSION['OBJ_user']->username)
151 return;
152
153 $block = NULL;
154
155 // $sql = PHPWS_ genLatestThreadsSQL($limit);
156 $sql=PHPWSBB_Runtime::genLatestThreadsSQL($limit);
157
158 $result = $GLOBALS['core']->getAllAssoc($sql);
159 $length=30;
160
161 if($result)
162 foreach($result as $nr => $row) {
163
164 $editor=$row['editor'];
165 $owner=$row['owner'];
166 $title=$row['label'];
167 $posts=$row['pcount'];
168 $id=$row['id'];
169
170 if(strlen($title)>$length)
171 $lbl=substr($title, 0, $length).'...';
172 else
173 $lbl=$title;
174
175 if(isset($editor))
176 $poster=$editor;
177 else
178 if(isset($owner))
179 $poster=$owner;
180 else
181 $poster=$_SESSION['translate']->it('Guest');
182
183
184 $link=PHPWS_Text::moduleLink($lbl, 'phpwsbb',
185 array( 'PHPWSBB_MAN_OP'=>'view',
186 'PHPWS_MAN_ITEMS'=>$id),
187 null, null, null);
188
189 $block .= "<p><strong>$poster</strong><br />".
190 "$link($posts)</p>";
191
192 }
193
194 $GLOBALS['CNT_phpwsbb_latestthreadsblock']['title'] =
195 $blocktitle;
196
197 $GLOBALS['CNT_phpwsbb_latestthreadsblock']['content'] = $block;
198
199 }// END FUNC showLatestThreadsBlock
|