Witam,
Chciałbym wstawić aktualnośc/nowości z forum na stronie głównej.
Jest jakiś skrypt aby mi to w tym pomogło ?
@edit. Nie wiem czy dobrze wybrałem, ale ściągnąłem topics_anywhere.
No i mam problem otóż : Wypełniłem wszystko to co trzeba, jednak lukę na port nic nie wstawiłem i błąd wyskoczył taki : SQLSTATE[28000] [1045] Access denied for user 'konsole-pc'@'77.55.54.65' (using password: YES)
A gdy już ustawiłem port : Fatal error: Call to a member function fetch() on a non-object in /home/konsole-pc/ftp/forum/topics_anywhere.php on line 227
<?php
$dbms = 'mysql';
$dbhost = 'sql.bla bla';
$dbport = '3307';
$dbname = 'nazwa';
$dbuser = 'nazwa';
$dbpasswd = 'hasło';
$table_prefix = '';
$limit = 10; // Topics limit
$length = 30; // Title length limit (in characters)
// Set an exception handler
set_exception_handler('handle_exception');
{
throw new Exception('Wymagane PHP 5 lub nowsze!');
}
if (!class_exists('PDO'))
{
throw new Exception('Wymagane rozszerzenie PHP Data Objects (PDO)!');
}
/**
* @param object $exception
* @return string
*/
function handle_exception($exception)
{
echo $exception->getMessage(); }
/**
* @param string $format
* @param int $timestamp
* @param int $timezone
* @param bool $dst
* @return string
*/
function format_date($format, $timestamp, $timezone, $dst)
{
'Tomorrow' => 'jutro',
'Today' => 'dzisiaj',
'Yesterday' => 'wczoraj',
0 => 'niecałą minutę temu',
1 => '%d min temu',
2 => '%d min temu',
60 => '1 godzinę temu'
),
'Monday' => 'poniedziałek',
'Tuesday' => 'wtorek',
'Wednesday' => 'środa',
'Thursday' => 'czwartek',
'Friday' => 'piątek',
'Saturday' => 'sobota',
'Sunday' => 'niedziela',
'Mon' => 'pn',
'Tue' => 'wt',
'Wed' => 'śr',
'Thu' => 'czw',
'Fri' => 'pt',
'Sat' => 'sob',
'Sun' => 'ndz',
'January' => 'stycznia',
'February' => 'lutego',
'March' => 'marca',
'April' => 'kwietnia',
'May' => 'maja',
'June' => 'czerwca',
'July' => 'lipca',
'August' => 'sierpnia',
'September' => 'września',
'October' => 'października',
'November' => 'listopada',
'December' => 'grudnia',
'Jan' => 'sty',
'Feb' => 'lut',
'Mar' => 'mar',
'Apr' => 'kwie',
'May_short' => 'maja',
'Jun' => 'cze',
'Jul' => 'lip',
'Aug' => 'sie',
'Sep' => 'wrz',
'Oct' => 'paź',
'Nov' => 'lis',
'Dec' => 'gru',
);
$zone_offset = $timezone * 3600 + $dst * 3600;
$midnight = gmmktime(0
, 0
, 0
) - $zone_offset; $delta = time() - $timestamp;
'is_short' => strpos($format, '|'), );
// Some languages use different terms for the long and short format of May
if ((strpos($format, '\M') === false && strpos($format, 'M') !== false) || (strpos($format, '\r') === false && strpos($format, 'r') !== false)) {
$l10n['May'] = $l10n['May_short'];
}
if ($date['is_short'] !== false)
{
// Relative dates in minutes and hours, e.g. 5 minutes ago
if ($delta < 60)
{
return $l10n['Ago'][0];
}
else if ($delta < 120)
{
}
else if ($delta < 3600 )
{
}
else if ($delta < 7200 )
{
}
// Relative dates in days, e.g. Today, 18:04
if ($timestamp > $midnight + 86400 || $timestamp > $midnight - 86400)
{
if ($timestamp > $midnight + 86400)
{
$day = 'Tomorrow';
}
else if ($timestamp > $midnight)
{
$day = 'Today';
}
else if ($timestamp > $midnight - 86400)
{
$day = 'Yesterday';
}
return str_replace('||', $l10n[$day], strtr(gmdate($date['format_short'], $timestamp + $zone_offset), $l10n)); }
}
return strtr(gmdate($date['format_long'], $timestamp + $zone_offset), $l10n); }
switch ($dbms)
{
case 'mysql':
case 'mysqli':
case 'postgres':
$dsn = ($dbms === 'postgres') ? 'pgsql:' : 'mysql:';
{
$dsn .= "host=$dbhost;";
}
{
$dsn .= "port=$dbport;";
}
{
$dsn .= "dbname=$dbname;";
}
break;
case 'oracle':
$dsn = 'oci:';
{
$dsn .= "dbname=$dbname;";
}
break;
case 'sqlite':
$dsn = 'sqlite2:';
{
$dsn .= $dbhost;
}
{
$dsn .= ":$dbport";
}
break;
}
$pdo = new PDO($dsn, $dbuser, $dbpasswd);
switch ($dbms)
{
case 'mysql':
case 'mysqli':
$pdo->exec('SET NAMES utf8');
break;
}
$sql = "SELECT *
FROM {$table_prefix}config
WHERE config_name = 'board_dst'
OR config_name = 'board_timezone'
OR config_name = 'default_dateformat'
OR config_name = 'script_path'
OR config_name = 'server_name'
OR config_name = 'server_protocol'";
$result = $pdo->query($sql);
// Make configuration array
while ($row = $result->fetch())
{
$config[$row['config_name']] = $row['config_value'];
}
// Create basic forum path
$path = $config['server_protocol'] . $config['server_name'] . $config['script_path'];
// Add "/" at the end of path if missing
if (substr($path, -1) !== '/') {
$path .= '/';
}
$sql = "SELECT topic_id, forum_id, topic_title, topic_last_poster_id, topic_last_poster_name, topic_last_poster_colour, topic_last_post_time
FROM {$table_prefix}topics
WHERE topic_approved = 1
ORDER BY topic_last_post_time DESC
LIMIT $limit";
$result = $pdo->query($sql);
foreach ($result as $row)
{
// @todo Make this code more readable
echo '<a href="', $path, 'viewtopic.php?f=', $row['forum_id'], '&t=', $row['topic_id'], '" title="', $row['topic_title'], '">', mb_strimwidth
($row['topic_title'], 0
, $length, '…', 'UTF-8'), '</a>'; echo ' przez <a href="', $path, 'memberlist.php?mode=viewprofile&u=', $row['topic_last_poster_id'], '"';
if (!empty($row['topic_last_poster_colour'])) {
echo 'style="font-weight: bold; color: ', $row['topic_last_poster_colour'], '"'; }
echo '>', $row['topic_last_poster_name'], '</a> – ', format_date
($config['default_dateformat'], $row['topic_last_post_time'], $config['board_timezone'], $config['board_dst']); }
$result->closeCursor();
?>
Ten post edytował rothejro 12.02.2012, 02:51:03