Index: aetherlibs/DB.php =================================================================== --- /dev/null +++ aetherlibs/DB.php @@ -0,0 +1,38 @@ +. + */ + +require_once('db_auth.inc'); + +// Set the default timezone to use. +date_default_timezone_set('UTC'); + +/** + * Interface to the database + * @extends PDO + */ +class DB extends PDO { + + public function __construct() + { + // This global variables are imported from db_auth.inc + 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,109 @@ - * - * @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 = []; + try { + $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', + ]; + } + } catch (PDOException $e) { + print "Error!: " . $e->getMessage() . "
"; + } + 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 + * @deprecated + */ + static function blog(int $count): array + { + $output = []; + try { + $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'], + ]; + } + } catch (PDOException $e) { + print "Error!: " . $e->getMessage() . "
"; + } + 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: fundraisers/yearend2017/config.php.dist =================================================================== --- fundraisers/yearend2017/config.php.dist +++ fundraisers/yearend2017/config.php.dist @@ -5,6 +5,11 @@ $dbuser = 'root'; $dbpass = 'root'; $dbname = 'endofyear'; -$dbConnection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname) or die (mysqli_connect_error()); +try { + $dbConnection = new PDO('mysql:host=' . $dbhost . ';dbname=' . $dbname, $dbuser, $dbpass); +} catch (PDOException $e) { + print "Error!: " . $e->getMessage() . "
"; + die(); +} ?> Index: fundraisers/yearend2017/index.php =================================================================== --- fundraisers/yearend2017/index.php +++ fundraisers/yearend2017/index.php @@ -88,17 +88,15 @@ prepare("SELECT *, UNIX_TIMESTAMP(CREATED_AT) AS date_t FROM endofyear2017donations ORDER BY CREATED_AT DESC;") or die($dbConnection->error); - $stmt->execute(); - $result = $stmt->get_result(); - $stmt->close(); - $count = $result->num_rows; - ?> - prepare("SELECT COUNT(*) FROM endofyear2017donations ORDER BY CREATED_AT DESC;"); + $countStmt->execute(); + $n = $countStmt->fetchColumn(); + + $res = $dbConnection->prepare("SELECT *, UNIX_TIMESTAMP(CREATED_AT) AS date_t FROM endofyear2017donations ORDER BY CREATED_AT DESC;"); + $res->execute(); $total = 0; - $n = $count; $table = ""; - while ($row = mysqli_fetch_array($result)) { + while ($row = $res->fetch()) { $name = htmlspecialchars($row["donor_name"]); if ($name == "") { $name = "Anonymous donation"; @@ -113,8 +111,7 @@ $table.=""; $n--; } - $table.=""; - mysqli_close($dbConnection); + $dbConnection = null; $goal_fmt=number_format(20000); $goal=20000; $percent=round($total * 100 / $goal); 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"); @@ -155,7 +152,7 @@

News

-
    +

      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