Post HTML code from R to Wordpress - html

I succesfully put together an RMarkdown file which produces a nice HTML page. You can see the output here: https://www.crazy-geese.at/updates/schedule.html
What I would like to do now is to post the HTML Code to this page on our Wordpress Site: http://www.crazy-geese.at/spielplann-bbl-2018/
So my specific problem is to get the content to the page. I would need to update it regularly and would like to automate it.
Here are some solutions I see:
Update the page directly from R (from RMarkdown?) with the html code (that would be awesome)
Write an external script that does this job (a bash script maybe?)
I'm aware of the packages RWordpress and knit2wp but couldn't figure out how to do it. I also tried iframe but I couldn't get rid of the iframe scrollbars.
Every help would be much appreciated. Thanks!

Using RWordpress works for me using the following code:
if (!require('knitr')) {
install.packages("knitr")
}
if (!require('devtools')) {
install.packages("devtools")
}
if (!require('RWordPress')) {
devtools::install_github(c("duncantl/XMLRPC", "duncantl/RWordPress"))
}
library(RWordPress)
library(knitr)
options(WordpressLogin = c(<user> = '<pwd>'),
WordpressURL = '<blog_url>/xmlrpc.php')
## new post; memorize the returned id
# knit2wp("<Rmd-file>", title = '<title>',
# publish = FALSE, action = "newPost")
## update post
knit2wp("<Rmd-file>", title = '<title>',
publish = FALSE, action = "editPost", postid = <id>)
I typically do some further changes in wordpress's interface, which is why I have publish = FALSE. You can use publish = TRUE if you do not need that.

Related

Jsoup not displaying tags using the select() function

I'm trying to scrape the team win-loss record data from the NBA website here. Here's an image of the lines of text I want to capture, it is circled in black:
Can someone try scraping this exact data and seeing if it works? I've been at it for hours and nothing is working. I was able to scrape the team names and start times but when I try using jsoup's select function on the record lines, I get 0 results back. It's as if the tags are hidden from the html hierarchy. Is this possible? I'm new to this and I may be doing something wrong.
Code I have tried:
Document document = Jsoup.connect("http://espn.go.com/nba/scoreboard/_/date/20160315").get();
games = document.select("section.sb-score");
for(Element game : games)
{
mHomeTeam = game.select("td.home").select("div.sb-meta").text();
Elements test = game.select("p.record.overall");
mAwayTeam = game.select("td.away").select("div.sb-meta").text();
mHomeTeamRecord = game.select("td.home").select("div.record-container").select("p.record").text();
mAwayTeamRecord = game.select("td.away").select("div.record-container").select("p.record").text();
mGameStartTime = game.select("span.time").text();
Game newGameObj = new Game(mHomeTeam, mAwayTeam, mGameStartTime, mHomeTeamRecord, mAwayTeamRecord);
mGameList.add(newGameObj);
}
The team win-loss record data is loaded by Javascript in the page. Since Jsoup is an HTML parser this is why it's not displaying tags with the select() method.
However, it seems this data is located inside the page directly in a Javascript object called window.espn.scoreboardData.
Here is how to extract this data:
Document doc = Jsoup.connect("http://espn.go.com/nba/scoreboard/_/date/20160315").get();
for(Element script : doc.select("script")) {
String scriptData = script.html();
if (scriptData.contains("window.espn.scoreboardData")) {
// Parse scriptData to extract team win-loss record ...
}
}

Does mediawiki allow me to make www.site.com/wiki/ the "main page" of the wiki?

...I know how to establish short URLs (using .htaccess) that remove the "index.php" from URLs. Now my Wiki main page URL looks like www.site.com/wiki/Main_page. However, i want it to simply look like www.site.com/wiki/ . Is it possible to do this without heavy modifications to the source code?
Yes, this can be done now. The main trick is to tell MediaWiki what the canonical URL of your main page is. To have the main page in the domain root:
$wgHooks['GetLocalURL'][] = function ( &$title, &$url, $query ) {
if ( $title->isExternal() || $query != '' && $title->isMainPage() ) {
$url = '/';
}
};
See http://laxstrom.name/blag/2015/08/31/mediawiki-short-urls-with-nginx-and-main-page-without-redirect/ for full details.

TYPO3 integrating HTML

I'm newbie at TYPO3, trying to install my custom template.
I have HTML/CSS/IMAGES files, but can't find how to implement it.
Find file /fileadmin/default/templates/typo3-intro-template.html changes on it affects on site. But I can't understand how to use it to show dynamic content.
When I add this:
page = PAGE
page.typeNum = 0
#page.10 = USER
page.10 = TEXT
#page.10.userFunc = tx_templavoila_pi1->main_page
page.10.value = Hello world
to page Setup, got Hello world, but without design.
Is there any way to add something like:
page.10.template = /fileadmin/default/templates/tmy-file.html
?
There are tons of manuals for Typo3. There are 2 choices with templating. Either with Templavoila or with Autoparser. Autoparser is completley scripted and Templavoila uses a graphical interface.
Here's an overview of setting up a site with TemplaVoila: http://webdevelopers.thedemo.ca/
We'll move to fluid in the future, but for now this method is tried and true, and not going anywhere for a while.
I don't like the way fluid uses inline syntax either.
config {
baseURL = http://www.bla.com/
prefixLocalAnchors = all
meaningfulTempFilePrefix=1
doctype=xhtml_trans
htmlTag_langKey=de
remove_defaultJS=external
inlineStyle2TempFile=1
disablePrefixComment = 1
linkVars=L
sys_language_uid=0
language=en
locale_all = en_EN.UTF-8
xmlprologue = none
}
page = PAGE
page.typeNum = 0
page.bodyTag=<body>
page.10=TEMPLATE
page.10 {
template = FILE
template.file = fileadmin/templates/template.html
workOnSubpart = DOCUMENT
subparts {
CONTENT=COA
CONTENT.10<styles.content.get
}
}
template file:
<!-- ###DOCUMENT### -->
<!-- ###CONTENT### -->CONTENT<!-- ###CONTENT### -->
<!-- ###DOCUMENT### -->

Spotify List objects created from localStorage data come up blank

I'm working on a Spotify app and trying to create a views.List object from some stored information in our database. On initial load, a POST is made to get the necessary info. I store this in localstorage so each subsequent request can avoid hitting the database and retrieve the object locally. What's happening though is the List objects I create from localstorage data come up blank, while the POST requests work just fine.
Here is the snippet I'm using to create the list:
var temp_playlist = models.Playlist.fromURI(playlist.uri);
var tempList = new views.List(temp_playlist, function (track) {
return new views.Track(track, views.Track.FIELD.STAR |
views.Track.FIELD.NAME |
views.Track.FIELD.ARTIST |
views.Track.FIELD.DURATION);
});
document.getElementById("tracklist").appendChild(tempList.node);
playlist.uri in the first line is what I'm retrieving either from a POST or from localstorage. The resulting views.List object (tempList) looks identical in both cases except for tempList.node. The one retrieved from localstorage shows these values for innerHTML, innerText, outerHTML, and outerText in console.log:
innerHTML: "<div style="height: 400px; "></div>"
innerText: ""
outerHTML: "<div style="height: 400px; "></div>"
outerText: ""
Whereas the one retrieved via POST has the full data:
innerHTML: "<div style="height: 400px; "><a href="spotify:track:07CnMloaACYeFpwgZ9ihfg" class="sp-item sp-track sp-track-availability-0" title="Boss On The Boat by Tosca" data-itemindex="0" data-viewindex="0" style="-webkit-transform: translateY(0px); ">....
innerText: "3Boss On The BoatTosca6:082....
and so forth..
Any help would be greatly appreciated
Solved this.
I am using hide() and show() to render the tabs in my app. I was constructing the tracklist and then show()ing the div which led to a blank tracklist. If I simply show() the div and then construct the tracklist it works fine.
The reason (I think) it was working for POSTs is because the tracklist was retrieved from the database and the slightly longer loading time probably meant the tracklist was constructed after the div's show() executed. With localStorage I guess the tracklist was constructed before the div was even shown, leading to the error.
Using, the local storage, I did it this way :
sp = getSpotifyApi(1);
var m = sp.require("sp://import/scripts/api/models");
var v = sp.require("sp://import/scripts/api/views");
var pl;
pl = m.Playlist.fromURI(uri);
var player = new v.Player();
player.track = pl.get(0);
player.context = pl;
var list = new v.List(pl);
XXXXX.append($(list.node));
Hope, it will help, as it's working for me
I think I've actually managed to solve this and I think it's bulletproof.
Basically I was trying to solve this by trying to convince the API that it needed to redraw the playlist by hiding things/scrolling things/moving things which worked occasionally but never consistently. It never occurred to me to change the playlist itself. Or at least make the API think the playlist has changed.
You can do so by firing an event on the Playlist object.
var models = sp.require('$api/models');
...
// playlist is your Playlist object. Usually retrieved from models.Playlist.fromURI
playlist.notify(models.EVENT.CHANGE, playlist);
These are just standard Spotify functions and the list updates because it thinks something has changed in the playlist. Hope this helps someone!

AJAX HTMLEditorExtender on postback tables don't display

I am currently using an Ajax tool; HTMLEditorExtender to turn a textbox into a WYSIWYG editor, in a C# ASP.NET project. On the initial page load I place a large amount of formated text and tables into the editor which appears fine; even the tables.
The data is loaded into an asp:panel and the items/display from the panel is what is actually loaded into the extender and displayed.
However, if I want to have a button that saves all of the data that is in the editor to a Session and after the button press still display everything in the WYSIWG editor on the page postback everything that loads in the the textbox is fine except for the tables. They come up with the tags. Is there anyway around this?
The code I am using to initially load the page is this:
ContentPlaceHolder cphMain = (ContentPlaceHolder)this.Master.FindControl("MainContent");
Panel pnlContent = (Panel)cphMain.FindControl("innerFrame");
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter hw = new HtmlTextWriter(sw);
pnlContent.RenderControl(hw);
txtPN.Text = sb.ToString();
pnlContent.Visible = false;
On the button click I am having this saved:
string strHTMLText = txtPN.Text;
Session["ProgressNoteHTML"] = strHTMLText;
And I am loading it on the postback like this:
txtPN.Text = (string)Session["ProgressNoteHTML"];
ContentPlaceHolder cphMain = (ContentPlaceHolder)this.Master.FindControl("MainContent");
Panel pnlContent = (Panel)cphMain.FindControl("innerFrame");
pnlContent.Visible = false;
Any ideas as to why any postbacks would make the tags appear and in the original page load they do not?
The solution offered by Erik won't work for table tags containing property values. For instance: <table align="right"> will not be decoded. I have also found that <img> tags are encoded by the HTMLEditorExtender as well.
The easier solution is to use the Server.HTMLDecode() method.
TextBox_Editor.Text = Server.HtmlDecode(TextBox_Editor.Text) 'fixes encoding bug in ajax:HTMLEditor
I have the same problem, It seems to have something to do with the default sanitizing that the extension performs on the HTML content. I haven't found a way to switch it off, but the workaround is pretty simple.
Write an Anti-Sanitizing function that replaces the cleansed tags with proper tags. Below is mine written in VB.Net. A C# version would look very similar:
Protected Function FixTableTags(ByVal input As String) As String
'find all the matching cleansed tags and replace them with correct tags.
Dim output As String = input
'replace Cleansed table tags.
output = output.Replace("<table>", "<table>")
output = output.Replace("</table>", "</table>")
output = output.Replace("<tbody>", "<tbody>")
output = output.Replace("</tbody>", "</tbody>")
output = output.Replace("<tr>", "<tr>")
output = output.Replace("<td>", "<td>")
output = output.Replace("</td>", "</td>")
output = output.Replace("</tr>", "</tr>")
Return output
End Function