CakePHP HTML Helper: image within a link gets escaped? - php

Updating from Cake 1.2 to 1.3 and I have an image nested in a link element, both generated by the HTML helper. The nested image's markup is however escaped from < to > ect. I know the HTML helper now escapes stuff by default, but I can't get it to change this behavior.
This is the code generating an example image link:
$html->link($html->image('icons/small/navigation-back.gif', array('alt'=>"Move Left", 'border'=>"0"))
,'#',array('id'=>'options_left'), array('escape'=>false))
I added the array('escape'=>false) bit from the official Cake documentation (part of the $options array), but I still get escaped image tags. Is the order set wrong or did more change than I'm aware of? The original code is straight from cake 1.2.

the third parameter is the options array:
$html->link($html->image('icons/small/navigation-back.gif', array('alt'=>"Move Left", 'border'=>"0"))
,'#',array('id'=>'options_left', 'escape'=>false))

Related

PHP mPDF QR-Code: How to control the auto-generated QR-Code-border?

To meet given requirements, we are asked to alter the auto-generated QR-Code-border. We’ve searched a lot for describing resources and tested a view guesses but ended up with no working solution. Our best shot was simply CSS, but it just adds an additional border and does not replace the element’s default one. We’ve also tried border="0" or border="false" within the calling HTML-snippet, but this has no effect on the actual output. Furthermore, we would be interested in adding attributes like line-width & -style, color, border-radius, padding and so on.
Additional info: To create QR-Codes within the UTF-8 coded HTML we use code snippets like:
<barcode code="Text goes here" size="0.8" type="QR" error="M" class="barcode" />
Since v7.0.0 there is a disableborder="1" attribute achieving this.
See Issue #368:
There is currently no way to achieve this with standard mPDF use.
Well…
It's actually a 7-line change in the code allowing use of a disableborder="1" HTML attribute which should make it work as you need. See above.

How to generate a html page from a template and datas

I want to generate some static html files from a template and a large set of datas.
This "set" is an uploaded json (ie a blob that became a file) that I want to read in the generated page using javascript, so I was thinking about inserting it as a string into a <script> tag of the page (something like <script>json=MYJSON</script>, I don't know if it's the best way to achieve this ...).
Now the question is how to copy a file (template) and add/edit a part of it (a tag) in the new file...
It seems that the simplest way is to use copy and give GET parameters to the template wich get it with a php code that echoes the tag .. for example here with a 'name' GET parameter :
copy('http://localhost/site/template.php/?name=' . $name, '../public/new_file.html');
It works fine, but the problem is that I can't pass a large data using this method, so how to achieve this ?

symfony 1.4 interprets and doesnt show html tags using fetchOne() in template

I have the following setup: php 5.4, symfony 1.4.17, and firefox, ie, chrome.
I have built a simple news module.
table: TbNews
columns:
id as primary key
scontent as a text field for saving the news content. It will have html content inside, saved with CKeditor and its working perfectly.
If I use fetchOne() (in template), the html is interpreted before writting the content.
If I use symfony pager (in action, then template) the html is NOT interpreted and I see the HTML tags in the output with the content.
You can see the examples below which shows exactly what Im talking about.
I have read in other topics that for security reasons symfony output escaper automatically converts HTML into "text", and we must use getRawValue on the data to get the original HTML chars.
show html tags in template - symfony and CKEDITOR. how safety?
Stop symfony from escaping html from query result
Symfony.com View Layer Output Escaping
Symfony sfOutputEscaper method getRawValue()
I have some questions:
why symfony output escaper is working with symfony pager, and its
not working if we use fetchOne()?
how should I use getRawValue() in my example below with the symfony
pager, interpreting the HTML and then showing only the content?
Is getRawValue() the best option to get only the content written?
Example code:
//1. fetchOne() outputs content interpreting html before.
//index/templates/indexSuccess.php
//-------------------------------
$q = Doctrine_Query::create()->from('TbNews e')->where('e.id = ?', '1');
$new = $q->fetchOne(); // <p>testcontent</p>\r\n
echo $new['scontent'];
// output: testcontent --- OK, output is not escaped because we are jumping symfony output escaper since we are doing it directly in the action.
//2. Get all news with symfony pager, html tags are not interpreted, html tags are shown.
//index/actions/actions.class.php
//-------------------------------
$app_max_news_in_homepage = 4;
$this->pager = new sfDoctrinePager('TbNews', $app_max_news_in_homepage);
$this->pager->setQuery(Doctrine::getTable('TbNews')->createQuery('a'));
$this->pager->setPage($request->getParameter('page', 1));
$this->pager->init();
//index/templates/indexSuccess.php
//--------------------------------
foreach ($pager->getResults() as $new)
{
echo $new['scontent']; // <p>testcontent</p>\r\n
}
//output: <p>testcontent</p> --- OK, since output is escaped by symfony output escaper since we get data at the action and show it in the template.
Your first test is wrong.
When you test with fetchOne(), you are inside an action. So the content you retrieve from your database and the one you displayed (with echo) isn't escaped because it's not send to the template.
When you perform your second test, you retrieve the content from the action and display the result inside the template. In this case, the content is escaped by sfOutputEscaper. If you make the first test and then try to display the content in your template, you'll see that the html is escaped.
// in actions
$this->new = $q->fetchOne();
// in template
echo $new['scontent'];
// result-> <p>testcontent</p>\r\n
If you have activated escaping_strategy & escaping_method inside your apps/[app_name]/config/settings.yml, every thing that will be given to the template will be escaped.
When I want to display a html content which has been escaped, I usually use the unescape method from the sfOutputEscaper. In your case:
foreach ($pager->getResults() as $new)
{
echo sfOutputEscaper::unescape($new['scontent']);
}
another option (said by Michal Trojanowski):
foreach ($pager->getResults()->getRawValue() as $new)
{
echo $new['scontent'];
}

How can LiveDocx in PHP be used to read .doc & .docx files and read text inside it and save to HTML?

Let's say we have a .doc & .docx files. I want to use LiveDocx in PHP to load the files, read it's content and strip the text from inside it. Then save it to an HTML string.
Can this be done?
I've searched the documentation, and it seams that LiveDocx only loads .doc & .docx template files only!
You can save using external libraries and simply grab the text from the XML within the files:
http://www.webcheatsheet.com/PHP/reading_the_clean_text_from_docx_odt.php
I think you can find what you need in this example.
I might be wrong, but I think they call them "template" files because they act like a template but are still normal .doc/.docx documents. I suggest you simply try to run that example.
I think you can use TextControl that improves phpLiveDocx TextControl link
Using this you can also import pdf doc and docx
When you do document conversion on LiveDocX, you need to do a mailmerge and then retrieve the document. Even though you aren't inserting any new content, you need to do a mailmerge that replaces a dummy placeholder with dummy content.
So, the process I'd suggest is:
1) Set your source document as local template
2) Merge a dummy field with dummy content
3) Retrieve your document as HTML
4) Use a script server side to remove the html and leave only the content (Something like, remove everything between the HEAD tags, then strip_tags on the rest)
5) You should be left with your content as a simple string - I'm not sure it'll be too meaningful, but might be useful for building something like search indices.

Outputting image using php GD library via function call

I know that I can output an image using GD by using
<img src='draw.php'>
Where draw.php is a file containing the code to create an image. How can I instead output the image via a function call (I am using the Zend Framework so will be using a View Helper) rather than simply pointing to a .php file in an img tag as above?
Any help greatly appreciated.
you can't.
at least not in a useable way - you could encode the image with base64:
<img src="data:image/png;base64,iVBORw0KGgoAAAANS..." alt=""/>
i don't have any idea which browsers support this, though ... quick test:
firefox: ok
chrome: ok
opera: ok
ie6: fail
ie7: fail
safari: fail
ok, forget it.
but, you're probably trying to do something different - passing the file through ZF. i can't help you with that, but it should work roughly like this:
in your controller, set the output type to image/png (however ZF handles that) pass through your image and make sure ZF doesn't add anything to the output (like additional html and stuff).
Why not make your View Helper create an image, write it to disk, and then output/return the img tag with the correct source attribute?
Send appropriate headers (content type) and then use http://www.php.net/image_jpeg

Categories