Index: aetherlibs/DB.php =================================================================== --- /dev/null +++ aetherlibs/DB.php @@ -0,0 +1,40 @@ +. + */ + +$path = '/srv/www/capacity-auth'; +set_include_path(get_include_path() . PATH_SEPARATOR . $path . PATH_SEPARATOR . "media/"); +require_once('db_auth.inc'); + +// set the default timezone to use. Available since PHP 5.1 +date_default_timezone_set('Europe/Berlin'); + +/** + * Interface to the database + * @extends PDO + */ +class DB extends PDO { + + public function __construct() + { + global $db_username; + global $db_password; + global $db_database; + + parent::__construct('mysql:host=localhost;dbname=' . $db_database, $db_username, $db_password); + } +} Index: aetherlibs/feeds.php =================================================================== --- aetherlibs/feeds.php +++ aetherlibs/feeds.php @@ -1,78 +1,100 @@ - * - * @author Ken Vermette - * @copyright 2017 Ken Vermette - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE - * License as published by the Free Software Foundation; either - * version 3 of the License, or any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU AFFERO GENERAL PUBLIC LICENSE for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - */ +/** +* News Lib +* +* @author Frank Karlitschek +* @copyright 2010 Frank Karlitschek karlitschek@kde.org +* +* @modifications Added default image fallback +* Improve code readability +* @author Sayak Banerjee +* @copyright 2010 Sayak Banerjee +* +* @author Ken Vermette +* @copyright 2017 Ken Vermette +* @copyright 2019 Carl Schwan +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library. If not, see . +* +*/ +/** + * Extract feeds from database + */ +class Feeds +{ + /** + * @params int $count Number of news that need to be fetched + * @return array an array of news + */ + static function news(int $count): array + { + $output = []; + $db = new DB(); + $stmt = $db->prepare('SELECT title, url, timestamp FROM news ORDER BY timestamp DESC LIMIT :count'); + $stmt->execute(['count' => $count]); + while ($row = $stmt->fetch()) { + $output[] = [ + 'title' => $row['title'], + 'time' => $row['timestamp'], + 'url' => $row['url'], + 'source' => 'news', + 'user' => 'KDE Community', + ]; + } + return $output; + } -class Feeds -{ - static function news ($count) - { - $output = []; - $request = DB::query('SELECT title, url, timestamp FROM news ORDER BY timestamp DESC LIMIT '.$count); - $num = DB::numrows($request); - - for($x = 0; $x < $num; $x++) { - $data = DB::fetch_assoc($request); - $output[] = [ - 'title' => $data['title'], - 'time' => $data['timestamp'], - 'url' => $data['url'], - 'source' => 'news', - 'user' => 'KDE Community', - ]; - } - - DB::free_result($request); - return $output; - } - - - static function blog($count) - { - $output = []; - $request = DB::query('SELECT user, title, url, timestamp FROM blog ORDER BY timestamp DESC LIMIT ' . $count); - $num = DB::numrows($request); - - for($x = 0; $x < $num; $x++) { - $data = DB::fetch_assoc($request); - $output[] = [ - 'title' => $data['title'], - 'time' => $data['timestamp'], - 'url' => $data['url'], - 'source' => 'blog', - 'user' => $data['user'] - ]; - } - - DB::free_result($request); - return $output; - } + + /** + * @params int $count Number of blog posts that need to be fetched + * @return array an array of blog posts + */ + static function blog(int $count): array + { + $output = []; + $db = new DB(); + $stmt = $db->prepare('SELECT title, url, timestamp FROM blog ORDER BY timestamp DESC LIMIT :count'); + $stmt->execute(['count' => $count]); + + while ($row = $stmt->fetch()) { + $output[] = [ + 'title' => $row['title'], + 'time' => $row['timestamp'], + 'url' => $row['url'], + 'source' => 'blog', + 'user' => $row['user'], + ]; + } + return $output; + } + + static function planet(int $count): array + { + $feed = simplexml_load_file('https://planet.kde.org/rss20.xml'); + $output = []; + if ($feed) { + for($i = 0 ; $i <= $count ; $i++) { + $item = $feed->channel->item[$i]; + $output[] = [ + 'title' => (string) $item->title, + 'url' => (string) $item->link, + ]; + } + } + return $output; + } } Index: index.php =================================================================== --- index.php +++ index.php @@ -8,11 +8,8 @@ require('aether/header.php'); - if (@include_once("libs/class_db.php")) { + if (@include_once("aetherlibs/DB.php")) { define("FRONTPAGE_LIVE_FEED", true); - } - - if (defined("FRONTPAGE_LIVE_FEED")) { require_once('users_conf.php'); require_once('aetherlibs/functions.php'); require_once("aetherlibs/feeds.php"); @@ -182,26 +179,18 @@

Community Blog Posts

- - '; - for( $i= 0 ; $i <= 3 ; $i++ ) { - $item = $feed->channel->item[$i]; - $title = (string) $item->title; - $url = (string) $item->link; - - printf( - '
  • %s
  • ', - $url, - $title - ); - }; - print ''; - } - ?> +
      + %s', + htmlspecialchars($item['url']), + htmlspecialchars($item['title']) + ); + } + ?> +
    🌍 Read our blogs on Planet KDE