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,9 +1,9 @@ 2020) { +$year = (int)$_GET["year"]; +if ($year < 2001 || $year > 2030) { 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 @@ $value) { - if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) { + if($get_magic_quotes_exists === true && get_magic_quotes_gpc() === 1) { $value = urlencode(stripslashes($value)); } else { $value = urlencode($value); @@ -60,7 +61,7 @@ } curl_close($ch); -if (strcmp ($res, "VERIFIED") == 0) { +if (strcmp ($res, "VERIFIED") === 0) { // assign posted variables to local variables $item_name = $_POST['item_name']; $item_number = $_POST['item_number']; @@ -73,62 +74,56 @@ $payer_email = $_POST['payer_email']; $donate_url = $_POST['custom']; - require("donations_auth.inc"); - - /* - $query = "CREATE TABLE IF NOT EXISTS donations ( id "; - $query .= "INT AUTO_INCREMENT PRIMARY KEY, date DATETIME, "; - $query .= "amount float(10,2), message VARCHAR(255), "; - $query .= "transactionid VARCHAR(255) UNIQUE, donate_url VARCHAR(255) )"; - mysql_query($query,$sq); - echo mysql_error(); - */ + require("www_config.php"); // check the payment_status is Completed - if ( $payment_status != "Completed") { + if ( $payment_status !== "Completed") { if ($do_debug) { fwrite($debug, "Unexpected payment status: ".$payment_status."\n"); } die("Payment status is ".$payment_status); } // check that receiver_email is your Primary PayPal email - if ( $receiver_email != "kde-ev-board@kde.org") { + if ( $receiver_email !== "kde-ev-board@kde.org") { if ($do_debug) { fwrite($debug, "Unexpected receiver email: ".$receiver_email."\n"); } die("Unknown email"); } // check that payment_amount/payment_currency are correct - if ( $payment_currency != "EUR" ) { + if ( $payment_currency !== "EUR" ) { if ($do_debug) { fwrite($debug, "Unexpected payment currency: ".$payment_currency."\n"); } die("Unknown currency used"); } // sanitise date $date = strtotime( $_POST["payment_date"] ); - if ( $date === false ) { + if (!$date) { echo "Date parsing failed, assuming now()"; $date = time(); } $date = date("Y-m-d H:i:s", $date); // process payment - $query = "REPLACE into donations VALUES( '', \"".$date."\""; - $query .= ", ".$payment_amount.", \"".addslashes( $memo )."\""; - $query .= ",\"".$txn_id."\", \"".addslashes( $donate_url )."\" )"; - mysql_query($query, $sq); - + $stmt = $dbConnection->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" ); + 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 @@ -24,33 +24,74 @@
  • KDE Sprints 2015 Fundraising
  • KDE End of Year 2016 Fundraising
  • + 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"); + $stmt->execute([ + 'year' => $year, + ]); + + while ($row = $stmt->fetch()) { + $data[ $row["month"] ] = $row["don"]; + } ?> +
    + +
    + + 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 "
    "; + display_graph($year, $dbConnection); 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."

    "; + $month < 10 ? $month_s = "0".$month : $month_s = $month; + $count->execute([ + 'year' => $year, + 'month_s' => $month_s, + ]); + if ($count->fetchColumn() === 0) { + continue; + } + $query->execute([ + 'year' => $year, + 'month_s' => $month_s, + ]); $total = 0; echo ""; echo ""; echo ""; - while ($row = mysql_fetch_array($q)) { + while ($row = $query->fetch()) { $msg = htmlentities($row["message"]); if ($msg == "") { $msg = "Anonymous donation"; Index: community/donations/statistics/index.php =================================================================== --- community/donations/statistics/index.php +++ community/donations/statistics/index.php @@ -3,12 +3,20 @@ $page_disablekdeevdonatebutton = true; $page_title="Donations Statistics"; - include "header.inc"; - - require("donations_auth.inc"); + require("www_config.php"); + require('../../../aether/config.php'); + $pageConfig = array_merge($pageConfig, [ + 'title' => "Donations Statistics" + ]); + require('../../../aether/header.php'); + $site_root = "../../"; + echo '
    '; function standard_deviation($aValues) { + if (count($aValues) === 0) { + return 0; + } $fMean = array_sum($aValues) / count($aValues); $fVariance = 0.0; foreach ($aValues as $i) @@ -26,6 +34,8 @@ echo "

    Per Month

    "; + $dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + for ($year = date("Y", time()); $year > 2010; $year--) { echo "
    ".date("Y - F", mktime(0,0,0,$month,1,$year))."
    DateAmountMessage
    "; echo ""; @@ -43,23 +53,32 @@ $year_min = INF; $year_all_amounts = array(); + $stmt = $dbConnection->prepare('SELECT amount, UNIX_TIMESTAMP(date) AS date_t FROM donations WHERE date >= :begin AND date <= :end'); + $stmtCount = $dbConnection->prepare('SELECT COUNT(*) FROM donations WHERE date >= :begin AND date <= :end'); + for ($month = 1; $month <= 12 ; $month++) { $month < 10 ? $month_s = "0".$month : $month_s = $month; - $query = "select amount,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'"; - $q = mysql_query($query,$sq); - echo mysql_error(); - if (mysql_num_rows($q) == 0) { + + $stmtCount->execute([ + 'begin' => $year.'-'.$month_s.'-01', + 'end' => $year.'-'.$month_s.'-31 23:59:59', + ]); + + if ($stmtCount->fetchColumn() === 0) { continue; } + + $stmt->execute([ + 'begin' => $year.'-'.$month_s.'-01', + 'end' => $year.'-'.$month_s.'-31 23:59:59', + ]); $total = 0; $number = 0; $max = -1; $min = INF; $all_amounts = array(); - while ($row = mysql_fetch_array($q)) { + while ($row = $stmt->fetch()) { $amount = $row["amount"]; $total += $amount; $number += 1; @@ -76,16 +95,16 @@ echo " - + "; } echo " - + @@ -136,48 +155,83 @@ = '".$_POST["from"]."' and date <= '".$_POST["to"]." 23:59:59'"; - } - $q = mysql_query($query,$sq); - echo mysql_error(); - - $urls = array(); - while ($row = mysql_fetch_array($q)) { - if ($row[0] == "") + if ($period === "today") { + $query .= ' WHERE DATE(date) = CURDATE()'; + $q = $dbConnection->query($query); + } else if ($period === "yesterday") { + $query .= ' WHERE DATE(date) = SUBDATE(CURDATE(), 1)'; + $q = $dbConnection->query($query); + } else if ($period === "month") { + $query .= ' WHERE YEAR(date) = YEAR(NOW()) AND MONTH(date) = MONTH(NOW())'; + $q = $dbConnection->query($query); + } else if ($period === "custom") { + $query .= ' WHERE date >= :from and date <= :to'; + $q = $dbConnection->prepare($query); + $q->execute([ + 'from' => $_POST['from'], + 'to' => $_POST['to'] . ' 23:59:59', + ]); + } else if ($period === "all") { + $q = $dbConnection->query($query); + } else { + echo "bug: $period"; + } + + $urls = []; + while ($row = $q->fetch()) { + if ($row[0] === "") { continue; + } - $query2 = "select amount from donations where donate_url = '".$row[0]."'"; - if ($period == "today") { - $query2 .= " and DATE(date) = CURDATE()"; - } else if ($period == "yesterday") { - $query2 .= " and DATE(date) = SUBDATE(CURDATE(), 1)"; - } else if ($period == "month") { - $query2 .= " and YEAR(date) = YEAR(NOW()) and MONTH(date) = MONTH(NOW())"; - } else if ($period == "custom") { - $query2 .= " and date >= '".$_POST["from"]."' and date <= '".$_POST["to"]." 23:59:59'"; + $query2 = 'SELECT amount FROM donations where donate_url = :donate_url'; + if ($period === 'today') { + $query2 .= ' AND DATE(date) = CURDATE()'; + $q2 = $dbConnection->prepare($query2); + $q2->execute([ + 'donate_url' => $row[0], + ]); + } else if ($period === 'yesterday') { + $query2 .= ' AND DATE(date) = SUBDATE(CURDATE(), 1)'; + $q2 = $dbConnection->prepare($query2); + $q2->execute([ + 'donate_url' => $row[0], + ]); + } else if ($period === 'month') { + $query2 .= ' AND YEAR(date) = YEAR(NOW()) and MONTH(date) = MONTH(NOW())'; + $q2 = $dbConnection->prepare($query2); + $q2->execute([ + 'donate_url' => $row[0], + ]); + } else if ($period === 'custom') { + $query2 .= ' AND date >= :from AND date <= :to'; + $q2 = $dbConnection->prepare($query2); + $q2->execute([ + 'donate_url' => $row[0], + 'from' => $_POST['from'], + 'to' => $_POST['to'] . ' 23:59:59', + ]); + } else if ($period === "all") { + $q2 = $dbConnection->prepare($query2); + $q2->execute([ + 'donate_url' => $row[0], + ]); + } else { + echo "bug: $period"; } - $q2 = mysql_query($query2,$sq); - echo mysql_error(); $total = 0; $number = 0; $max = -1; $min = INF; $all_amounts = array(); - while ($row2 = mysql_fetch_array($q2)) { + while ($row2 = $q2->fetch()) { $amount = $row2["amount"]; $total += $amount; $number += 1; @@ -241,8 +295,7 @@ "; } - echo "
    ".$year."
    ".date("F", mktime(0,0,0,$month,1,$year))." ".$number." ".$total."".round($total/$number, 2)."".($number !== 0 ? round($total/$number, 2) : 0)." ".round(standard_deviation($all_amounts),2)." ".$max." ".$min."
    Year Total ".$year_number." ".$year_total."".round($year_total/$year_number, 2)."".($year_number !== 0 ? round($year_total/$year_number, 2) : 0)." ".round(standard_deviation($year_all_amounts),2)." ".$year_max." ".$year_min." ".$value[3]."

    "; - - include "footer.inc"; + echo "
    "; + include "../../../aether/footer.php"; ?> Index: fundraisers/kdesprints2015/index.php =================================================================== --- fundraisers/kdesprints2015/index.php +++ fundraisers/kdesprints2015/index.php @@ -18,16 +18,15 @@ require('../../aether/header.php'); $site_root = "../../"; - require("donations_auth.inc"); + require("www_config.php"); - $query = "select *,unix_timestamp(date) as date_t from randameetings2015donations order by date desc;"; - $q = mysql_query($query,$sq); - echo mysql_error(); + $res = $dbConnection->prepare("SELECT *, UNIX_TIMESTAMP(date) AS date_t FROM randameetings2015donations ORDER BY date DESC;"); + $res->execute(); $total = 0; $count = 0; $table = ""; $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(); $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 +54,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. @@ -74,7 +76,7 @@ $memo = ""; } - require("donations_auth.inc"); + require("www_config.php"); // check the payment_status is Completed if ( $payment_status != "Completed") { Index: fundraisers/randameetings2016/index.php =================================================================== --- fundraisers/randameetings2016/index.php +++ fundraisers/randameetings2016/index.php @@ -28,15 +28,14 @@ $enddate="2016-07-22"; $daystogo=floor((strtotime($enddate)-time())/(60*60*24)); - require("donations_auth.inc"); + require("www_config.php"); - $query = "select *,unix_timestamp(date) as date_t from randameetings2016donations order by date desc;"; - $q = mysql_query($query,$sq); - echo mysql_error(); + $res = $dbConnection->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 @@ -74,7 +75,7 @@ $memo = ""; } - require("donations_auth.inc"); + require("www_config.php"); // check the payment_status is Completed if ( $payment_status != "Completed") { Index: fundraisers/randameetings2016/stats.php =================================================================== --- fundraisers/randameetings2016/stats.php +++ fundraisers/randameetings2016/stats.php @@ -223,20 +223,19 @@ $enddate="2016-07-11"; $daystogo=floor((strtotime($enddate)-time())/(60*60*24)); - require("donations_auth.inc"); + require("www_config.php"); - $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 @@ -28,17 +28,19 @@ $enddate="2017-09-30"; $daystogo=floor((strtotime($enddate)-time())/(60*60*24)); - require_once("config.php"); + require_once("www_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'); @@ -20,7 +21,7 @@ } if ($verified) { - require_once("config.php"); + require_once("www_config.php"); $payment_amount = $_POST['mc_gross']; $payment_status = $_POST['payment_status']; $receiver_email = $_POST["receiver_email"]; Index: fundraisers/randameetings2017/stats.php =================================================================== --- fundraisers/randameetings2017/stats.php +++ fundraisers/randameetings2017/stats.php @@ -222,11 +222,9 @@ $enddate="2017-09-17"; $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); + require("www_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');"); $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 @@ -18,21 +18,18 @@ require('../../aether/header.php'); $site_root = "../../"; - require("donations_auth.inc"); + require("www_config.php"); - $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 @@ -16,21 +16,18 @@ require('../../aether/header.php'); $site_root = "../../"; - require("donations_auth.inc"); + require("www_config.php"); + + $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 +47,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 @@ -86,19 +86,17 @@ 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: fundraisers/yearend2017/notify.php =================================================================== --- fundraisers/yearend2017/notify.php +++ fundraisers/yearend2017/notify.php @@ -20,7 +20,7 @@ } if ($verified) { - require_once("config.php"); + require_once("www_config.php"); $payment_amount = $_POST['mc_gross']; $payment_status = $_POST['payment_status']; $receiver_email = $_POST["receiver_email"]; 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("www_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,126 @@ + + * + * 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(); + $this->generateDonationTable('randameetings2014donations'); + $this->generateDonationTable('randameetings2016donations'); + $this->generateDonationTable2('randameetings2017donations'); + } + + 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']; + } + } + + private function generateDonationTable($name) + { + $stmt = $this->db->exec("CREATE TABLE IF NOT EXISTS $name ( + id INT AUTO_INCREMENT PRIMARY KEY, + date DATETIME, + amount FLOAT(10, 2), + message VARCHAR(255), + transactionid VARCHAR(255) UNIQUE );"); + + $stmt = $this->db->prepare("INSERT into $name VALUES( NULL, :date, :payment_amount, :memo, :txn_id);"); + + 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, + ]); + } + $query = $this->db->query("SELECT * from $name"); + + while ($row = $query->fetch()) { + echo $row['amount'] . '
    '; + } + } + + private function generateDonationTable2($name) + { + $stmt = $this->db->exec("CREATE TABLE IF NOT EXISTS $name ( + id INT AUTO_INCREMENT PRIMARY KEY, + CREATED_AT DATETIME, + amount FLOAT(10, 2), + message VARCHAR(255), + donor_name VARCHAR(255), + transactionid VARCHAR(255) UNIQUE );"); + + $stmt = $this->db->prepare("INSERT into $name VALUES( NULL, :date, :payment_amount, :memo, :name, :txn_id);"); + + 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", + 'name' => "FooBar", + 'txn_id' => time() + $i, + ]); + } + $query = $this->db->query("SELECT * from $name"); + + while ($row = $query->fetch()) { + echo $row['amount'] . '
    '; + } + } +} + +$fixture = new Fixture($dbConnection); +echo "Done";
    ".i18n_var("Total Amount")."".i18n_var("Donor Name")."