All pastes #452883 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-04-22 16:21 UTC
rendered paste body
<?php
////////// SETTINGS
$default_number = 5;	// ilosc tematow na liscie (domyslnie)
$default_maxlength = 60;	// maksymalna ilosc znakow w temacie
$default_frame = '_blank';	// domysla ramka do wczytywania tematow (okno)
$default_charset = 'iso-8859-2';	// domyslne kodowanie strony, na ktorej beda wyswietlane tematy (iso-8859-2, utf-8, windows-1250)
$default_expires = 0;	// domyslne czas utraty waznosci w minutach
//////////


if (!isset($_GET)) $_GET = $HTTP_GET_VARS;
$number = !empty($_GET['n']) ? intval($_GET['n']) : $default_number;
$maxlength = !empty($_GET{'m'}) ? intval($_GET['m']) : $default_maxlength;
$frame = isset($_GET['f']) ? $_GET['f'] : $default_frame;
$charset = !empty($_GET['c']) ? $_GET['c'] : $default_charset;
$javascript = isset($_GET['j']) ? true : false;
$javascriptID = !empty($_GET['j']) && eregi('^[a-z_][a-z0-9_]*$', $_GET['j']) ? $_GET['j'] : null;
$expires = isset($_GET['e']) ? $_GET['e'] : $default_expires;
$forums = isset($_GET['id']) && ereg('^[0-9]+(,[0-9]+)*$', $_GET['id']) ? $_GET['id'] : '';

if ($expires == 0)
{
	// Nie przechowuj w cache'u:
	@ header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
	@ header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
	@ header('Cache-Control: no-store, no-cache, must-revalidate');
	@ header('Cache-Control: post-check=0, pre-check=0', false);
	@ header('Pragma: no-cache');
}
else
{
	@ header('Expires: ' . gmdate('D, d M Y H:i:s', gmmktime() + $expires*60) . ' GMT');
}

if (!$_SERVER) $_SERVER = $HTTP_SERVER_VARS;
$base_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']) . '/';
$base_url = ereg_replace('/+$', '/', $base_url);
if (isset($_SERVER['PATH_TRANSLATED']))
{
	$base_path = dirname($_SERVER['PATH_TRANSLATED']) . '/';
	$base_path = ereg_replace('/+$', '/', $base_path);
}
else $base_path = './';
$phpbb_root_path = $base_path;

if (defined('IN_PHPBB')) exit;
define('IN_PHPBB', true); 
include($base_path . 'extension.inc'); 
include($base_path . 'config.'.$phpEx); 
include($base_path . 'includes/constants.'.$phpEx);
include($base_path . 'includes/functions.'.$phpEx); 
include($base_path . 'includes/db.'.$phpEx); 


$sql = "SELECT t.topic_id, t.topic_title, f.forum_name, p.post_id 
  FROM " . TOPICS_TABLE . " AS t, " . POSTS_TABLE . " AS p, " . FORUMS_TABLE . " AS f 
  WHERE 
    t.forum_id = f.forum_id 
      AND f.auth_view = " . AUTH_ALL . " 
      AND p.topic_id = t.topic_id 
      AND p.post_id = t.topic_last_post_id " .
      ($forums == '' ? '' : " AND f.forum_id IN (" . $forums . ")") . " 
  ORDER BY p.post_time DESC LIMIT " . $number;

if ( !($result = $db->sql_query($sql)) )
{
	$db->sql_close();
	exit;
}

if ($javascript)
{
	if ($javascriptID) echo 'if (document.getElementById(\'' . $javascriptID . '\')) document.getElementById(\'' . $javascriptID . '\').innerHTML = \'';
	else echo "document.write('";
}

echo '<ul>';

$i = 0;
while ($row = $db->sql_fetchrow($result))
{
	$row['topic_title'] = html_entity_decode($row['topic_title']);
	$row['topic_title'] = stripslashes($row['topic_title']);
	
	// Przycinanie:
	if (strlen($row['topic_title']) > $maxlength)
	{
		$row['topic_title'] = substr($row['topic_title'], 0, $maxlength);
		if (strstr($row['topic_title'], ' ')) $row['topic_title'] = substr($row['topic_title'], 0, strrpos($row['topic_title'], ' '));
		$row['topic_title'] .= '...';
	}
	
	// Cenzura:
	$orig_word = array();
	$replacement_word = array();
	obtain_word_list($orig_word, $replacement_word);
	if (count($orig_word)) $row['topic_title'] = preg_replace($orig_word, $replacement_word, $row['topic_title']);
	
	// Zamiana strony kodowej:
	$charset = strtolower($charset);
	if ($charset == 'windows-1250')
	{
		$row['topic_title'] = strtr($row['topic_title'], "\xA1\xA6\xAC\xB1\xB6\xBC", "\xA5\x8C\x8F\xB9\x9C\x9F");
		$row['forum_name'] = strtr($row['forum_name'], "\xA1\xA6\xAC\xB1\xB6\xBC", "\xA5\x8C\x8F\xB9\x9C\x9F");
	}
	else if ($charset == 'utf-8')
	{
		$row['topic_title'] = str_replace(array("\xA1","\xC6","\xCA","\xA3","\xD1","\xD3","\xA6","\xAC","\xAF", "\xB1","\xE6","\xEA","\xB3","\xF1","\xF3","\xB6","\xBC","\xBF"), array("\xC4\x84","\xC4\x86","\xC4\x98","\xC5\x81","\xC5\x83","\xC3\x93","\xC5\x9A","\xC5\xB9","\xC5\xBB", "\xC4\x85","\xC4\x87","\xC4\x99","\xC5\x82","\xC5\x84","\xC3\xB3","\xC5\x9B","\xC5\xBA","\xC5\xBC"), $row['topic_title']);
		$row['forum_name'] = str_replace(array("\xA1","\xC6","\xCA","\xA3","\xD1","\xD3","\xA6","\xAC","\xAF", "\xB1","\xE6","\xEA","\xB3","\xF1","\xF3","\xB6","\xBC","\xBF"), array("\xC4\x84","\xC4\x86","\xC4\x98","\xC5\x81","\xC5\x83","\xC3\x93","\xC5\x9A","\xC5\xB9","\xC5\xBB", "\xC4\x85","\xC4\x87","\xC4\x99","\xC5\x82","\xC5\x84","\xC3\xB3","\xC5\x9B","\xC5\xBA","\xC5\xBC"), $row['forum_name']);
	}
	
	$link = '<li class="row' . (($i++ % 2)+1) . '"><a' . ($frame ? ' target="' . htmlspecialchars($frame) . '"' : '') .' href="' . $base_url . 'viewtopic.' . $phpEx . '?' . POST_TOPIC_URL . '=' . urlencode($row['topic_id']) . '" title="' . htmlspecialchars(strip_tags($row['forum_name'])) . '">' . htmlspecialchars($row['topic_title']) . '</a>&nbsp;<b><a' . ($frame ? ' target="' . htmlspecialchars($frame) . '"' : '') .' href="' . $base_url . 'viewtopic.' . $phpEx . '?' . POST_POST_URL . '=' . urlencode($row['post_id']) . '#' . htmlspecialchars($row['post_id']) . '">&raquo;</a></b></li>';	
	echo (!$javascript ? $link . "\n" : str_replace(array("\\", "'"), array("\\\\", "\\'"), $link));
}

echo '</ul>';

if ($javascript)
{
	if ($javascriptID) echo '\';';
	else echo '\');';
}

$db->sql_freeresult($result);
$db->sql_close();

unset($base_url, $base_path);
?>