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


  1. <?php
  2.  
  3. $dbms = 'mysql';
  4. $dbhost = 'sql.bla bla';
  5. $dbport = '3307';
  6. $dbname = 'nazwa';
  7. $dbuser = 'nazwa';
  8. $dbpasswd = 'hasło';
  9. $table_prefix = '';
  10.  
  11. $limit = 10; // Topics limit
  12. $length = 30; // Title length limit (in characters)
  13.  
  14. // Set an exception handler
  15. set_exception_handler('handle_exception');
  16.  
  17. if (version_compare(PHP_VERSION, '5.0.0', '<'))
  18. {
  19. throw new Exception('Wymagane PHP 5 lub nowsze!');
  20. }
  21.  
  22. if (!class_exists('PDO'))
  23. {
  24. throw new Exception('Wymagane rozszerzenie PHP Data Objects (PDO)!');
  25. }
  26.  
  27. /**
  28.  * @param object $exception
  29.  * @return string
  30.  */
  31. function handle_exception($exception)
  32. {
  33. echo $exception->getMessage();
  34. }
  35.  
  36. /**
  37.  * @param string $format
  38.  * @param int $timestamp
  39.  * @param int $timezone
  40.  * @param bool $dst
  41.  * @return string
  42.  */
  43. function format_date($format, $timestamp, $timezone, $dst)
  44. {
  45. $l10n = array(
  46. 'Tomorrow' => 'jutro',
  47. 'Today' => 'dzisiaj',
  48. 'Yesterday' => 'wczoraj',
  49. 'Ago' => array(
  50. 0 => 'niecałą minutę temu',
  51. 1 => '%d min temu',
  52. 2 => '%d min temu',
  53. 60 => '1 godzinę temu'
  54. ),
  55.  
  56. 'Monday' => 'poniedziałek',
  57. 'Tuesday' => 'wtorek',
  58. 'Wednesday' => 'środa',
  59. 'Thursday' => 'czwartek',
  60. 'Friday' => 'piątek',
  61. 'Saturday' => 'sobota',
  62. 'Sunday' => 'niedziela',
  63.  
  64. 'Mon' => 'pn',
  65. 'Tue' => 'wt',
  66. 'Wed' => 'śr',
  67. 'Thu' => 'czw',
  68. 'Fri' => 'pt',
  69. 'Sat' => 'sob',
  70. 'Sun' => 'ndz',
  71.  
  72. 'January' => 'stycznia',
  73. 'February' => 'lutego',
  74. 'March' => 'marca',
  75. 'April' => 'kwietnia',
  76. 'May' => 'maja',
  77. 'June' => 'czerwca',
  78. 'July' => 'lipca',
  79. 'August' => 'sierpnia',
  80. 'September' => 'września',
  81. 'October' => 'października',
  82. 'November' => 'listopada',
  83. 'December' => 'grudnia',
  84.  
  85. 'Jan' => 'sty',
  86. 'Feb' => 'lut',
  87. 'Mar' => 'mar',
  88. 'Apr' => 'kwie',
  89. 'May_short' => 'maja',
  90. 'Jun' => 'cze',
  91. 'Jul' => 'lip',
  92. 'Aug' => 'sie',
  93. 'Sep' => 'wrz',
  94. 'Oct' => 'paź',
  95. 'Nov' => 'lis',
  96. 'Dec' => 'gru',
  97. );
  98.  
  99. $zone_offset = $timezone * 3600 + $dst * 3600;
  100. $midnight = gmmktime(0, 0, 0) - $zone_offset;
  101. $delta = time() - $timestamp;
  102.  
  103. $date = array(
  104. 'is_short' => strpos($format, '|'),
  105. 'format_short' => substr($format, 0, strpos($format, '|')) . '||' . substr(strrchr($format, '|'), 1),
  106. 'format_long' => str_replace('|', '', $format)
  107. );
  108.  
  109. // Some languages use different terms for the long and short format of May
  110. if ((strpos($format, '\M') === false && strpos($format, 'M') !== false) || (strpos($format, '\r') === false && strpos($format, 'r') !== false))
  111. {
  112. $l10n['May'] = $l10n['May_short'];
  113. }
  114.  
  115. if ($date['is_short'] !== false)
  116. {
  117. // Relative dates in minutes and hours, e.g. 5 minutes ago
  118. if ($delta < 60)
  119. {
  120. return $l10n['Ago'][0];
  121. }
  122. else if ($delta < 120)
  123. {
  124. return sprintf($l10n['Ago'][1], floor($delta / 60));
  125. }
  126. else if ($delta < 3600 )
  127. {
  128. return sprintf($l10n['Ago'][2], floor($delta / 60));
  129. }
  130. else if ($delta < 7200 )
  131. {
  132. return sprintf($l10n['Ago'][60], floor($delta / 3600));
  133. }
  134.  
  135. // Relative dates in days, e.g. Today, 18:04
  136. if ($timestamp > $midnight + 86400 || $timestamp > $midnight - 86400)
  137. {
  138. if ($timestamp > $midnight + 86400)
  139. {
  140. $day = 'Tomorrow';
  141. }
  142. else if ($timestamp > $midnight)
  143. {
  144. $day = 'Today';
  145. }
  146. else if ($timestamp > $midnight - 86400)
  147. {
  148. $day = 'Yesterday';
  149. }
  150.  
  151. return str_replace('||', $l10n[$day], strtr(gmdate($date['format_short'], $timestamp + $zone_offset), $l10n));
  152. }
  153. }
  154.  
  155. return strtr(gmdate($date['format_long'], $timestamp + $zone_offset), $l10n);
  156. }
  157.  
  158. switch ($dbms)
  159. {
  160. case 'mysql':
  161. case 'mysqli':
  162. case 'postgres':
  163. $dsn = ($dbms === 'postgres') ? 'pgsql:' : 'mysql:';
  164.  
  165. if (!empty($dbhost))
  166. {
  167. $dsn .= "host=$dbhost;";
  168. }
  169.  
  170. if (!empty($dbport))
  171. {
  172. $dsn .= "port=$dbport;";
  173. }
  174.  
  175. if (!empty($dbname))
  176. {
  177. $dsn .= "dbname=$dbname;";
  178. }
  179. break;
  180.  
  181. case 'oracle':
  182. $dsn = 'oci:';
  183.  
  184. if (!empty($dbname))
  185. {
  186. $dsn .= "dbname=$dbname;";
  187. }
  188. break;
  189.  
  190. case 'sqlite':
  191. $dsn = 'sqlite2:';
  192.  
  193. if (!empty($dbhost))
  194. {
  195. $dsn .= $dbhost;
  196. }
  197.  
  198. if (!empty($dbport))
  199. {
  200. $dsn .= ":$dbport";
  201. }
  202. break;
  203. }
  204.  
  205. $pdo = new PDO($dsn, $dbuser, $dbpasswd);
  206.  
  207. switch ($dbms)
  208. {
  209. case 'mysql':
  210. case 'mysqli':
  211. $pdo->exec('SET NAMES utf8');
  212. break;
  213. }
  214.  
  215. $sql = "SELECT *
  216. FROM {$table_prefix}config
  217. WHERE config_name = 'board_dst'
  218. OR config_name = 'board_timezone'
  219. OR config_name = 'default_dateformat'
  220. OR config_name = 'script_path'
  221. OR config_name = 'server_name'
  222. OR config_name = 'server_protocol'";
  223.  
  224. $result = $pdo->query($sql);
  225.  
  226. // Make configuration array
  227. while ($row = $result->fetch())
  228. {
  229. $config[$row['config_name']] = $row['config_value'];
  230. }
  231.  
  232. // Create basic forum path
  233. $path = $config['server_protocol'] . $config['server_name'] . $config['script_path'];
  234.  
  235. // Add "/" at the end of path if missing
  236. if (substr($path, -1) !== '/')
  237. {
  238. $path .= '/';
  239. }
  240.  
  241. $sql = "SELECT topic_id, forum_id, topic_title, topic_last_poster_id, topic_last_poster_name, topic_last_poster_colour, topic_last_post_time
  242. FROM {$table_prefix}topics
  243. WHERE topic_approved = 1
  244. ORDER BY topic_last_post_time DESC
  245. LIMIT $limit";
  246.  
  247. $result = $pdo->query($sql);
  248.  
  249. echo '<ul>';
  250.  
  251. foreach ($result as $row)
  252. {
  253. // @todo Make this code more readable
  254. echo '<li>';
  255. 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>';
  256. echo ' przez <a href="', $path, 'memberlist.php?mode=viewprofile&u=', $row['topic_last_poster_id'], '"';
  257.  
  258. if (!empty($row['topic_last_poster_colour']))
  259. {
  260. echo 'style="font-weight: bold; color: ', $row['topic_last_poster_colour'], '"';
  261. }
  262.  
  263. echo '>', $row['topic_last_poster_name'], '</a> – ', format_date($config['default_dateformat'], $row['topic_last_post_time'], $config['board_timezone'], $config['board_dst']);
  264. echo '</li>';
  265. }
  266.  
  267. echo '</ul>';
  268.  
  269. $result->closeCursor();
  270.  
  271. ?>