Location: PHPKode > projects > Enigma > Enigma2/Enigma2_Install/Blocks/Block_headlines.php
<?php
/*
*****************************************************************

 Block_headlines.php
 
*****************************************************************
LSP: Lunabyte Systems Portal
Open-Source Project Inspired by Zef Hemel (hide@address.com)
*****************************************************************
Software Version:                  LSP 2.0 "Enigma 2"
Software by:                         Lunabyte Systems (http://www.lunabyte.net)
Copyright 2002-2005 by:       Lunabyte Systems (http://www.lunabyte.net)
Support, News, Updates at:    http://www.lunabyte.net
*****************************************************************
This program is free software; you may redistribute it and/or modify it 
under the terms of the provided license as published by Lunabyte Systems.

This program is distributed in the hope that it is and will be useful,                  
but WITHOUT ANY WARRANTIES; without even any implied warranty of           
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                        

See the "LSP_license.txt" file for details of the LSP license.
The latest version can always be found at http://www.lunabyte.net.
*****************************************************************
*/

if (!defined('ENIGMA'))
	die('<b>Access Violation</b><br />Direct Access to this location is not allowed.');

function Block_headlines()
{
     global $_REQUEST, $scripturl, $db_prefix, $user_info, $context, $settings, $txt, $ID_MEMBER, $modSettings;

	loadPLanguage('News');
	
	$nend = !empty($modSettings['maxnewsitems']) ? $modSettings['maxnewsitems'] : '5';

	$LIMIT = 'LIMIT 0, ' . $nend;

	// Find all the news for the current display.  Newer ones will have higher IDs.
	$request = db_query("
		SELECT
			n.*, m.posterTime, m.subject, m.ID_TOPIC, m.ID_MEMBER, m.ID_MSG, m.ID_BOARD, b.name AS bName,  
			t2.numReplies AS Replies, t2.numViews AS Views, nc.name AS CatName, nc.image AS CatImage, nc.ID_CATEGORY AS CatId,
			IFNULL(mem.realName, m.posterName) AS posterName, " . ($user_info['is_guest'] ? '1 AS isRead, 0 as logTime' : '
			IFNULL(lt.logTime, IFNULL(lmr.logTime, 0)) >= GREATEST(m.posterTime, m.modifiedTime) AS isRead,
			IFNULL(lt.logTime, IFNULL(lmr.logTime, 0)) AS logTime') . "
		FROM ({$db_prefix}news AS n, {$db_prefix}messages AS m, {$db_prefix}topics AS t2, {$db_prefix}boards AS b)
			LEFT JOIN {$db_prefix}news_categories AS nc ON (n.ID_CATEGORY = nc.ID_CATEGORY)
			LEFT JOIN {$db_prefix}topics AS t ON (n.ID_TOPIC = t.ID_FIRST_MSG)
			LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)" . (!$user_info['is_guest'] ? "
			LEFT JOIN {$db_prefix}log_topics AS lt ON (lt.ID_TOPIC = m.ID_TOPIC AND lt.ID_MEMBER = $ID_MEMBER)
			LEFT JOIN {$db_prefix}log_mark_read AS lmr ON (lmr.ID_BOARD = m.ID_BOARD AND lmr.ID_MEMBER = $ID_MEMBER)" : '') . "
		WHERE $user_info[query_see_board]
			AND n.ID_TOPIC = m.ID_TOPIC
			AND n.publish = 0
			AND n.stage = 1 AND reviewFlag = 0
			AND b.ID_BOARD = m.ID_BOARD
			AND m.ID_MSG = t2.ID_FIRST_MSG
		GROUP BY m.ID_MSG DESC
		$LIMIT", __FILE__, __LINE__);

	while ($row = mysql_fetch_assoc($request))
	{
		// Censor the subject.
		censorText($row['subject']);
		censorText($row['body']);

		// Build the array.
		$headline[] = array(
			'title' => $row['subject'],
			'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . ';topicseen#msg' . $row['ID_MSG'],
			'poster' => array(
				'id' => $row['ID_MEMBER'],
				'name' => $row['posterName'],
				'href' => empty($row['ID_MEMBER']) ? '' : $scripturl . '?action=profile;u=' . $row['ID_MEMBER'],
				'link' => empty($row['ID_MEMBER']) ? $row['posterName'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['posterName'] . '</a>'
			),
			'new' => !empty($row['isRead']),
		);
	}
	mysql_free_result($request);
	
	if (empty($headline))  // if by chance there isn't any news, load a message saying that
	{
		return $txt['news_none'];
	}
	
	else
	{
		echo '
			<table border="0" class="ssi_table">';

		foreach( $headline AS $news)
		{
			echo '
				<tr>
					<td><small>
						<a href="', $news['href'], '">', $news['title'], '</a>
						', $txt[525], ' ', $news['poster']['link'], '
						', $news['new'] ? '' : '<a href="' . $news['href'] . '"><img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="' . $txt[302] . '" border="0" /></a>', '
					</small></td>
				</tr>';		
		}
		
		echo '
			</table>';
	}

}
?>
Return current item: Enigma