View file module/lenta.php

File size: 7.86Kb
<?php

/*************************************************
 *    apwa.ru       lenta.php
 *                 -------------
 *  [email protected] 2011
 ************************************************/

if ( !defined('IN_PHPBB') )
{
	die("Hacking attempt");
}

$lang['Topic_new'] = 'создана тема';
$lang['Album_new_img'] = 'добавленно изображение';
$lang['Album_comment'] = 'добавлен комментарий к %sизображению%s';
$lang['Weblog_new_entry'] = 'создана запись в дневниках';
$lang['Weblog_comments'] = 'добавлен %sкомментарий в дневнике%s';
$lang['Gb_text'] = 'написано сообщение в %sгостевой%s';


$mode = ( isset($HTTP_GET_VARS['mode']) ) ? htmlspecialchars($HTTP_GET_VARS['mode']) : '';
$id = ( intval($HTTP_GET_VARS['id']) ) ? intval($HTTP_GET_VARS['id']) : '';

if ( $mode == 'delete' && $id != '')
{
	 if ( $userdata['user_level'] != ADMIN )
	 {
	         message_die(GENERAL_MESSAGE, $lang['Reached_on_error']);
	 }
         else
         { 
	         $sql = "DELETE FROM " . SOBYTIE_TABLE . " 
		         WHERE id = " . $id;
	         if (!$result = $db->sql_query($sql)) 
	         {
		         message_die(GENERAL_ERROR, 'Error removing shout.', '', __LINE__, __FILE__, $sql);
	         }
	         else
	         {			         
		         message_die(GENERAL_MESSAGE, 'Успешно удалено!<br/>' . sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a>'));
	         } 
	 } 
}
           
$start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;

$result = $db->sql_query('SELECT COUNT(id) AS total FROM ' . SOBYTIE_TABLE);
$row = $db->sql_fetchrow($result);       
$num = $row['total'];		       
$db->sql_freeresult($result);  

$pagination = ( $num == '0' || $profiledata['user_id'] ) ? '' : generate_pagination("index.$phpEx?module=lenta", $num, '8', $start);

$profilesql = ($profiledata['user_id']) ? 'AND s.user_id = ' . $profiledata['user_id'] . '' : '';

$sql = "SELECT s.*, u.user_avatar_type, u.user_allowavatar, u.user_avatar, u.user_nic_color FROM " . SOBYTIE_TABLE . " s, " . USERS_TABLE . " u
        WHERE s.user_id = u.user_id
        $profilesql
        ORDER BY s.time DESC LIMIT " . $start . ", 9";
if ( !$result = $db->sql_query($sql) )
{
	message_die(GENERAL_ERROR, "КосяГ какойто!", '', __LINE__, __FILE__, $sql);
}
$postrow = array();
while ($row = $db->sql_fetchrow($result))
{
       $postrow[] = $row;
}
$db->sql_freeresult($result);
	
$template->set_filenames(array(
	'lenta' => 'module/lenta_body.tpl')
);

$template->assign_vars(array(
        'PAGINATION' => $pagination)
);   

for ($i = 0; $i < count($postrow); $i++)
{	
	/*$time_del = mktime()-(1*86400);
	if ( $postrow[$i]['time'] < $time_del )
	{
                $id = $row['id'];
                $sql = "DELETE FROM " . SOBYTIE_TABLE . "
                        WHERE id = $id";
                if( !$db->sql_query($sql) )
                {
                         message_die(GENERAL_ERROR, 'Could not delete', '', __LINE__, __FILE__, $sql);
                }
	}*/
	
	$images = '';
        $comment_pic_id = '';	
	if ($postrow[$i]['link_type'] == "newtopic")
	{
	        $links = $lang['Topic_new'] . ' <a href="' . append_sid('topic' . $postrow[$i]['link_id'] . '.xhtml') . '">' . $postrow[$i]['subject'] . '</a>';	        
	}
	else if ($postrow[$i]['link_type'] == "album")
	{
	        $links = $lang['Album_new_img'] . ' <a href="' . append_sid('album_page.' . $phpEx . '?pic_id=' . $postrow[$i]['link_id']) . '">' . $postrow[$i]['subject'] . '</a>';
	        $images = '<a href="' . append_sid('album_page.' . $phpEx . '?pic_id=' . $postrow[$i]['link_id']) . '"><img src="' . append_sid('album_pic.'. $phpEx . '?thumb=2&amp;pic_id=' . $postrow[$i]['link_id']) . '" alt="' . $postrow[$i]['subject'] . '"/></a>';	        	        
	        $comment_pic_id = $postrow[$i]['link_id'];
	}
	else if ($postrow[$i]['link_type'] == "album_comment")
	{	        
	        $links = sprintf($lang['Album_comment'], '<a href="' . append_sid('album_comment.' . $phpEx . '?pic_id=' . $postrow[$i]['link_id']) . '">','</a>');
	        $images = '<a href="' . append_sid('album_page.' . $phpEx . '?pic_id=' . $postrow[$i]['link_id']) . '"><img src="' . append_sid('album_pic.'. $phpEx . '?thumb=2&amp;pic_id=' . $postrow[$i]['link_id']) . '" alt=""/></a>'; 	        
	        $comment_pic_id = $postrow[$i]['link_id'];
	}
	else if ($postrow[$i]['link_type'] == "gb_post")
	{
	        $links = sprintf($lang['Gb_text'], '<a href="' . append_sid('gb.' . $phpEx) . '">','</a>');
	}	
	else if ($postrow[$i]['link_type'] == "weblog")
	{
	        $links = $lang['Weblog_new_entry'] . ' <a href="' . append_sid("weblog_entry.$phpEx?" . 'e' . '=' . $postrow[$i]['link_id']) . '">' . $postrow[$i]['subject'] . '</a>';
	}
	else if ($postrow[$i]['link_type'] == "weblog_comment")
	{
	        $links = sprintf($lang['Weblog_comments'], '<a href="' . append_sid("weblog_entry.$phpEx?" . 'e' . '=' . $postrow[$i]['link_id']) . '">', '</a>');
	}
	else
	{
	        $links = $postrow[$i]['subject'];
	}
	
	$text = $postrow[$i]['text']; 
	
	if( strlen($text) > 100 )
	{
	 	$text = substr($text, 0, 100-strlen(strrchr(substr($text, 0, 100), ' '))) . '&hellip;';
	}
	else
	{        
	 	$text = $text;
	} 
	
	$text = preg_replace('#(<)([\/]?.*?)(>)#is', "&lt;\\2&gt;", $text);
        $text = @smilies_pass($text);	
	$text = str_replace("\n", "\n<br />\n", $text);
							
	if ($userdata['user_level'] == ADMIN)
	{
	        $delete = '<a href="' . append_sid("index.$phpEx?mode=delete&amp;id=" . $postrow[$i]['id']) . '">' . $lang['Delete_post'] . '</a>';	        
	}
				
	avatar_img($postrow[$i]['user_avatar_type'], $postrow[$i]['user_allowavatar'], $postrow[$i]['user_avatar'], $avatar_img, $avatar_mini);
        
        $user_id = $postrow[$i]['user_id'];
	$username = str_replace("amp;", "", $postrow[$i]['username']);	
	$user = ( $user_id == ANONYMOUS ) ? $lang['Guest'] : '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . '='  . $user_id) . '">' . $username . '</a>';
        $row_class = ( !($i % 2) ) ? 'row_easy' : 'row_hard';
        
	$template->assign_block_vars('viewrow', array(
		'ROW_CLASS' => $row_class,
	        'AVATAR_MINI' => $avatar_mini,	
		'LINKS' => $links,
		'TEXT' => $images . ' ' . $text,
	        'DELETE' => $delete,	
		'USER' => $user,
		'DATE' => create_date($board_config['default_dateformat'], $postrow[$i]['time'], $board_config['board_timezone']))
	);
        /*if( $comment_pic_id )
        { 	
	        $sql = "SELECT c.*, u.user_id, u.username
		        FROM " . ALBUM_COMMENT_TABLE . " c, " . USERS_TABLE . " u 
		        WHERE c.comment_user_id = u.user_id
			AND c.comment_pic_id = '$comment_pic_id'
			ORDER BY c.comment_time DESC LIMIT 4";
		if( !$result = $db->sql_query($sql) )
		{
			message_die(GENERAL_ERROR, 'Could not obtain comments information from the database', '', __LINE__, __FILE__, $sql);
		}

		while( $row = $db->sql_fetchrow($result) )
		{	
			if( ($row['user_id'] == ALBUM_GUEST) or ($row['username'] == '') )
			{
				$poster = ($row['comment_username'] == '') ? $lang['Guest'] : $row['comment_username'];
			}
			else
			{
				$poster = '<a href="'. append_sid("profile.$phpEx?mode=viewprofile&amp;". POST_USERS_URL .'='. $row['user_id']) .'">'. $row['username'] .'</a>';
			}
			
			$comment_text = smilies_pass($row['comment_text']);	

			$template->assign_block_vars('viewrow.commentrow', array(
				'POSTER' => $poster,
				'TIME' => create_date($board_config['default_dateformat'], $row['comment_time'], $board_config['board_timezone']),
				'TEXT' => $comment_text)
			);	
		}		
        }*/	
}

$template->assign_var_from_handle('MODULE_LENTA', 'lenta');

?>