Файл: forums/class.ForumMain.php
Строк: 60
<?php
/**
* Class for displaying forum topics home
* Sample output
* $fo = new ForumMain ( $user['level'], 4, 25 );
* $fo -> ForumShow ();
* Where $user['level'] is a group for displaying to admins only
* 4 numbers of topics, 25 size of icons.
* Good luck to you...))
*/
class ForumMain
{
// --- Set Default
private $sol = 0;
private $level = 0;
private $limit = 0;
private $w = 'auto';
// --- Default array
private static $i = array (
' Автор: ', ' Система ',
' Последний: ', 'close.png', 'up.png', 'Нет тем' );
// --- Control variables
public function __construct (
$level = 0, $limit = 4, $w = 'auto' ) {
$this->level = $level;
$this->limit = $limit;
$this->w = $w;
return;
}
// --- We work with the tables of the Forum
private function sqlReader ( )
{
$sql = sprintf ("SELECT Comm.CountPost,
Them.Name, Them.ID, Them.ID_razdel, Them.ID_forum,
IF ( Comm.Time IS NULL, Them.time, Comm.Time ) AS CountTime,
# --- We give Nick a conclusion topic or comments
IF ( PostComm.ID_User_Post IS NULL, CONCAT ( '%s ', User.Login ),
CONCAT ( IF ( User.Login IS NULL, '%s',
CONCAT ( '%s ', User.Login ) ) ) ) AS Login,
# --- Determine the choice of icons
CASE
WHEN Them.Close <=> '1' THEN '%s'
WHEN Them.Up <=> '1' THEN '%s'
ELSE Forum.ID_icon END AS Icons
# --- Counter and Time
FROM forum_t AS Them
LEFT JOIN ( SELECT id_them, time AS Time, COUNT( * ) AS CountPost
FROM forum_p GROUP BY id_them )
AS Comm ON Comm.id_them = Them.id
# --- Them Access And Icon
LEFT JOIN ( SELECT id, adm AS ID_Adm, icon AS ID_icon
FROM forum_f GROUP BY id )
AS Forum ON Forum.id = Them.id_forum
# --- Them Post
LEFT JOIN ( SELECT id_them, id_user as ID_User_Post
FROM forum_p GROUP BY id )
AS PostComm ON PostComm.id_them = Them.id
# --- Nick Them and Comm
LEFT JOIN ( SELECT id, nick AS Login
FROM user GROUP BY id ) AS
User ON User.id <=> IF ( PostComm.ID_User_Post IS NOT NULL,
PostComm.ID_User_Post, Them.id_user )
# --- Visibility to admins and Icons
WHERE ID_Adm <= '%s'
GROUP BY Them.id
ORDER BY Them.time_create DESC,
Them.name DESC LIMIT %d ",
# --- Query variables
self::$i[0], self::$i[1], self::$i[2], self::$i[3],
self::$i[4], ( int ) $this->level, ( int ) $this->limit );
return $this -> sol =
mysql_query ( $sql );
}
public function ForumShow ( ) {
$this -> sqlReader();
// --- If there is no
if ( mysql_num_rows ( $this -> sol ) === 0 ) { ?>
<div class='mess'>
<?=self::$i[5]?>
</div>
<?
}
// --- It's a cycle
while ( $i = mysql_fetch_object ( $this -> sol ) )
{
?>
<img src='/style/forum/<?=$i->Icons?>' width='<?=$this->w?>' ALT='N'/>
<a href='/forum/<?=$i->ID_forum?>/<?=$i->ID_razdel?>/<?=$i->ID?>/'>
<?= text ( $i -> Name ) ?> (<?= ( int ) ( $i -> CountPost ) ?>)
<?= vremja ( $i -> CountTime ) ?>
</a>
<br/>
<?= text ( $i -> Login ) ?>
<br/>
<?
}
return;
}
}