mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2024-11-22 13:07:59 +01:00
Closes T360: Replace the dev blog feed with the Twitter feed.
This commit is contained in:
parent
efa16a2baa
commit
1aa0b5f9d7
8 changed files with 44 additions and 182 deletions
|
@ -3,9 +3,7 @@
|
||||||
namespace App\Http\Controllers\Api\Web;
|
namespace App\Http\Controllers\Api\Web;
|
||||||
|
|
||||||
use App\Http\Controllers\ApiControllerBase;
|
use App\Http\Controllers\ApiControllerBase;
|
||||||
use App\News;
|
|
||||||
use App\Track;
|
use App\Track;
|
||||||
use Cover;
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\Input;
|
use Illuminate\Support\Facades\Input;
|
||||||
use Illuminate\Support\Facades\Response;
|
use Illuminate\Support\Facades\Response;
|
||||||
|
@ -32,16 +30,7 @@ class DashboardController extends ApiControllerBase
|
||||||
|
|
||||||
return Response::json([
|
return Response::json([
|
||||||
'recent_tracks' => $recentTracks,
|
'recent_tracks' => $recentTracks,
|
||||||
'popular_tracks' => Track::popular(30, Auth::check() && Auth::user()->can_see_explicit_content),
|
'popular_tracks' => Track::popular(30, Auth::check() && Auth::user()->can_see_explicit_content)
|
||||||
'news' => News::getNews(0, 10)
|
|
||||||
], 200);
|
], 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function postReadNews()
|
|
||||||
{
|
|
||||||
News::markPostAsRead(Input::get('url'));
|
|
||||||
|
|
||||||
return Response::json([
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
}
|
70
app/News.php
70
app/News.php
|
@ -1,70 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
use SimplePie;
|
|
||||||
|
|
||||||
class News extends Model
|
|
||||||
{
|
|
||||||
public static function getNews($start = 0, $end = 4)
|
|
||||||
{
|
|
||||||
$feed = new SimplePie();
|
|
||||||
$feed->cache = false;
|
|
||||||
$feed->set_feed_url('http://mlpforums.com/blog/rss/404-ponyfm-development-blog/');
|
|
||||||
$feed->init();
|
|
||||||
$feed->handle_content_type();
|
|
||||||
|
|
||||||
$posts = $feed->get_items($start, $end);
|
|
||||||
$postHashes = [];
|
|
||||||
|
|
||||||
foreach ($posts as $post) {
|
|
||||||
$postHashes[] = self::calculateHash($post->get_permalink());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($postHashes) == 0) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$seenRecords = Auth::check() ? self::where('user_id', '=', Auth::user()->id)->whereIn('post_hash',
|
|
||||||
$postHashes)->get() : [];
|
|
||||||
$seenHashes = [];
|
|
||||||
|
|
||||||
foreach ($seenRecords as $record) {
|
|
||||||
$seenHashes[$record->post_hash] = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
$postsReturn = [];
|
|
||||||
|
|
||||||
// This date is around when the last blog post was posted as of now.
|
|
||||||
// I put in a cutoff so that blog posts made before this update is pushed are always marked as 'read'
|
|
||||||
$readCutoffDate = mktime(null, null, null, 4, 28, 2013);
|
|
||||||
|
|
||||||
foreach ($posts as $post) {
|
|
||||||
$autoRead = $post->get_date('U') < $readCutoffDate;
|
|
||||||
$postsReturn[] = [
|
|
||||||
'title' => $post->get_title(),
|
|
||||||
'date' => $post->get_date('j F Y g:i a'),
|
|
||||||
'url' => $post->get_permalink(),
|
|
||||||
'read' => $autoRead || isset($seenHashes[self::calculateHash($post->get_permalink())])
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $postsReturn;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function markPostAsRead($postUrl)
|
|
||||||
{
|
|
||||||
$postHash = self::calculateHash($postUrl);
|
|
||||||
$news = new News();
|
|
||||||
$news->user_id = Auth::user()->id;
|
|
||||||
$news->post_hash = $postHash;
|
|
||||||
$news->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function calculateHash($postPermalink)
|
|
||||||
{
|
|
||||||
return md5($postPermalink);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -9,7 +9,6 @@
|
||||||
"laravel/framework": "5.1.*",
|
"laravel/framework": "5.1.*",
|
||||||
"codescale/ffmpeg-php": "2.7.0",
|
"codescale/ffmpeg-php": "2.7.0",
|
||||||
"kriswallsmith/assetic": "1.2.*@dev",
|
"kriswallsmith/assetic": "1.2.*@dev",
|
||||||
"simplepie/simplepie": "1.3.1",
|
|
||||||
"intouch/laravel-newrelic": "*",
|
"intouch/laravel-newrelic": "*",
|
||||||
"barryvdh/laravel-ide-helper": "^2.1"
|
"barryvdh/laravel-ide-helper": "^2.1"
|
||||||
},
|
},
|
||||||
|
|
71
composer.lock
generated
71
composer.lock
generated
|
@ -4,7 +4,8 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"hash": "d034b42b177f410db0ab3fc82a278346",
|
"hash": "9079e8e598ee7e2caa54fdc23e02e0c1",
|
||||||
|
"content-hash": "de0cc2821022365e5f198a9e5ba3be3f",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "barryvdh/laravel-ide-helper",
|
"name": "barryvdh/laravel-ide-helper",
|
||||||
|
@ -555,16 +556,16 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "kriswallsmith/assetic",
|
"name": "kriswallsmith/assetic",
|
||||||
"version": "1.2.x-dev",
|
"version": "dev-master",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/kriswallsmith/assetic.git",
|
"url": "https://github.com/kriswallsmith/assetic.git",
|
||||||
"reference": "182bfb92b61df601b6eb5676bcb3c91eb5fad57a"
|
"reference": "5bea57990f7ddbeb3d57e7ef96eae9ddd56c4297"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/kriswallsmith/assetic/zipball/182bfb92b61df601b6eb5676bcb3c91eb5fad57a",
|
"url": "https://api.github.com/repos/kriswallsmith/assetic/zipball/5bea57990f7ddbeb3d57e7ef96eae9ddd56c4297",
|
||||||
"reference": "182bfb92b61df601b6eb5676bcb3c91eb5fad57a",
|
"reference": "5bea57990f7ddbeb3d57e7ef96eae9ddd56c4297",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -579,8 +580,8 @@
|
||||||
"leafo/scssphp": "*",
|
"leafo/scssphp": "*",
|
||||||
"leafo/scssphp-compass": "*",
|
"leafo/scssphp-compass": "*",
|
||||||
"mrclay/minify": "*",
|
"mrclay/minify": "*",
|
||||||
"patchwork/jsqueeze": "~1.0",
|
"patchwork/jsqueeze": "*",
|
||||||
"phpunit/phpunit": "~4",
|
"phpunit/phpunit": "~3.7",
|
||||||
"psr/log": "~1.0",
|
"psr/log": "~1.0",
|
||||||
"ptachoire/cssembed": "*",
|
"ptachoire/cssembed": "*",
|
||||||
"twig/twig": "~1.6"
|
"twig/twig": "~1.6"
|
||||||
|
@ -625,7 +626,7 @@
|
||||||
"compression",
|
"compression",
|
||||||
"minification"
|
"minification"
|
||||||
],
|
],
|
||||||
"time": "2015-08-05 10:14:34"
|
"time": "2014-07-08 11:30:40"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "laravel/framework",
|
"name": "laravel/framework",
|
||||||
|
@ -1207,60 +1208,6 @@
|
||||||
],
|
],
|
||||||
"time": "2015-07-16 15:26:57"
|
"time": "2015-07-16 15:26:57"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "simplepie/simplepie",
|
|
||||||
"version": "1.3.1",
|
|
||||||
"source": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/simplepie/simplepie.git",
|
|
||||||
"reference": "ce53709778bc1e2e4deda1651b66e5081398d5cc"
|
|
||||||
},
|
|
||||||
"dist": {
|
|
||||||
"type": "zip",
|
|
||||||
"url": "https://api.github.com/repos/simplepie/simplepie/zipball/ce53709778bc1e2e4deda1651b66e5081398d5cc",
|
|
||||||
"reference": "ce53709778bc1e2e4deda1651b66e5081398d5cc",
|
|
||||||
"shasum": ""
|
|
||||||
},
|
|
||||||
"require": {
|
|
||||||
"php": ">=5.2.0"
|
|
||||||
},
|
|
||||||
"type": "library",
|
|
||||||
"autoload": {
|
|
||||||
"psr-0": {
|
|
||||||
"SimplePie": "library"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
|
||||||
"license": [
|
|
||||||
"BSD-3-Clause"
|
|
||||||
],
|
|
||||||
"authors": [
|
|
||||||
{
|
|
||||||
"name": "Ryan Parman",
|
|
||||||
"homepage": "http://ryanparman.com/",
|
|
||||||
"role": "Creator, alumnus developer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Geoffrey Sneddon",
|
|
||||||
"homepage": "http://gsnedders.com/",
|
|
||||||
"role": "Alumnus developer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Ryan McCue",
|
|
||||||
"email": "me@ryanmccue.info",
|
|
||||||
"homepage": "http://ryanmccue.info/",
|
|
||||||
"role": "Developer"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "A simple Atom/RSS parsing library for PHP",
|
|
||||||
"homepage": "http://simplepie.org/",
|
|
||||||
"keywords": [
|
|
||||||
"atom",
|
|
||||||
"feeds",
|
|
||||||
"rss"
|
|
||||||
],
|
|
||||||
"time": "2012-10-30 17:54:03"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "swiftmailer/swiftmailer",
|
"name": "swiftmailer/swiftmailer",
|
||||||
"version": "v5.4.1",
|
"version": "v5.4.1",
|
||||||
|
|
|
@ -2,30 +2,33 @@
|
||||||
<section class="recent-tracks">
|
<section class="recent-tracks">
|
||||||
<h1>
|
<h1>
|
||||||
<a href="/tracks"><i class="icon-music"></i> see more</a>
|
<a href="/tracks"><i class="icon-music"></i> see more</a>
|
||||||
The Newest Tunes
|
The newest tunes
|
||||||
</h1>
|
</h1>
|
||||||
<pfm-tracks-list tracks="recentTracks" class="two-columns"></pfm-tracks-list>
|
<pfm-tracks-list tracks="recentTracks" class="two-columns"></pfm-tracks-list>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="popular-tracks">
|
<section class="popular-tracks">
|
||||||
<h1>
|
<h1>
|
||||||
What's Popular Today
|
What's popular today
|
||||||
</h1>
|
</h1>
|
||||||
<pfm-tracks-list tracks="popularTracks" class="two-columns"></pfm-tracks-list>
|
<pfm-tracks-list tracks="popularTracks" class="two-columns"></pfm-tracks-list>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="news">
|
<section class="news">
|
||||||
<h1>
|
<h1>
|
||||||
<a href="http://mlpforums.com/blog/404-ponyfm-development-blog/" target="_blank">read all</a>
|
<a href="https://twitter.com/ponyfm" target="_blank">follow @ponyfm</a>
|
||||||
Pony.fm News
|
Pony.fm news
|
||||||
</h1>
|
</h1>
|
||||||
<ul>
|
<a class="twitter-timeline" href="https://twitter.com/ponyfm" data-widget-id="644195953956798464">Tweets by
|
||||||
<li ng-repeat="post in news" ng-class="{'read': post.read}">
|
@ponyfm</a>
|
||||||
<a href="{{post.url}}" target="_blank" ng-click="markAsRead(post)">
|
<script>!function (d, s, id) {
|
||||||
<em>{{post.date}}</em>
|
var js, fjs = d.getElementsByTagName(s)[0], p = /^http:/.test(d.location) ? 'http' : 'https';
|
||||||
{{post.title}}
|
if (!d.getElementById(id)) {
|
||||||
</a>
|
js = d.createElement(s);
|
||||||
</li>
|
js.id = id;
|
||||||
</ul>
|
js.src = p + "://platform.twitter.com/widgets.js";
|
||||||
|
fjs.parentNode.insertBefore(js, fjs);
|
||||||
|
}
|
||||||
|
}(document, "script", "twitter-wjs");</script>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
|
@ -2,14 +2,14 @@
|
||||||
<section class="recent-tracks">
|
<section class="recent-tracks">
|
||||||
<h1>
|
<h1>
|
||||||
<a href="/tracks"><i class="icon-music"></i> see more</a>
|
<a href="/tracks"><i class="icon-music"></i> see more</a>
|
||||||
The Newest Tunes
|
The newest tunes
|
||||||
</h1>
|
</h1>
|
||||||
<pfm-tracks-list tracks="recentTracks" class="two-columns"></pfm-tracks-list>
|
<pfm-tracks-list tracks="recentTracks" class="two-columns"></pfm-tracks-list>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="popular-tracks">
|
<section class="popular-tracks">
|
||||||
<h1>
|
<h1>
|
||||||
What's Popular Today
|
What's popular today
|
||||||
</h1>
|
</h1>
|
||||||
<pfm-tracks-list tracks="popularTracks" class="two-columns"></pfm-tracks-list>
|
<pfm-tracks-list tracks="popularTracks" class="two-columns"></pfm-tracks-list>
|
||||||
</section>
|
</section>
|
||||||
|
@ -26,15 +26,18 @@
|
||||||
|
|
||||||
<h1>
|
<h1>
|
||||||
<a href="http://mlpforums.com/blog/404-ponyfm-development-blog/" target="_blank">read all</a>
|
<a href="http://mlpforums.com/blog/404-ponyfm-development-blog/" target="_blank">read all</a>
|
||||||
Pony.fm News
|
Pony.fm news
|
||||||
</h1>
|
</h1>
|
||||||
<ul>
|
<a class="twitter-timeline" href="https://twitter.com/ponyfm" data-widget-id="644195953956798464">Tweets by
|
||||||
<li ng-repeat="post in news">
|
@ponyfm</a>
|
||||||
<a href="{{post.url}}" target="_blank">
|
<script>!function (d, s, id) {
|
||||||
<em>{{post.date}}</em>
|
var js, fjs = d.getElementsByTagName(s)[0], p = /^http:/.test(d.location) ? 'http' : 'https';
|
||||||
{{post.title}}
|
if (!d.getElementById(id)) {
|
||||||
</a>
|
js = d.createElement(s);
|
||||||
</li>
|
js.id = id;
|
||||||
</ul>
|
js.src = p + "://platform.twitter.com/widgets.js";
|
||||||
|
fjs.parentNode.insertBefore(js, fjs);
|
||||||
|
}
|
||||||
|
}(document, "script", "twitter-wjs");</script>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
|
@ -8,15 +8,8 @@ angular.module('ponyfm').controller "dashboard", [
|
||||||
($scope, dashboard, auth, $http) ->
|
($scope, dashboard, auth, $http) ->
|
||||||
$scope.recentTracks = null
|
$scope.recentTracks = null
|
||||||
$scope.popularTracks = null
|
$scope.popularTracks = null
|
||||||
$scope.news = null
|
|
||||||
|
|
||||||
dashboard.refresh().done (res) ->
|
dashboard.refresh().done (res) ->
|
||||||
$scope.recentTracks = res.recent_tracks
|
$scope.recentTracks = res.recent_tracks
|
||||||
$scope.popularTracks = res.popular_tracks
|
$scope.popularTracks = res.popular_tracks
|
||||||
$scope.news = res.news
|
|
||||||
|
|
||||||
$scope.markAsRead = (post) ->
|
|
||||||
if auth.data.isLogged
|
|
||||||
$http.post('/api/web/dashboard/read-news', {url: post.url, _token: window.pfm.token}).success ->
|
|
||||||
post.read = true
|
|
||||||
]
|
]
|
|
@ -8,10 +8,8 @@ angular.module('ponyfm').controller "home", [
|
||||||
($scope, dashboard) ->
|
($scope, dashboard) ->
|
||||||
$scope.recentTracks = null
|
$scope.recentTracks = null
|
||||||
$scope.popularTracks = null
|
$scope.popularTracks = null
|
||||||
$scope.news = null
|
|
||||||
|
|
||||||
dashboard.refresh().done (res) ->
|
dashboard.refresh().done (res) ->
|
||||||
$scope.recentTracks = res.recent_tracks
|
$scope.recentTracks = res.recent_tracks
|
||||||
$scope.popularTracks = res.popular_tracks
|
$scope.popularTracks = res.popular_tracks
|
||||||
$scope.news = res.news
|
|
||||||
]
|
]
|
Loading…
Reference in a new issue