Grab text only from Wordpress website, display on iOS app - ios

Is there any way I can grab only the title, author, date, and text from a Wordpress website's article through its RSS feed? I'm trying to create an iOS app (Xcode) that can display this information.
EDIT:
I am currently using rshankras' BlogReader code to fetch articles from the website, but it displays the actual link to the page. I'm looking to be able to access the article's title, author, date, and text, and be able to format it myself, instead of having the actual site show up. What tools can I use to do this, if feasible?
This is the website in question.

You are using a ready-made app so I think, you will have to modify it yourself to serve your purpose. For showing content as you want, you need to manipulate the HTML content instead of viewing it in WebView.
Inside your app, the WebView element is in PostViewController.swift file. So if your put the following code in line number 24 of that file, you will get the URL that is being requested.
println(url)
This code prints the output in console. Now as you know the url. You can simply fetch the HTML Code and manipulate and show it as your heart want using the following way:
let pageurl = NSURL(string: url) //you got the url variable 3 lines above
let task = NSURLSession.sharedSession().dataTaskWithURL(pageurl!) {
(data, response, errror) in
if error == nil {
var urlContent = NSString(data: data, encoding: NSUTF8StringEncoding) as NSString!
println(urlContent)
}
}
This will print the full HTML Code string encoded using UTF-8.
Now in the postViewController, instead of using WebView element, you can use a label, or textbox or whatever you want to show your content inside. Then create an outlet for that element. And then manipulate the HTML Code String by following way:
var urlContentArray = urlContent?.componentSeparatedByString("<span class=\"storybyline\">") // In your website (vikinglogue.com) your author name is inside this span element.
println(urlContentArray[1]) // This will print everything after that span section in your console
var authorArray = urlContentArray[1].componentSeparatedByString("</span>")
var author = authorArray[0]
Now you have the author name and you can show it in any textbox or label or in any element that support text. You can grab all other info from that page in the same way. I hope it helped.

Since RSS comes in a structured XML format, you can simply fetch your page's rss feed and parse the elements for the needed data. To see some how to code, you may check out mwaterfalls' Feedparser
e.g
<title>Girls softball dominating early</title>
<link>
http://vikinglogue.com/2377/sports/girls-softball-dominating-early/
</link>
<comments>
http://vikinglogue.com/2377/sports/girls-softball-dominating-early/#comments
</comments>
<pubDate>Wed, 22 Apr 2015 21:54:32 +0000</pubDate>

Related

Styling a vaadin Component (Dialog) with CSS file

I have a Dialog that retrieve informations from an endpoint (String of information) but I have a Problem with style this dialog, because all these informations appear untidily!
For example to be clear, I have this endpoint, that it helps me to retrieve a Data about Mobile, and want to show this Data in a Dialog (BUT the Style should like Screenshot Nr. 1), but my Problem is that the data appears as Preview (Screenshot 2).
You can use the Html component with a pre tag where you put the formatted JSON:
Html pre = new Html("<pre>" + formattedJson + "</pre>");
To format the JSON String you can use this:
String prettyJson = mapper.writerWithDefaultPrettyPrinter()
.writeValueAsString(mapper.readTree(inputJson));
Find more examples here: https://roytuts.com/how-to-pretty-print-json-in-java/

pdf.js rendering as PDF with base64

I am stuck at last point of my application, i am supposed to display user form in PDF which works fine on desktop browsers as they has pdf viewer built in, but for Android / iOS its not working as pdf viewer is missing.
So i was trying to use PDF.js to display it, (to be honest, this is very widely used but documentation is lacking), only catch is i am getting data in base64 format. PDF.js has example on site which shows how to render the base64 data but its not PDF, for that displaying PDF as "PDF" i need to user their "viewer.html" but that does not take base64 data?
closest i have come to Pdf.js: rendering a pdf file using base64... on stack overflow, but i dont know how to use it after PDFJS.getDocument(pdfAsArray)?.
Other link that came across was other link
I dont want to rely on Google / Third party PDF viewer as i dont know how long they will support this.
There are no end-to-end answers on this topic in community so here is my attempt to put something here. (maybe it will help others)
Okay, PDF.js is one way of showing PDF in browser, specially when you don't want to rely on PDF plugin to be installed. In my case, my application generates report in PDF and that can be viewed before downloading but on handheld devices it was not working because of missing PDF viewer plugin.
In my case PDF was sent to browse in base64 string, that I can use to display PDF with <object src="base64-data"...></object>. This works like charm on Chrome / FF but switch to mobile view and it stops working.
<object type="application/pdf" id="pdfbin" width="100%" height="100%" title="Report.pdf">
<p class="text-center">Looks like there is no PDF viewer plugin installed, try one of the below approach...</p>
</object>
In above code it will try to show the PDF or fall back to <p> and show error message. And I Was planning to add the PDF viewer at this point, PDF.js was the choice but was not able to display it. One example on PDF.js with Base64 data shows how to do this but that renders it as an Image not PDF, and I was not able to find solution for that and hence the question, here is what I did,
First add the JavaScript code to convert base64 to array
convert to blob and use viewer.html file packaged with PDF.js to display it as PDF
In case if you are wondering why base64 data, then answer is simple I can create the PDF, read it, send the data to client and delete the file, I don't have to run any cleaner service/cron job to delete generated PDF files
Few Things To Note
Below code is using Flask + Jinja2, change the way base64 is read in html if you are using something else
viewer.html needs to be changed to have required js & css files in proper location (by default their location is relative; you need them to be referred from static folder)
viewer.js looks for pdf.worker.js in predefined location, change that in case its throwing error as above file not found.
viewer.js might throw file origin does not match viewer error in that case as a quick fix comment the code which throws this error and see if that solves the issue (look for that error in viewer.js)
I am not the author of below code, I have just put it together from different places.
Now to the code (so PDF will be displayed when user clicks on button with id="open_id")
Jquery
var pdfDataX = '{{ base64Pdf }}';
var BASE64_MARKER = ';base64,';
PDFJS.workerSrc = "{{ url_for('static', filename='js/pdf.worker.js') }}";
$('#open_id').click(function() {
PDFJS.disableWorker = true;
var pdfAsDataUri = "data:application/pdf;base64," + pdfDataX ;
PDFJS.workerSrc = "{{ url_for('static', filename='js/pdf.worker.js') }}";
// Try to show in the viewer.html
var blob = base64toBlob(pdfDataX, 'application/pdf');
var url = URL.createObjectURL(blob);
var viewerUrl = "{{ url_for('static', filename='viewer.html') }}" + '?file=' + encodeURIComponent(url);
$('#pdfViewer').attr('src', viewerUrl);
// Finish
var mdObj = $('#pdfbin');
mdObj.hide();
mdObj.attr('data', pdfAsDataUri);
mdObj.show();
$('#myModal').modal();
});
var base64toBlob = function(b64Data, contentType, sliceSize) {
contentType = contentType || '';
sliceSize = sliceSize || 512;
var byteCharacters = atob(b64Data);
var byteArrays = [];
for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
var slice = byteCharacters.slice(offset, offset + sliceSize);
var byteNumbers = new Array(slice.length);
for (var i=0; i<slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}
var byteArray = new Uint8Array(byteNumbers);
byteArrays.push(byteArray);
}
var blob = new Blob(byteArrays, {type: contentType});
return blob;
}
$('.save').click(function(e) {
e.preventDefault();
var blob = base64toBlob(pdfDataX, 'application/pdf');
saveAs(blob, 'abcd.pdf'); // requires https://github.com/eligrey/FileSaver.js/
return false;
});
HTML
<object type="application/pdf" id="pdfbin" width="100%" height="100%" title="Resume.pdf">
<p class="text-center">Looks like there is no PDF viewer plugin installed, try one of the below approach...</p>
<iframe id="pdfViewer" style="width: 100%; height: 100%;" allowfullscreen="" webkitallowfullscreen=""></iframe>
</object>
Hope this will be useful for others in future.

typo3 tsconfig url parameters media

We are using Typo3 7.6.
We use a simple text and media Element to embed youtube videos.
Those youtube video-embed links do need paramters (like rel=0), but I see no option to imput them and I do not find any typoScript where I can set those parameters in any help. Putting the paramters directly into the URL that I enter in the element does not work, merely the ID is parsed.
Is there a simple way to do this?
You need to set buttons.link.queryParametersSelector.enabled to true in your page TS-Config.
To do this edit your rootpage(normally id=1) and go to tab Resources.
Fill in the following code to the field Page TSConfig.
RTE.default.buttons.link.queryParametersSelector.enabled = 1
After saving you should see an additional field called "Additional link parameters" when you use the link wizard.
Reference: EXT: rtehtmlarea -> buttons.link.queryParametersSelector.enabled
I assume you use fluid styled content? If so, the gallery processer could be configured via TypoScript setup like this:
lib.contentElement.settings {
media {
additionalConfig {
no-cookie = 1
modestbranding = 1
relatedVideos = 0
showinfo = 0
}
}
}

Extract first url or image from a webpage in objective c

Is there a way to extract any link from the URL of the page and open it in UIWebView.
I already know how to display a webpage on ios screen:
[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http:google.com]]]
Example: Suppose a string is given by the user "ABC". The code I want to write should search say "ABC" in google and open the first link that it shows. <- This all to be done automatically. All that user care is give the input string.
Please help regarding the procedure and steps one should follow.
Thanks
If I undestood what you want, you can load the url content into a string
[NSString stringWithContentsOfUrl: [NSURL URLWithString:#"http://mydomain.com"] encoding: NSUTF8StringEncoding error: nil];
and after that you need to know the html struct to extract the link (result) that you want. Eg: for google, you can find a div <div id="ires"> that has ol and li elements that contains the links. So you just load the webview content with the result link, like you said above.

How to extract the headline and content from a crawled web page / article?

I need some guidelines on how to detect the headline and content of crawled pages. I've been seeing some very weird front-end codework since i started working on this crawler.
You could try the Simple HTML DOM Parser. It sports a syntax to find specific elements similar to jQuery.
They have an example on how to scrape Slashdot:
// Create DOM from URL
$html = file_get_html('http://slashdot.org/');
// Find all article blocks
foreach($html->find('div.article') as $article) {
$item['title'] = $article->find('div.title', 0)->plaintext;
$item['intro'] = $article->find('div.intro', 0)->plaintext;
$item['details'] = $article->find('div.details', 0)->plaintext;
$articles[] = $item;
}
print_r($articles);

Resources