Don't make the twitter searcher easy to alter
Get the twitter filters from the settings on the home node Makes latest forum activity on home async too
This commit is contained in:
@@ -1761,7 +1761,6 @@
|
||||
<Content Include="Views\MacroPartials\Releases\AllReleases.cshtml" />
|
||||
<Content Include="Views\MacroPartials\Projects\ProjectDetails.cshtml" />
|
||||
<Content Include="Views\MacroPartials\Members\Register.cshtml" />
|
||||
<Content Include="Views\MacroPartials\Forum\LatestActivity.cshtml" />
|
||||
<Content Include="Views\MacroPartials\Members\ProfileProjectForums.cshtml" />
|
||||
<Content Include="masterpages\ReleaseProgress.master" />
|
||||
<Content Include="Views\MacroPartials\Global\AlertBar.cshtml" />
|
||||
@@ -1792,6 +1791,7 @@
|
||||
<Content Include="Views\Partials\Community\TermsAndConditions.cshtml" />
|
||||
<Content Include="Views\MacroPartials\Members\ForgotPassword.cshtml" />
|
||||
<Content Include="Views\MacroPartials\Members\Login.cshtml" />
|
||||
<Content Include="Views\Partials\Home\LatestForumActivity.cshtml" />
|
||||
<None Include="Views\Partials\Forum\MemberBadge.cshtml" />
|
||||
<Content Include="Views\Search\Search.aspx" />
|
||||
<Content Include="Views\Web.config" />
|
||||
@@ -4434,7 +4434,6 @@
|
||||
<Content Include="Views\Partials\Projects\CompatibilityReport.cshtml" />
|
||||
<Content Include="Views\Partials\Project\Edit.cshtml" />
|
||||
<Content Include="Views\Partials\Home\Documentation.cshtml" />
|
||||
<Content Include="Views\Partials\Home\ForumActivity.cshtml" />
|
||||
<Content Include="Views\Partials\Grid\Editors\Textstring.cshtml" />
|
||||
<Content Include="Views\Partials\Grid\Editors\Rte.cshtml" />
|
||||
<Content Include="Views\Partials\Grid\Editors\Media.cshtml" />
|
||||
|
||||
@@ -57,24 +57,89 @@
|
||||
|
||||
@if (Members.IsLoggedIn())
|
||||
{
|
||||
@Html.Partial("home/forumactivity")
|
||||
<div id="twitter-search"></div>
|
||||
@ForumActivity()
|
||||
@TwitterSearch()
|
||||
@Html.Partial("home/documentation")
|
||||
}
|
||||
else
|
||||
{
|
||||
@Html.Partial("home/documentation")
|
||||
@Html.Partial("home/forumactivity")
|
||||
<div id="twitter-search"></div>
|
||||
@ForumActivity()
|
||||
@TwitterSearch()
|
||||
}
|
||||
|
||||
@helper ForumActivity()
|
||||
{
|
||||
<section class="forum">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
|
||||
<div class="col-md-12">
|
||||
<h1 class="text-center">Forum Activity</h1>
|
||||
<p>
|
||||
Recent activity in the forums, where people are helping each other with current problems.
|
||||
</p>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<small>Recent posts</small>
|
||||
</div>
|
||||
|
||||
<div class="col-md-12 flex" id="forum-activity">
|
||||
<h2>Loading latest forum activity...</h2>
|
||||
</div>
|
||||
|
||||
<div class="col-md-12 goto-forum">
|
||||
<a class="button green" href="/forum">Go to Forum →</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
}
|
||||
|
||||
@helper TwitterSearch()
|
||||
{
|
||||
<section class="forum">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
|
||||
<div class="col-md-12">
|
||||
<h1 class="text-center">Twitter Activity</h1>
|
||||
<p>
|
||||
Recent activity on twitter, where people are talking about Umbraco.
|
||||
</p>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<small>Recent tweets</small>
|
||||
</div>
|
||||
|
||||
<div class="col-md-12 flex" id="twitter-search">
|
||||
<h2>Loading twitter search results...</h2>
|
||||
</div>
|
||||
|
||||
<div class="col-md-12 goto-forum">
|
||||
<a class="button green" href="https://twitter.com/search?f=tweets&vertical=default&q=umbraco&src=typd">Join the conversation on Twitter →</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
}
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
try {
|
||||
$("#twitter-search").load("@Url.Action("TwitterSearchResult", "TwitterSearch")");
|
||||
$("#twitter-search").load("@Url.Action("TwitterSearchResult", "TwitterSearch", new { numberOfResults = 6 })");
|
||||
}
|
||||
catch (err) {
|
||||
console.log("Couldn't load Twitter feed", err.message);
|
||||
catch (errTwitter) {
|
||||
console.log("Couldn't load Twitter feed", errTwitter.message);
|
||||
}
|
||||
|
||||
try {
|
||||
$("#forum-activity").load("@Url.Action("LatestActivity", "LatestActivity", new { numberOfTopics = 6 })");
|
||||
}
|
||||
catch (errForum) {
|
||||
console.log("Couldn't load latest forum activity", errForum.message);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@@ -1,54 +0,0 @@
|
||||
@using OurUmbraco.Forum.Extensions
|
||||
@using OurUmbraco.Forum.Models
|
||||
@using OurUmbraco.Forum.Services
|
||||
@using OurUmbraco.Our
|
||||
@inherits Umbraco.Web.Macros.PartialViewMacroPage
|
||||
|
||||
@{
|
||||
var ts = new TopicService(ApplicationContext.DatabaseContext);
|
||||
}
|
||||
|
||||
<div class="col-md-12 flex">
|
||||
@Column(ts.GetLatestTopics(6, 1))
|
||||
</div>
|
||||
|
||||
@helper Column(IEnumerable<ReadOnlyTopic> topics)
|
||||
{
|
||||
foreach (var topic in topics.ToArray())
|
||||
{
|
||||
var cat = Umbraco.TypedContent(topic.ParentId);
|
||||
var mem = Members.GetById(topic.LatestReplyAuthor) ?? Members.GetById(topic.MemberId);
|
||||
|
||||
<a href="@topic.GetUrl()" class="forum-thread @Umbraco.If(topic.Answer > 0, " solved")">
|
||||
|
||||
<div class="avatar">
|
||||
@if(mem != null)
|
||||
{
|
||||
@Html.Raw(Utils.GetMemberAvatar(mem, 100))
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="meta">
|
||||
<div class="forum-thread-text">
|
||||
<h3>@topic.Title</h3>
|
||||
<p>
|
||||
@if (topic.Replies != 0 && !string.IsNullOrEmpty(topic.LastReplyAuthorName))
|
||||
{
|
||||
<text>last edited by @topic.LastReplyAuthorName</text>
|
||||
}
|
||||
else
|
||||
{
|
||||
<text>created by @topic.AuthorName</text>
|
||||
}
|
||||
|
||||
@topic.Updated.ConvertToRelativeTime()
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="category">
|
||||
<span class="cat">@cat.Name</span>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
@inherits Umbraco.Web.Macros.PartialViewMacroPage
|
||||
|
||||
<section class="forum">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
|
||||
<div class="col-md-12">
|
||||
<h1 class="text-center">Forum Activity</h1>
|
||||
<p>
|
||||
Recent activity in the forums, where people are helping each other with current problems.
|
||||
</p>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<small>Recent posts</small>
|
||||
</div>
|
||||
|
||||
@Umbraco.RenderMacro("ForumLatestActivity")
|
||||
|
||||
|
||||
<div class="col-md-12 goto-forum">
|
||||
<a class="button green" href="/forum">Go to Forum →</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
@@ -0,0 +1,40 @@
|
||||
@using OurUmbraco.Forum.Extensions
|
||||
@using OurUmbraco.Forum.Models
|
||||
@model ReadOnlyTopic[]
|
||||
|
||||
@foreach (var topic in Model)
|
||||
{
|
||||
<a href="@topic.GetUrl()" class="forum-thread @(topic.Answer > 0 ? "solved": null)">
|
||||
|
||||
<div class="avatar">
|
||||
@Html.Raw(topic.LastReplyAuthorAvatar)
|
||||
</div>
|
||||
|
||||
<div class="meta">
|
||||
<div class="forum-thread-text">
|
||||
<h3>@topic.Title</h3>
|
||||
<p>
|
||||
@if (topic.Replies != 0 && !string.IsNullOrEmpty(topic.LastReplyAuthorName))
|
||||
{
|
||||
<text>last updated by @topic.LastReplyAuthorName</text>
|
||||
}
|
||||
else
|
||||
{
|
||||
<text>created by @topic.AuthorName</text>
|
||||
}
|
||||
|
||||
@topic.Updated.ConvertToRelativeTime()
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="category">
|
||||
<span class="cat">@topic.CategoryName</span>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
}
|
||||
|
||||
@if (Model.Any() == false)
|
||||
{
|
||||
<h2>Could not load recent forum activity.</h2>
|
||||
}
|
||||
@@ -2,51 +2,24 @@
|
||||
@using Tweetinvi.Models
|
||||
@model ITweet[]
|
||||
|
||||
@if (Model.Any())
|
||||
@foreach (var tweet in Model)
|
||||
{
|
||||
<section class="forum">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<a href="@tweet.Url" class="forum-thread">
|
||||
|
||||
<div class="col-md-12">
|
||||
<h1 class="text-center">Twitter Activity</h1>
|
||||
<p>
|
||||
Recent activity on twitter, where people are talking about Umbraco.
|
||||
</p>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<small>Recent tweets</small>
|
||||
</div>
|
||||
|
||||
<div class="col-md-12 flex">
|
||||
@Column(Model)
|
||||
</div>
|
||||
|
||||
<div class="col-md-12 goto-forum">
|
||||
<a class="button green" href="https://twitter.com/search?f=tweets&vertical=default&q=umbraco&src=typd">Join the conversation on Twitter →</a>
|
||||
</div>
|
||||
<div class="avatar">
|
||||
<img src="@tweet.CreatedBy.ProfileImageUrl400x400" />
|
||||
</div>
|
||||
|
||||
<div class="meta">
|
||||
<div class="forum-thread-text">
|
||||
<h3>@tweet.Text</h3>
|
||||
<p>@tweet.CreatedAt.ConvertToRelativeTime() by @@@tweet.CreatedBy.UserIdentifier.ScreenName (@tweet.CreatedBy.Name)</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</a>
|
||||
}
|
||||
|
||||
@helper Column(ITweet[] tweets)
|
||||
@if (Model.Any() == false)
|
||||
{
|
||||
foreach (var tweet in tweets.Take(6))
|
||||
{
|
||||
<a href="@tweet.Url" class="forum-thread">
|
||||
|
||||
<div class="avatar">
|
||||
<img src="@tweet.CreatedBy.ProfileImageUrl400x400" />
|
||||
</div>
|
||||
|
||||
<div class="meta">
|
||||
<div class="forum-thread-text">
|
||||
<h3>@tweet.Text</h3>
|
||||
<p>@tweet.CreatedAt.ConvertToRelativeTime() by @@@tweet.CreatedBy.UserIdentifier.ScreenName (@tweet.CreatedBy.Name)</p>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
}
|
||||
<h2>Could not load recent tweets.</h2>
|
||||
}
|
||||
@@ -1,9 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Mvc;
|
||||
using Tweetinvi;
|
||||
using Tweetinvi.Models;
|
||||
@@ -11,14 +8,18 @@ using Tweetinvi.Parameters;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.Mvc;
|
||||
|
||||
namespace OurUmbraco.Community.Controllers
|
||||
{
|
||||
public class TwitterSearchController : SurfaceController
|
||||
{
|
||||
public ActionResult TwitterSearchResult(string searchWord = "umbraco")
|
||||
public ActionResult TwitterSearchResult(int numberOfResults = 6)
|
||||
{
|
||||
if (numberOfResults > 30)
|
||||
numberOfResults = 6;
|
||||
|
||||
ITweet[] filteredTweets = { };
|
||||
try
|
||||
{
|
||||
@@ -31,18 +32,25 @@ namespace OurUmbraco.Community.Controllers
|
||||
ConfigurationManager.AppSettings["twitterUserAccessSecret"]);
|
||||
Tweetinvi.User.GetAuthenticatedUser();
|
||||
|
||||
var searchParameter = new SearchTweetsParameters(searchWord) { SearchType = SearchResultType.Recent };
|
||||
var searchParameter = new SearchTweetsParameters("umbraco") { SearchType = SearchResultType.Recent };
|
||||
return Search.SearchTweets(searchParameter).ToArray();
|
||||
|
||||
}, TimeSpan.FromMinutes(2));
|
||||
|
||||
var usernameFilter = "Technologx,Technologx4Real,SOAzure,AdamSmith1,AdamSmitht1,UriSamuels,coding_jobfeeds,TechSparkUk,ItProjectBoard,liveedutv,AdeboyejoAde,VivacitySocial,CHHCInc,DevOpsBlogs,ItCrowdSource,EquiKey".ToLowerInvariant().Split(',');
|
||||
var wordFilter = "exegesis,#Job Alert:,#pigefodboldbsf".ToLowerInvariant().Split(',');
|
||||
var settingsNode = Umbraco.TypedContentAtRoot().FirstOrDefault();
|
||||
if (settingsNode != null)
|
||||
{
|
||||
var usernameFilter = settingsNode.GetPropertyValue<string>("twitterFilterAccounts")
|
||||
.ToLowerInvariant().Split(',').Where(x => x != string.Empty);
|
||||
var wordFilter = settingsNode.GetPropertyValue<string>("twitterFilterWords")
|
||||
.ToLowerInvariant().Split(',').Where(x => x != string.Empty);
|
||||
|
||||
filteredTweets = tweets.Where(
|
||||
x => x.Urls.Any(u => u.ExpandedURL.Contains("umbraco-proxy.com")) == false
|
||||
&& x.CreatedBy.UserIdentifier.ScreenName.ToLowerInvariant().ContainsAny(usernameFilter) == false
|
||||
&& x.Text.ToLowerInvariant().ContainsAny(wordFilter) == false).ToArray();
|
||||
filteredTweets = tweets.Where(x =>
|
||||
x.CreatedBy.UserIdentifier.ScreenName.ToLowerInvariant().ContainsAny(usernameFilter) == false
|
||||
&& x.Text.ToLowerInvariant().ContainsAny(wordFilter) == false)
|
||||
.Take(numberOfResults)
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using OurUmbraco.Forum.Services;
|
||||
using Umbraco.Web.Mvc;
|
||||
|
||||
namespace OurUmbraco.Forum.Controllers
|
||||
{
|
||||
public class LatestActivityController : SurfaceController
|
||||
{
|
||||
public ActionResult LatestActivity(int numberOfTopics = 6)
|
||||
{
|
||||
if (numberOfTopics > 30)
|
||||
numberOfTopics = 6;
|
||||
|
||||
var ts = new TopicService(ApplicationContext.DatabaseContext);
|
||||
var topics = ts.GetLatestTopics(numberOfTopics).ToArray();
|
||||
foreach (var topic in topics)
|
||||
{
|
||||
var category = Umbraco.TypedContent(topic.ParentId);
|
||||
if(category != null)
|
||||
topic.CategoryName = category.Name;
|
||||
|
||||
var member = Members.GetById(topic.LatestReplyAuthor) ?? Members.GetById(topic.MemberId);
|
||||
if (member != null)
|
||||
topic.LastReplyAuthorAvatar = Our.Utils.GetMemberAvatar(member, 100);
|
||||
}
|
||||
|
||||
return PartialView("~/Views/Partials/Home/LatestForumActivity.cshtml", topics);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,5 +16,11 @@ namespace OurUmbraco.Forum.Models
|
||||
|
||||
[ResultColumn("LastReplyAuthorName")]
|
||||
public string LastReplyAuthorName { get; set; }
|
||||
|
||||
[ResultColumn("LastReplyAuthorAvatar")]
|
||||
public string LastReplyAuthorAvatar { get; set; }
|
||||
|
||||
[ResultColumn("CategoryName")]
|
||||
public string CategoryName { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,7 @@ namespace OurUmbraco.Our
|
||||
AddMarkAsSolutionReminderSent();
|
||||
UseNewLoginForm();
|
||||
UseNewForgotPasswordForm();
|
||||
AddTwitterFilters();
|
||||
}
|
||||
|
||||
private void EnsureMigrationsMarkerPathExists()
|
||||
@@ -637,5 +638,49 @@ namespace OurUmbraco.Our
|
||||
LogHelper.Error<MigrationsHandler>(string.Format("Migration: '{0}' failed", migrationName), ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void AddTwitterFilters()
|
||||
{
|
||||
var migrationName = MethodBase.GetCurrentMethod().Name;
|
||||
|
||||
try
|
||||
{
|
||||
var path = HostingEnvironment.MapPath(MigrationMarkersPath + migrationName + ".txt");
|
||||
if (File.Exists(path))
|
||||
return;
|
||||
|
||||
var contentTypeService = ApplicationContext.Current.Services.ContentTypeService;
|
||||
var communityContentType = contentTypeService.GetContentType("Community");
|
||||
var propertyTypeAlias = "twitterFilterAccounts";
|
||||
var textboxMultiple = new DataTypeDefinition("Umbraco.TextboxMultiple");
|
||||
|
||||
var tabName = "Settings";
|
||||
if (communityContentType.PropertyGroups.Contains(tabName) == false)
|
||||
communityContentType.AddPropertyGroup(tabName);
|
||||
|
||||
if (communityContentType.PropertyTypeExists(propertyTypeAlias) == false)
|
||||
{
|
||||
var textboxAccountsFilter = new PropertyType(textboxMultiple, propertyTypeAlias) { Name = "CSV of Twitter accounts to filter" };
|
||||
communityContentType.AddPropertyType(textboxAccountsFilter, tabName);
|
||||
}
|
||||
|
||||
propertyTypeAlias = "twitterFilterWords";
|
||||
if (communityContentType.PropertyTypeExists(propertyTypeAlias) == false)
|
||||
{
|
||||
var textboxWordFilter = new PropertyType(textboxMultiple, propertyTypeAlias) { Name = "CSV of words filter tweets out" };
|
||||
communityContentType.AddPropertyType(textboxWordFilter, tabName);
|
||||
}
|
||||
|
||||
contentTypeService.Save(communityContentType);
|
||||
|
||||
string[] lines = { "" };
|
||||
File.WriteAllLines(path, lines);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Error<MigrationsHandler>(string.Format("Migration: '{0}' failed", migrationName), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,6 +374,7 @@
|
||||
<Compile Include="Forum\Api\ForumControllerBase.cs" />
|
||||
<Compile Include="Forum\Api\PublicForumController.cs" />
|
||||
<Compile Include="Forum\Api\TopicController.cs" />
|
||||
<Compile Include="Forum\Controllers\LatestActivityController.cs" />
|
||||
<Compile Include="Forum\EventHandlers\MemberApprovedEventhandler.cs" />
|
||||
<Compile Include="Forum\EventHandlers\NewForumHandler.cs" />
|
||||
<Compile Include="Forum\Events.cs" />
|
||||
|
||||
Reference in New Issue
Block a user