Index: aetherlibs/feeds.php =================================================================== --- aetherlibs/feeds.php +++ aetherlibs/feeds.php @@ -1,78 +1,130 @@ - * - * @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 . +* +*/ +require_once __DIR__.'/../vendor/autoload.php'; +use Symfony\Contracts\Cache\ItemInterface; +use Symfony\Component\Cache\Adapter\FilesystemAdapter; -class Feeds +/** + * Extract feeds from database + */ +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; - } + private $db; + + /** + * @params PDO $db Database connection + */ + public function __construct(PDO $db) + { + $this->db = $db; + } + + /** + * @params int $count Number of news that need to be fetched + * @return array an array of news + */ + function news(int $count): array + { + $output = []; + try { + $stmt = $this->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; + } + + + /** + * @params int $count Number of blog posts that need to be fetched + * @return array an array of blog posts + * @deprecated + */ + function blog(int $count): array + { + $output = []; + try { + $db = new DB(); + $stmt = $this->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 + { + $cache = new FilesystemAdapter(); + $output = $cache->get('feedrss', function (ItemInterface $item) use ($count) { + $item->expiresAfter(3600); + + $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; + }); + return $output; + } } Index: community/donations/graph.php =================================================================== --- community/donations/graph.php +++ community/donations/graph.php @@ -1,8 +1,8 @@ 2020) { echo "year check failed"; exit(1); @@ -13,86 +13,52 @@ $i < 10 ? $i_s = "0".$i : $i_s = $i; $data[ $year."-".$i_s ] = 0; } +// $dbConnection->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );//Error Handling -$query = "select sum(amount) as don, DATE_FORMAT(date,\"%Y-%m\") as month from donations "; -$query .= "where year(date) = '".$year."' "; -$query .= "group by month order by month desc"; -$q = mysql_query($query,$sq); -while ($row = mysql_fetch_array($q)) { - $data[ $row["month"] ] = $row["don"]; -} - -$keys = array_keys($data); -$values = array_values($data); - -// below is taken from http://code.web-max.ca/image_graph.php -// and adapted a bit. - -// Get the total number of columns we are going to plot - - $columns = count($values); - -// Get the height and width of the final image - - $width = 400; - $height = 200; - -// Set the amount of space between each column - - $padding = 5; - -// Get the width of 1 column - - $column_width = $width / $columns ; - -// Generate the image variables - - $im = imagecreate($width,$height); - $gray = imagecolorallocate ($im,0xcc,0xcc,0xcc); - $gray_lite = imagecolorallocate ($im,0xee,0xee,0xee); - $gray_dark = imagecolorallocate ($im,0x7f,0x7f,0x7f); - $white = imagecolorallocate ($im,0xff,0xff,0xff); - - $blue_lite = imagecolorallocate($im, 0xE7, 0xF8, 0xFF); - $blue_dark = imagecolorallocate($im, 0x4A, 0x81, 0xCA); - $black = imagecolorallocate($im, 0x00, 0x00, 0x00); - -// Fill in the background of the image +$stmt = $dbConnection->prepare("SELECT SUM(amount) as don, DATE_FORMAT(date,\"%Y-%m\") as month from donations WHERE YEAR(date) = :year GROUP BY month ORDER BY month DESC"); - imagefilledrectangle($im,0,0,$width,$height,$white); - - $maxv = 0; +$stmt->execute([ + 'year' => $year, +]); -// Calculate the maximum value we are going to plot - - for($i=0;$i<$columns;$i++)$maxv = max($values[$i],$maxv); - -// Now plot each column - - $font_file = '/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf'; - for($i=0;$i<$columns;$i++) - { - $column_height = ($height / 100) * (( $values[$i] / $maxv) *100); - - $x1 = $i*$column_width; - $y1 = $height-$column_height; - $x2 = (($i+1)*$column_width)-$padding; - $y2 = $height; - - imagefilledrectangle($im,$x1,$y1,$x2,$y2,$blue_dark); - -// This part is just for 3D effect - - imageline($im,$x1,$y1,$x1,$y2,$gray_lite); - imageline($im,$x1,$y2,$x2,$y2,$gray_lite); - imageline($im,$x2,$y1,$x2,$y2,$gray_dark); - - imagefttext( $im, 9, 0, $x1+8, $y2-5 , $black, $font_file, $i+1); +while ($row = $stmt->fetch()) { + $data[ $row["month"] ] = $row["don"]; +} +?> + + + + + + + +
+ + + +
+ + Index: community/donations/notify.php =================================================================== --- community/donations/notify.php +++ community/donations/notify.php @@ -1,6 +1,7 @@ prepare("REPLACE into donations VALUES( NULL, :date, :payment_amount, :memo, :txn_id, :donate_url)"); + $stmt->execute([ + 'date' => $date, + 'payment_amount' => $payment_amount, + 'memo' => addslashes($memo), + 'txn_id' => $txn_id, + 'donate_url' => addslashes($donate_url), + ]); + if ($do_debug) { - fwrite( $debug, "\nQuery:".$query."\n" ); - fwrite( $debug, "Error:".mysql_error()."\n" ); + error_log("\nQuery:".$stmt->debugDumpParams()."\n" ); + fwrite( $debug, "\nQuery:".$stmt->debugDumpParams()."\n" ); } -} else if (strcmp ($res, "INVALID") == 0) { +} else if (strcmp ($res, "INVALID") === 0) { if ($do_debug) { fwrite($debug, "Invalid transaction\n"); } Index: community/donations/previousdonations.php =================================================================== --- community/donations/previousdonations.php +++ community/donations/previousdonations.php @@ -28,29 +28,33 @@ prepare("SELECT *, UNIX_TIMESTAMP(date) AS date_t FROM donations WHERE date >= ':year-:month_s-01' AND date <= ':year-:month_s-31 23:59:59' ORDER BY date DESC;"); +$count = $dbConnection->prepare("SELECT COUNT(*) WHERE date >= ':year-:month_s-01' AND date <= ':year-:month_s-31 23:59:59';"); for ($year = date("Y", time()); $year > 2001; $year--) { echo "

$year

"; - echo "
"; + echo "
"; echo ""; echo "
"; echo "

"; for ($month = 12; $month >=1 ; $month--) { - $month < 10 ? $month_s = "0".$month : $month_s = $month; - $query = "select *,unix_timestamp(date) as date_t from donations "; - $query .= "where date >= '".$year."-".$month_s."-01' and "; - $query .= "date <= '".$year."-".$month_s."-31 23:59:59' order by date desc"; - # echo "
".$query."

"; - $q = mysql_query($query,$sq); - echo mysql_error(); - if (mysql_num_rows($q) == 0) { - continue; - } + # echo "
".$query."

"; + $count->execute([ + 'year' => $year, + 'month_s' => $month_s, + ]); + if ($count->fetchColumn() === 0) { + continue; + } + $q = $query->execute([ + 'year' => $year, + 'month_s' => $month_s, + ]); $total = 0; echo ""; echo ""; echo ""; - while ($row = mysql_fetch_array($q)) { + while ($row = $q->fetch()) { $msg = htmlentities($row["message"]); if ($msg == "") { $msg = "Anonymous donation"; Index: fundraisers/kdesprints2015/index.php =================================================================== --- fundraisers/kdesprints2015/index.php +++ fundraisers/kdesprints2015/index.php @@ -20,14 +20,13 @@ require("donations_auth.inc"); - $query = "select *,unix_timestamp(date) as date_t from randameetings2015donations order by date desc;"; - $q = mysql_query($query,$sq); - echo mysql_error(); + $res = $db->prepare("SELECT *, UNIX_TIMESTAMP(date) AS date_t FROM randameetings2015donations ORDER BY date DESC;"); + $res->execute(); $total = 0; $count = 0; $table = "
".date("Y - F", mktime(0,0,0,$month,1,$year))."
DateAmountMessage
"; $table.=""; - while ($row = mysql_fetch_array($q)) { + while ($row = $res->fetch()) { $msg = htmlspecialchars($row["message"]); if ($msg == "") { $msg = "Anonymous donation"; @@ -55,16 +54,16 @@

KDE Sprints 2015 fundraising

- + --> */ ?> €$total raised of a €$goal goal

"; echo "
"; echo "
" -?> - + -->*/ +?> The Randa Meetings 2015 Fundraiser has finished. Thank you everybody who supported us in this fundraiser. We didn't reach the set goal but we collected quite some money and that means there will be more KDE Sprints thanks to your support! See http://planet.kde.org for more information to come and go to the KDE donation page if you want to support us further. Index: fundraisers/kdesprints2015/notify.php =================================================================== --- fundraisers/kdesprints2015/notify.php +++ fundraisers/kdesprints2015/notify.php @@ -1,5 +1,7 @@ prepare("SELECT *, UNIX_TIMESTAMP(date) AS date_t FROM randameetings2014donations ORDER BY date DESC;"); + $res->execute(); $query = "select *,unix_timestamp(date) as date_t from randameetings2014donations order by date desc;"; - $q = mysql_query($query,$sq); - echo mysql_error(); $total = 0; $count = 0; $table = "
No.DateAmountDonor Name
"; $table.=""; - while ($row = mysql_fetch_array($q)) { + while ($row = $res->fetch()) { $msg = htmlspecialchars($row["message"]); if ($msg == "") { $msg = "Anonymous donation"; @@ -55,16 +55,15 @@

Randa Meetings 2014 fundraising

- +--> */ ?> €$total raised of a €$goal goal

"; echo "
"; echo "
" -?> - +--> */ ?> The Randa Meetings 2014 Fundraiser has finished. Thank you everybody who supported us in this fundraiser. We didn't reach the set goal but we collected quite some money and that means there is going to be Randa Meetings in August 2014. See http://planet.kde.org for more information to come and go to the KDE donation page if you want to support us further. Index: fundraisers/randameetings2014/notify.php =================================================================== --- fundraisers/randameetings2014/notify.php +++ fundraisers/randameetings2014/notify.php @@ -2,6 +2,8 @@ $do_debug = true; +die("Donation to the Randa Meeting 2014 are not supported anymore. See Donnations"); + // STEP 1: read POST data // Reading POSTed data directly from $_POST causes serialization issues with array data in the POST. Index: fundraisers/randameetings2016/index.php =================================================================== --- fundraisers/randameetings2016/index.php +++ fundraisers/randameetings2016/index.php @@ -30,13 +30,12 @@ require("donations_auth.inc"); - $query = "select *,unix_timestamp(date) as date_t from randameetings2016donations order by date desc;"; - $q = mysql_query($query,$sq); - echo mysql_error(); + $res = $db->prepare("SELECT *, UNIX_TIMESTAMP(date) AS date_t FROM randameetings2016donations ORDER BY date DESC;"); + $res->execute(); $total = 0; $count = 0; $table = ""; - while ($row = mysql_fetch_array($q)) { + while ($row = $res->fetch()) { $msg = htmlspecialchars($row["message"]); if ($msg == "") { $msg = "Anonymous donation"; @@ -164,7 +163,7 @@ "; ?> - + */ ?> Index: fundraisers/randameetings2016/notify.php =================================================================== --- fundraisers/randameetings2016/notify.php +++ fundraisers/randameetings2016/notify.php @@ -1,6 +1,7 @@ Donnations"); // STEP 1: read POST data Index: fundraisers/randameetings2016/stats.php =================================================================== --- fundraisers/randameetings2016/stats.php +++ fundraisers/randameetings2016/stats.php @@ -225,18 +225,17 @@ require("donations_auth.inc"); - $query = "select sum(amount) as amount_sum, count(*) donations, DATE_FORMAT(date, '%m%d') as date_fmt from randameetings2016donations group by DATE_FORMAT(date, '%m%d') ORDER BY DATE_FORMAT(date, '%m%d');"; - $q = mysql_query($query,$sq); - echo mysql_error(); + $stmt = $dbConnection->prepare("select sum(amount) as amount_sum, count(*) donations, DATE_FORMAT(date, '%m%d') as date_fmt from randameetings2016donations group by DATE_FORMAT(date, '%m%d') ORDER BY DATE_FORMAT(date, '%m%d');"); + $stmt->execute(); $labels2016 = ""; $values2016 = ""; $cumulativeAmount2016 = ""; $cumulativeAmount2016Value = 0; $cumulativeDonations2016 = ""; $cumulativeDonations2016Value = 0; $donations2016 = ""; $count = 1; - while ($row = mysql_fetch_array($q)) { + while ($row = $stmt->fetch()) { //$labels2016.=", ".$row["date_fmt"]; $labels2016.=", ".$count; $count++; @@ -253,18 +252,17 @@ $cumulativeDonations2016.=""; $donations2016.=""; - $query = "select sum(amount) as amount_sum, count(*) donations, DATE_FORMAT(date, '%m%d') as date_fmt from randameetings2015donations group by DATE_FORMAT(date, '%m%d') ORDER BY DATE_FORMAT(date, '%m%d');"; - $q = mysql_query($query,$sq); - echo mysql_error(); + $stmt = $dbConnection->prepare("select sum(amount) as amount_sum, count(*) donations, DATE_FORMAT(date, '%m%d') as date_fmt from randameetings2015donations group by DATE_FORMAT(date, '%m%d') ORDER BY DATE_FORMAT(date, '%m%d');"); + $stmt->execute(); $labels2015 = ""; $values2015 = ""; $cumulativeAmount2015 = ""; $cumulativeAmount2015Value = 0; $cumulativeDonations2015 = ""; $cumulativeDonations2015Value = 0; $donations2015 = ""; $count = 1; - while ($row = mysql_fetch_array($q)) { + while ($row = $stmt->fetch()) { //$labels2015.=", ".$row["date_fmt"]; $labels2015.=", ".$count; $count++; Index: fundraisers/randameetings2017/index.php =================================================================== --- fundraisers/randameetings2017/index.php +++ fundraisers/randameetings2017/index.php @@ -30,15 +30,17 @@ require_once("config.php"); - $stmt = $dbConnection->prepare("SELECT *, UNIX_TIMESTAMP(CREATED_AT) AS date_t FROM randameetings2017donations ORDER BY CREATED_AT DESC;") or die ($dbConnection->error); - $stmt->execute(); - $result = $stmt->get_result(); - $stmt->close(); + $countStmt = $dbConnection->prepare("SELECT COUNT(*) FROM randameetings2017donations ORDER BY CREATED_AT DESC;"); + $countStmt->execute(); + $n = $countStmt->fetchColumn(); + + $res = $dbConnection->prepare("SELECT *, UNIX_TIMESTAMP(CREATED_AT) AS date_t FROM randameetings2017donations ORDER BY CREATED_AT DESC;"); + $res->execute(); $total = 0; - $count = $result->num_rows; + $count = $n; $n = $count; $table = ""; - while ($row = mysqli_fetch_array($result)) { + while ($row = $res->fetch()) { $name = htmlspecialchars($row["donor_name"]); if ($name == "") $name = "Anonymous donation"; @@ -53,7 +55,7 @@ $n--; } $table.=""; - mysqli_close($dbConnection); + $dbConnection = null; $percent=round($total * 100 / $goal); $percent=min($percent, 100); $graph_style = "width: 100%; height: 30px; border: 1px solid #888; background: rgb(204,204,204); Index: fundraisers/randameetings2017/notify.php =================================================================== --- fundraisers/randameetings2017/notify.php +++ fundraisers/randameetings2017/notify.php @@ -1,6 +1,7 @@ Donnations"); require('paypalIPN.php'); Index: fundraisers/randameetings2017/stats.php =================================================================== --- fundraisers/randameetings2017/stats.php +++ fundraisers/randameetings2017/stats.php @@ -223,10 +223,8 @@ $daystogo=floor((strtotime($enddate)-time())/(60*60*24)); require("config.php"); - $stmt = $dbConnection->prepare("SELECT SUM(amount) AS amount_sum, count(*) donations, DATE_FORMAT(CREATED_AT, '%m%d') AS date_fmt FROM randameetings2017donations ORDER BY DATE_FORMAT(CREATED_AT, '%m%d');") or die ($dbConnection->error); + $stmt = $dbConnection->prepare("SELECT SUM(amount) AS amount_sum, count(*) donations, DATE_FORMAT(CREATED_AT, '%m%d') AS date_fmt FROM randameetings2017donations ORDER BY DATE_FORMAT(CREATED_AT, '%m%d');"); $stmt->execute(); - $result = $stmt->get_result(); - $stmt->close(); $labels2017 = ""; $values2017 = ""; @@ -236,7 +234,7 @@ $cumulativeDonations2017Value = 0; $donations2017 = ""; $count = 1; - while ($row = mysqli_fetch_array($result)) { + while ($row = $stmt->fetch()) { //$labels2017.=", ".$row["date_fmt"]; $labels2017.=", ".$count; $count++; @@ -255,8 +253,6 @@ $stmt = $dbConnection->prepare("SELECT SUM(amount) AS amount_sum, count(*) donations, DATE_FORMAT(date, '%m%d') AS date_fmt FROM randameetings2016donations ORDER BY DATE_FORMAT(date, '%m%d');") or die ($dbConnection->error); $stmt->execute(); - $result = $stmt->get_result(); - $stmt->close(); $labels2016 = ""; $values2016 = ""; @@ -266,7 +262,7 @@ $cumulativeDonations2016Value = 0; $donations2016 = ""; $count = 1; - while ($row = mysqli_fetch_array($result)) { + while ($row = $stmt->fetch()) { //$labels2016.=", ".$row["date_fmt"]; $labels2016.=", ".$count; $count++; Index: fundraisers/yearend2014/index.php =================================================================== --- fundraisers/yearend2014/index.php +++ fundraisers/yearend2014/index.php @@ -20,19 +20,16 @@ require("donations_auth.inc"); - $query = "select count(*) from yearend2014donations;"; - $q = mysql_query($query,$sq); - echo mysql_error(); - $row = mysql_fetch_array($q); - $index = $row[0]; - - $query = "select *,unix_timestamp(date) as date_t from yearend2014donations order by date desc;"; - $q = mysql_query($query,$sq); - echo mysql_error(); + $countStmt = $dbConnection->prepare("SELECT COUNT(*) FROM yearend2014donations ORDER BY CREATED_AT DESC;"); + $countStmt->execute(); + $n = $countStmt->fetchColumn(); + + $res = $dbConnection->prepare("SELECT *, UNIX_TIMESTAMP(CREATED_AT) AS date_t FROM yearend2014donations ORDER BY CREATED_AT DESC;"); + $res->execute(); $total = 0; $table = "
No.DateAmountDonor Name
"; $table.=""; - while ($row = mysql_fetch_array($q)) { + while ($row = $res->fetch()) { $msg = htmlspecialchars($row["message"]); if ($msg == "") { $msg = "".i18n_var("Anonymous donation").""; Index: fundraisers/yearend2016/index.php =================================================================== --- fundraisers/yearend2016/index.php +++ fundraisers/yearend2016/index.php @@ -18,19 +18,17 @@ require("donations_auth.inc"); + $countStmt = $dbConnection->prepare("SELECT COUNT(*) FROM yearend2016donations ORDER BY CREATED_AT DESC;"); + $countStmt->execute(); + $n = $countStmt->fetchColumn(); + + $res = $dbConnection->prepare("SELECT *, UNIX_TIMESTAMP(CREATED_AT) AS date_t FROM yearend2016donations ORDER BY CREATED_AT DESC;"); $query = "select count(*) from yearend2016donations;"; - $q = mysql_query($query,$sq); - echo mysql_error(); - $row = mysql_fetch_array($q); - $index = $row[0]; - - $query = "select *,unix_timestamp(date) as date_t from yearend2016donations order by date desc;"; - $q = mysql_query($query,$sq); - echo mysql_error(); + $total = 0; $table = "
".i18n_var("Date")."".i18n_var("Amount")."".i18n_var("Donor Name")."
"; $table.=""; - while ($row = mysql_fetch_array($q)) { + while ($row = $res->fetch()) { $msg = htmlspecialchars($row["message"]); if ($msg == "") { $msg = "".i18n_var("Anonymous donation").""; @@ -50,27 +48,26 @@ // This is select from select seems mysql specific? $query = "select MIN(sum_amount) from ( select sum(amount) as sum_amount from yearend2016donations group by email order by sum_amount DESC LIMIT 9 ) as tops;"; - $q = mysql_query($query,$sq); - echo mysql_error(); - $limit_amount = mysql_fetch_array($q)[0]; - - $query = "select * from ( select email, sum(amount) as sum_amount from yearend2016donations group by email order by sum_amount ) as tops where sum_amount >= ".$limit_amount." order by sum_amount DESC;"; - $q = mysql_query($query,$sq); - echo mysql_error(); + $limitStmt = $dbConnection->prepare($query); + $limitStmt->execute(); + $limit_amount = $limitStmt->fetchColumn(); + + $query = "select * from ( select email, sum(amount) as sum_amount from yearend2016donations group by email order by sum_amount ) as tops where sum_amount >= :limit_amount order by sum_amount DESC;"; + $q = $dbConnection->prepare($query); + $q->execute(['limit_amount' => $limit_amount]); $top9table = "
".i18n_var("Date")."".i18n_var("Amount")."".i18n_var("Donor Name")."
"; $top9table.=""; $count = 0; $last_amount = -1; $last_was_same_amount = false; - while ($row = mysql_fetch_array($q)) { + $q2 = $dbConnection->prepare('select distinct message as name from yearend2016donations where email=:email'); + while ($row = $q->fetch()) { $amount = $row["sum_amount"]; $email = $row['email']; - $query2 = "select distinct message as name from yearend2016donations where email='".$email."';"; - $q2 = mysql_query($query2,$sq); - echo mysql_error(); + $q2->execute(['email' => $email]); $donation_count = 0; - while ($row2 = mysql_fetch_array($q2)) { + while ($row2 = $q2-fetch()) { $msg = $row2["name"]; $donation_count++; } 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,12 +8,8 @@ require('aether/header.php'); - if (@include_once("libs/class_db.php")) { + if (@include_once("config.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"); } @@ -149,10 +145,11 @@

News

-
    +
      news(20); //$items = array_merge($items, Feeds::blog(8)); svsort($items, 'timestamp'); @@ -176,26 +173,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
Index: setup-db.php =================================================================== --- /dev/null +++ setup-db.php @@ -0,0 +1,69 @@ + + * + * 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 . + */ + +die("You shall not pass!"); + +require_once('config.php'); + +/** + * Create sample dabase for testing purpose + */ +class Fixture +{ + private $db; + + public function __construct(\PDO $db) + { + $this->db = $db; + $this->db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );//Error Handling + $this->generateGlobalDonationTable(); + } + + private function generateGlobalDonationTable() + { + $this->db->exec("CREATE TABLE IF NOT EXISTS donations ( + id INT AUTO_INCREMENT PRIMARY KEY, + date DATETIME, + amount FLOAT(10, 2), + message VARCHAR(255), + transactionid VARCHAR(255) UNIQUE, + donate_url VARCHAR(255) );"); + + $stmt = $this->db->prepare("INSERT into donations VALUES( NULL, :date, :payment_amount, :memo, :txn_id, :donate_url);"); + + + for ($i = 0; $i < 10; $i++) { + $stmt->execute([ + 'date' => (new DateTime())->format('Y-m-d H:i:s'), + 'payment_amount' => $i * 10.5, + 'memo' => "Thanks $i", + 'txn_id' => time() + $i, + 'donate_url' => "test.org/test_donation" + ]); + } + $query = $this->db->query("SELECT * from donations"); + + while ($row = $query->fetch()) { + echo $row['amount']; + } + } +} + +$fixture = new Fixture($dbConnection); +echo "Done";
".i18n_var("Total Amount")."".i18n_var("Donor Name")."