Replace bbcode to HTML in PHP - html

For several weeks I learn a lot from this site.
Now I search for hours for a tip but can not find it and I decided to post a question.
I want an image from bbcode filter and a style as I add, but I do not know how to do this.
Who can tell me how can in chage this:
[attach=news-ZmAk6khfk0.jpg align=left title=title width=500 height=500 rel=rel]<br />
De formatie van Rutten creëerde in het eerste bedrijf geen uitgespeelde kansen. Vanuit de tweede lijn vielen een paar schoten te noteren. Dries Mertens en Tim Matavz hadden het vizier niet op scherp staan.
To this:
<img src=news-ZmAk6khfk0.jpg align=left title=title width=500 height=500 border=0 class=footblocks/>

Take a look at the PEAR package BBCode Parser 2. It's an excellent tool that will save you hours.
Edit: PECL also has one similar to the PEAR version: BBCode Parser

Related

How can I make text in a marquee element to scroll continuously?

I have a the next marquee element:
<marquee height="450px" class="quotes" behavior="scroll" direction="up" scrollamount="2">
Sal ahí fuera y prueba diferentes cosas hasta que descubras donde dan resultado tus talentos,
intereses y prioridades<br /><br />
The best founders get things done every time. Small chunks at a time.<br /><br />
Tienes que amar la idea en cuestión, tienes que sentir pasión por ella, si no, te pondrás contra las
cuerdas todos los días.<br /><br />
People can dismiss your start-up but you never can.<br /><br />
You cant build Twitter looking for it. Make something unsexy people will pay for.<br /><br />
Las ideas que parecen malas son las mejores, ya que no hay gente trabajando en ellas.<br /><br />
Intensity→ you can't have other hobbies.<br /><br />
Lo mejor es ir a por un mercado pequeño pero en crecimiento y expandirse desde ahí.
</marquee>
The text start from bottom and scroll to top, once the last text line appears, doesn't appear any other until this reach the top.
I want my text to start in the top and scroll up, also when the last quote appears, I don't want to wait until this to reach the top to see the first one, I want no space between them.
Is this possible?
Thanks in advance!

Trouble in converting PCRE Regex to sed

I'm running into trouble on how to use a working PCRE regex in sed. I found a related topic, but unfortunately it's not working for me (I'm working on Linux not MacOS X if that should be necessary information).
I have some HTML code of which I need a special part - however not between the same tags. The regex I have is working according to some regex testing sites (like regex101 or regexr.com), however, when trying to use it on sed, it shows me the whole file instead of the wanted part.
My regex is:
/((<div id="main-content" class="wiki-content">)([\w\d\s\S]*))(<\/rdf:RDF>\n-->)/g
It grabs a part starting with the specific div and collects everything including the following RDF part.
The text I'm working with looks (with the interesting part - the rest around I cut due to length and also this part only appears once the file) as follows (inlcuding the gaps):
[...]
a href="#page-metadata-start" class="assistive">Go to start of metadata</a>
<div id="page-metadata-end" class="assistive"></div>
<div id="main-content" class="wiki-content">
<p><br/></p><p><br/></p><div class="panel conf-macro output-block" data-hasbody="true" data-macro-name="panel" style="border-color: #004237;border-width: 1px;"><div class="panelHeader" style="border-bottom-width: 1px;border-bottom-color: #004237;background-color: #004237;color: white;"><b>Inhalt</b></div><div class="panelContent">
<p> </p><div class="toc-macro client-side-toc-macro conf-macro output-block" data-hasbody="false" data-headerelements="H1,H2,H3,H4,H5,H6,H7" data-macro-name="toc"> </div><p> </p>
</div></div><h1 id="id-01-Dokumentation-1EinstiegindiePlanung">1 Einstieg in die Planung</h1><p><br/></p><h2 id="id-01-Dokumentation-1.1Startseite">1.1 Startseite</h2><p>Nach der Anmeldung im System findet sich der User auf der Startseite wieder. Von hier aus gelangt er zur "Planning Map".</p><p>Durch das Umschalten der Company auf die Counter Company kann der Planer die zuvor eingetragenen Werte kontrollieren. Diese erscheinen nach dem Umschalten in der zweiten<br/>Tabelle als negativer Wert auf dem gemappten IC Account.</p><p><br/></p><div class="table-wrap"><table class="wrapped confluenceTable"><colgroup><col/><col/><col/></colgroup><tbody><tr><th class="confluenceTh">Button</th><th class="confluenceTh">Aktion</th><th class="confluenceTh">Beschreibung</th></tr><tr><p>Alle Eintragungen werden auf der untersten Ebene (weißer Hintergrund) ausgeführt. Monate, die nicht mehr beplant werden können sind farblich hinterlegt. Ebenfalls farblich hinterlegt sind<br/>die Accounts, die hier nicht beplant werden können (IC / Capex und Rule belegte Accounts).</p><p><br/></p><div class="table-wrap"><table class="wrapped confluenceTable"><colgroup><col/><col/><col/></colgroup><tbody><tr><th class="confluenceTh">Button</th><th class="confluenceTh">Aktion</th><th class="confluenceTh">Beschreibung</th></tr><tr><td colspan="1" class="confluenceTd">Back</td><td colspan="1" class="confluenceTd">Sheet Wechsel</td><td colspan="1" class="confluenceTd">Zurück zum Sheet Planning Map</td></tr><tr><td colspan="1" class="confluenceTd">Refresh</td><td colspan="1" class="confluenceTd">Prozess ausführen</td><td colspan="1" class="confluenceTd">Sheet wird nochmals neu aufgebaut</td></tr></tbody></table></div>
</div>
<!--
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<rdf:Description
rdf:about="https://confluence.example.org/confluence/display/KUN/01+-+Dokumentation"
dc:identifier="https://confluence.example.org/confluence/display/KUN/01+-+Dokumentation"
dc:title="01 - Dokumentation"
trackback:ping="https://confluence.example.org/confluence/rpc/trackback/47022143"/>
</rdf:RDF>
-->
[...]
So when I try this regex on the mentioned test websites, it marks the part I need (between <div id="main-content" class="wiki-content"> and </rdf:RDF>\n-->).
But when using sed -r '/((<div id="main-content" class="wiki-content">)([\w\d\s\S]*))(<\/rdf:RDF>\n-->)/g' testfile.txt it shows me the complete file content instead only the part I'm looking for (sed -E... produces the same).
I can't work out, where my problem is, so any help would be very much appreciated. Also, I'm not a professional regex user...
I'm not sure about how it will work in your case, as I need probably some more data, but this one could work for you:
sed -ne '/<div id="main-content" class="wiki-content">/,/-->/{p}' file.html

How to process JSON-deliverd HTML-text into formatted UITextView

I'm trying to create my first IOS app and run into problems when creating the view. The app shows info that I get from a JSON file. The JSON contains formatted text in HTML style. Within this html text there are one or more photos. In the app I want these photos to be shown above the text (each photo shown for some seconds). The photos are separate items in the JSON as well so I really don't need the reference in the HTML text. I want the photo and the text to be scrollable in case it does not fit on the screen.
I've tried the following: Removed the href tags from the HTML text and shown the text in a UIWebView. Above the text I showed the photos in a UIImageView. The text was scrollable instantly, but the photos weer always visible.
So now I think I should use UITextview. But how do I get the formatting that's in the HTML text transferred to a formatted UITextView? Or am I missing something?
The HTML text looks something like this:
<p>ik was de afgelopen dagen voor het eerst van mijn leven in de Duitse stad Keulen. Bepakt met een frisse blik zitten we nu in de ICE die ons terug brengt naar Amsterdam. Hoog tijd om die blik te delen!<br \/>\n<a href=\"http:\/\/www.blablablog.nl\/wp-content\/uploads\/IMG_8259.jpg\"><img src=\"http:\/\/www.blablablog.nl\/wp-content\/uploads\/IMG_8259.jpg\" alt=\"\"><\/a> <\/p>\n<p><b>De ICE<\/b><\/p>\n<p>Eerst maar ‘s beginnen met die hogesnelheidstrein. Hij stopt weinig en da’s een voordeel. De stoelen zitten lekker en er rijdt een bistrowagen mee, maar echt snelheid maken doet hij pas na Keulen dus als je net als ik onvoorbereid op dat moment wacht kom je bedrogen uit.<br \/>\n <a href=\"http:\/\/www.blablablog.nl\/wp-content\/uploads\/IMG_8248.jpg\"><img src=\"http:\/\/www.blablablog.nl\/wp-content\/uploads\/IMG_8248.jpg\" alt=\"\"><\/a> <\/p>\n<p><b>De inwoners<\/b>
You can just use UIWebView for that and initialize it with the html string. This way everything is taken care of automatically.
If you format the HTML properly you won't have issues with scrolling.

How to translate Trac custom content added with site.html?

We have customized our Trac instance to display additional content to the newticket page, with the following site.html file (as explained in documentation):
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://genshi.edgewall.org/"
py:strip="">
<form py:match="div[#id='content' and #class='ticket']/form[#action='/newticket#ticket']" py:attrs="select('#*')">
<div class="warning">
<p>You are about to create a new JOSM ticket.
</p>
<p>Please make sure to always use this link in About Dialog (Shift-F1) to come here:</p>
<img src="raw-attachment/wiki/Help/Action/About/bugreport_small.png" alt="Bug report link in About dialog" height="53" width="361" />
<p>Clicking on this link prefills the bug report with useful information for us (Status Report).
</p>
<p>In any case, don't be shy :) Please let us a way to contact you if needed (either by creating an account or entering your e-mail address below (it won't be publicly visible but will allow us to reach you, and you will be notified about ticket progress).
</p>
</div>
${select('*')}
</form>
</html>
I don't see anything in the documentation about translation. How can we translate this text now?
Unfortunately this is not easy until something like the proposal for custom labels has been realized.
Currently it requires adding your additional msgids to Trac core PO files and recompiling and installing that custom Trac version - quite ugly and not remotely as modifiable as the template.
Providing custom translations within a plugin would not be effective, because plugin translations would reside in a translation domain, that is not evaluated for Trac core templates like the (new) ticket page.
I have finally come up with a small JavaScript solution.
It's simple when you only need a few languages with a text that doesn't change:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://genshi.edgewall.org/"
py:strip="">
<form py:match="div[#id='content' and #class='ticket']/form[#action='/newticket#ticket']" py:attrs="select('#*')">
<div class="warning">
<table style="border:0; border-collapse:separate; border-spacing:0 10px" class="wiki">
<tr><td style="background:#FFFC75; border:1px solid #ccc; border-right:0" valign="top">
<p id="josm_warning_01">You are about to create a new JOSM ticket.
</p>
<p id="josm_warning_02">Please make sure to always use Help/Report bug or this link in About Dialog (Shift-F1) to come here:</p>
<img src="raw-attachment/wiki/Help/Action/ReportBug/reportbug.png" alt="Bug report menu entry" height="84" width="207" />
<img src="raw-attachment/wiki/Help/Action/About/bugreport_small.png" alt="Bug report link in About dialog" height="53" width="361" />
</td></tr>
</table>
</div>
<script type="text/javascript">
if (navigator.language.indexOf('fr') == 0) {
document.getElementById("josm_warning_01").innerHTML = 'Vous êtes sur le point de créer un nouveau ticket JOSM.';
document.getElementById("josm_warning_02").innerHTML = 'S\'il vous plaît, assurez-vous de toujours utiliser Aide/Rapporter un bug ou ce lien dans la fenêtre À propos (Shift-F1) pour venir ici:';
} else if (navigator.language.indexOf('de') == 0) {
document.getElementById("josm_warning_01").innerHTML = 'Sie sind dabei, ein neues JOSM-Ticket zu erstellen.';
document.getElementById("josm_warning_02").innerHTML = 'Bitte nutzen Sie immer Hilfe → Fehler melden oder diesen Link im "Über JOSM..."-Fenster, um hierher zu gelangen:';
}
</script>
${select('*')}
</form>
</html>

What is this encoding and how can I convert in UIWebView

I would like to know how to get my UIWebView to show these characters correctly. The image below is a snapshot of my UIWebView, showing some European language characters are not displaying correctly. I looked at the original web page that this was presented on, and the characters are correct. I suspect there are some meta tags that need to be set in the HTML head used in my UIWebView. but I'm not sure what they would be. Both the original web page and my own HTML are encoded with UTF-8 like this:
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
This should be:
Pour sa première exposition à la Inception Gallery, Christine Barbe
affiche une maturité dans son expérimentation en photographie et en
vidéo. Elle témoigne d'une nouvelle réflexion profonde liée à notre
condition d'humain au sein de notre environnement et à celle de
l'intervention du corps dans l'imprégnation de cet environnement.
...
The data is UTF-8 encoded but UIWebView is interpreting it as if it were ISO-8859-1. This is what makes e.g. “è” rendered as “è”.