From 638344c04c42e3a852b293e877c970d5d60d50dc Mon Sep 17 00:00:00 2001 From: flashwave Date: Sun, 19 Jul 2015 22:10:17 +0200 Subject: [PATCH] broken --- _sakura/components/Main.php | 28 +++++++++++++++++++++++++++ _sakura/sakura.php | 4 +++- _sakura/templates/yuuno/main/news.tpl | 13 +++++++++---- main/news.php | 13 +++++++++++++ 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/_sakura/components/Main.php b/_sakura/components/Main.php index 0c0b373..b7d5991 100644 --- a/_sakura/components/Main.php +++ b/_sakura/components/Main.php @@ -288,6 +288,34 @@ class Main { } + // Generate disqus hmac (https://github.com/disqus/DISQUS-API-Recipes/blob/master/sso/php/sso.php) + public static function dsqHmacSha1($data, $key) { + + $blocksize = 64; + + if(strlen($key) > $blocksize) { + + $key = pack('H*', sha1($key)); + + } + + $key = str_pad($key, $blocksize, chr(0x00)); + $ipad = str_repeat(chr(0x36), $blocksize); + $opad = str_repeat(chr(0x5c), $blocksize); + $hmac = pack( + 'H*', sha1( + ($key ^ $opad) . pack( + 'H*', sha1( + ($key ^ $ipad) . $data + ) + ) + ) + ); + + return bin2hex($hmac); + + } + // Loading info pages public static function loadInfoPage($id) { diff --git a/_sakura/sakura.php b/_sakura/sakura.php index a406e84..d5b6175 100644 --- a/_sakura/sakura.php +++ b/_sakura/sakura.php @@ -80,7 +80,9 @@ $renderData = [ 'cookiepath' => Configuration::getConfig('cookie_path'), 'minpwdentropy' => Configuration::getConfig('min_entropy'), 'minusernamelength' => Configuration::getConfig('username_min_length'), - 'maxusernamelength' => Configuration::getConfig('username_max_length') + 'maxusernamelength' => Configuration::getConfig('username_max_length'), + 'disqus_shortname' => Configuration::getConfig('disqus_shortname'), + 'disqus_api_key' => Configuration::getConfig('disqus_api_key') ], diff --git a/_sakura/templates/yuuno/main/news.tpl b/_sakura/templates/yuuno/main/news.tpl index 6798ff8..2c39aa1 100644 --- a/_sakura/templates/yuuno/main/news.tpl +++ b/_sakura/templates/yuuno/main/news.tpl @@ -34,18 +34,23 @@
comments powered by Disqus diff --git a/main/news.php b/main/news.php index b492f7d..65cb0c1 100644 --- a/main/news.php +++ b/main/news.php @@ -12,10 +12,23 @@ use DOMDocument; // Include components require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) .'_sakura/sakura.php'; +// Get user data +$disqus_user = Users::getUser(Session::$userId); + +// Set disqus data +$disqus_data = [ + $disqus_user['id'], + $disqus_user['username'], + $disqus_user['email'], + 'http://'. Configuration::getLocalConfig('urls', 'main') .'/a/'. $disqus_user['id'], + 'http://'. Configuration::getLocalConfig('urls', 'main') .'/u/'. $disqus_user['id'] +]; + // Add page specific things $renderData['newsPosts'] = Main::getNewsPosts((isset($_GET['id']) && !isset($_GET['xml']) && is_numeric($_GET['id'])) ? $_GET['id'] : null, (isset($_GET['id']) && !isset($_GET['xml']) && is_numeric($_GET['id']))); $renderData['page'] = [ 'title' => (isset($_GET['id']) ? (count($renderData['newsPosts']) ? $renderData['newsPosts'][0]['title'] : 'Post does not exist!') : 'Flashii News'), + 'disqus_sso' => ($disqus_user['password_algo'] == 'nologin' ? '{}' : (($disqus_message = base64_encode(json_encode($disqus_data))) .' '. Main::dsqHmacSha1($disqus_message .' '. time(), Configuration::getConfig('disqus_api_secret')) .' '. time())) ]; // News XML feed