How to keep Zend_Debug HTML tags out of Zend_Log - zend-framework

I use Zend_Debug::dump to dump variables into a Zend_Log file. How can I get it to stop wrapping the output in HTML tags?
The documentaion says "If the output stream is detected as a web presentation, the output of var_dump() is escaped using ยป htmlspecialchars() and wrapped with (X)HTML tags." Why does it think my log file is a web presentation?
The method for the dump function has a boolean $echo flag. Even when this is FALSE, I get HTML markup in my log files.
Thanks for you help!

Zend Debug is always using htmlspecialchars() to quote. You cant disable this by an provided parameter.
The boolean for "echo" is only used to disable the var_dump() (wich is used in Zend_Debug) printing to the browser.
Code from Zend_Debug::dump():
$output = htmlspecialchars($output, ENT_QUOTES);
if (self::getSapi() == 'cli') {
$output = PHP_EOL . $label
. PHP_EOL . $output
. PHP_EOL;
} else {
if(!extension_loaded('xdebug')) {
$output = htmlspecialchars($output, ENT_QUOTES);
}
$output = '<pre>'
. $label
. $output
. '</pre>';
}

Related

Laravel, how to use form helper outside blade?

For some reason I have to write HTML::macro() to return HTML tags.
HTML::macro('myMycro', function()
{
$result = '<form id="xxx">...';
return = $result;
}
then I can use the HTML::myMacro() inside my blade.
{{ HTML::myMacro() }}
Is it possible to use form helper Form::open(), Form::input() to generate HTML tags inside the macro so I don't have to manually write tags???
If so, please suggest me how to do it because of my poor background in PHP and Laravel, I just simply tried
...
$result = Form::open('some_parameters');
...
But I didn't work, I don't know can I use form helper outside blade or not, so please advise me.
Thanks.
I dont see any reason why not.
This works like a charm
Form::macro('myForm', function()
{
$output = Form::open(['url/to/post']);
$output .= Form::text('firstName');
$output .= Form::close();
return $output;
});
// Then use in in regular PHP view...
echo Form::myForm();
// ... or even Blade view
{{ Form::myForm() }}

Joomla setRedirect doesn't work

I have a simple Joomla controller, but I can't redirect anything.
According to the documentation:
class MyController extends MyBaseController {
function import() {
$link = JRoute::_('index.php?option=com_foo&ctrl=bar');
$this->setRedirect($link);
}
}
//The url contains & html escaped character instead of "&"
This should work, but I get a malformed URL. Is there something I'm missing here? Why is Joomla converting all the "&" characters into &'s? How am I suppose to use setRedirect?
Thank you
Alright, I fixed it. So if anyone needs it:
instead of
$link = JRoute::_('index.php?option=com_foo&ctrl=bar');
$this->setRedirect($link);
use
$link = JRoute::_('index.php?option=com_foo&ctrl=bar',false);
$this->setRedirect($link);
to make it work.
Glad you found your answer, and by the way, the boolean parameter in JRoute::_() is by default true, and useful for xml compliance. What it does is that inside the static method, it uses the htmlspecialchars php function like this: $url = htmlspecialchars($url) to replace the & for xml.
Try this.
$mainframe = &JFactory::getApplication();
$mainframe->redirect(JURI::root()."index.php?option=com_foo&ctrl=bar","your custom message[optional]","message type[optional- warning,error,information etc]");
After inspecting the Joomla source you can quickly see why this is happening:
if (headers_sent())
{
echo "<script>document.location.href='" . htmlspecialchars($url) . "';</script>\n";
}
else
{
... ... ...
The problem is that your page has probably already output some data (via echo or some other means).
In this situation, Joomla is programmed to use a simple javascript redirect. However, in this javascript redirect it has htmlspecialchars() applied to the URL.
A simple solution is to just not use Joomlas function and directly write the javascript in a way that makes more sense:
echo "<script>document.location.href='" . $url . "';</script>\n";
This works for me :)
/libraries/joomla/application/application.php
Find line 400
// If the headers have been sent, then we cannot send an additional location header
// so we will output a javascript redirect statement.
if (headers_sent())
{
echo "<script>document.location.href='" . htmlspecialchars($url) . "';</script>\n";
}
replace to
// If the headers have been sent, then we cannot send an additional location header
// so we will output a javascript redirect statement.
if (headers_sent())
{
echo "<script>document.location.href='" . $url . "';</script>\n";
}
This works!

Zend_Navigation rendering submenu with partial

I've posted an edit to my question. While working on it I noticed the problem is easy to simplify.
I need a custom format of my submenu so i have to use partial. But then the problem occurs.
The below code shows the INCORRECT level (0):
echo $this->navigation()->menu()
->setMinDepth(1)
->setMaxDepth(1)
->setRenderParents(false)
->setOnlyActiveBranch(true)
->renderPartial(null, array('partials/menu.phtml', 'default'));
The below code shows the CORRECT menu level (1)
echo $this->navigation()->menu()
->setMinDepth(1)
->setMaxDepth(1)
->setRenderParents(false)
->setOnlyActiveBranch(true)
->render();
Any ideas? Guys please. I would appreciate any help!
Edit
My partials/menu.phtml:
foreach ($this->container as $page)
{
$active = $page->isActive();
echo '<div class="item">';
echo '<a class="'. ($active ? 'active' : '') .'" href="' . $this->baseUrl($page->getHref()) . '">' . $page->getLabel() . '</a>';
echo '</div>';
}
EDIT 2
My understanding of Zend_Navigation was, first to prepare container and than put it through partial.
$nav = $this->navigation()->menu()->setOnlyActiveBranch(true)->getContainer();
echo $this->navigation()->menu()->renderPartial($nav, array('/partials/menu.phtml', 'default'));
What is the point of setting set{Min/Max}Depth, parentRendering at the container when passing it anywehere is useless?
I use this code:
<?=$this->navigation()->menu()->renderPartial(null, 'shared/menu.phtml')?>
you should pass true to the method $page->isActive(true) so that also functions in depth.
in your partial
foreach ($this->container as $page) {
$active = $page->isActive(true);
if (count($page->getPages())) {
foreach ($page->getPages() as $subPage) {
$active = $subPage->isActive(true);
echo '<div class="item">';
echo '<a class="'. ($active ? 'active' : '') .'" href="' . $this->baseUrl($subPage->getHref()) . '">' . $subPage->getLabel() . '</a>';
echo '</div>';
}
}
}
before the second foreach you could add a check if and when to show the submenu.
my 2 cent.
EDIT
try this:
$partial = array('partials/menu.phtml', 'default');
echo $this->navigation()->menu()
->setMinDepth(1)
->setMaxDepth(1)
->setRenderParents(false)
->setOnlyActiveBranch(true)
->setPartial($partial)
->render();
Came across this while searching for an answer to the same problem. Having looked through the code for Zend_View_Helper_Navigation_Menu, it doesn't look like any of the view helper options are passed through to the view partial, although I don't see why they couldn't be... (in ZF 1.12 take look a line 736 of Zend_View_Helper_Navigation_Menu, the only thing passed is the container itself, the options array could easily be passed along with it, or the container prefiltered, may be worth filing a feature request with ZF)
These options are purely a way of filtering the Zend_Navigation_Container for rendering with the default renderMenu method. As you say, it seems you can accomplish the same thing by first filtering the container and then passing it as the first argument of the renderPartial method
In your main view
Find the container of the submenu located in navigation config. Then echo this container using said partial.
$pages = $this->navigation()->findOneBy('label', 'Label of your submenu');
echo $this->navigation()->menu()->renderPartial($pages,module/partials/menu.phtml');
In the partial (module/partials/menu.phtml)
Customise. This example iterates over the top level pages of your chosen container.
foreach ($this->container as $page) {
echo $this->navigation()->menu()->htmlify($page) . PHP_EOL;
}

Displaying images in atom feed

I have problems with displaying images in atom file. It doesn't include images in feed in google reader, opera or firefox.
As a starting point I did everything like in Listing 6. at [An overview of the Atom 1.0 Syndication Format] But it doesn't work.
Update
It is not problem with hotlink protected images. Described here: How to display item photo in atom feed?
Later I changed feed according to description posted here.
I added:
<media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="path_to_image.jpg" />
But still it doesn't work
I had the same problem when trying to include images as enclosure, but it seemed that the easiest way for me was to include the image with the normal img tag to the html content.
(It's also wrapped in CDATA, which might affect the way Google Reader handles the content. I haven't tried without.)
The following example works for me to make atom feed images visible in Google Reader:
<content type="html">
<![CDATA[
<a href="http://test.lvh.me:3000/listings/341-test-pics?locale=en">
<img alt="test_pic" src="http://test.lvh.me:3000/system/images/20/medium/test_pic.jpg?1343246102" />
</a>
]]>
</content>
Wordpress uses the metafield enclosure to set the medias. This is the correct tag according to RSS specification. I have seen people suggest using media:content but if using that make sure to set the XML namespace for it.
Unfortunately due to some dodgy Wordpress code you can not set this dynamically. (Wordpress gets all metafields and then loops through them instead of calling the enclosure directly)
You can set the enclosure on save post. It should be an array with entries of the form "$url\n$length\n$type"
If you want to add the enclosure tags yourself you can do the following:
RSS
add_action( 'rss2_item', 'hughie_rss2_item_enclosure' );
function hughie_rss2_item_enclosure():void
{
$id = get_post_thumbnail_id();
$url = wp_get_attachment_url($id);
$length = filesize(get_attached_file($id));
$type = get_post_mime_type($id);
echo apply_filters( 'rss_enclosure', '<enclosure url="' . esc_url( $url ) . '" length="' . absint( $length ) . '" type="' . esc_attr( $type ) . '" />' . "\n" );
}
ATOM:
add_action( 'atom_entry', 'hughie_atom_entry_enclosure' );
function hughie_atom_entry_enclosure():void
{
$id = get_post_thumbnail_id();
$url = wp_get_attachment_url($id);
$length = filesize(get_attached_file($id));
$type = get_post_mime_type($id);
echo apply_filters( 'atom_enclosure', '<link rel="enclosure" href="' . esc_url( $url ) . '" length="' . absint( $length ) . '" type="' . esc_attr( $type ) . '" />' . "\n" );
}
The only way I found to set the enclosure dynamically is short-circuiting the get_metadata call. You can add checks to make sure that you are in a feed or even the check the stacktrace to make sure.
add_filter('get_post_metadata', 'hughie_get_post_metadata', 10, 5 );
function hughie_get_post_metadata($value, int $object_id, string $meta_key, bool $single, string $meta_type)
{
if (is_feed() && $meta_key === '') {
$backtrace = debug_backtrace();
if (isset($backtrace[7]['function']) && ( $backtrace[7]['function'] === 'rss_enclosure' || $backtrace[7]['function'] === 'atom_enclosure' ) ) {
if (!isset($value['enclosure'])) {
$value['enclosure'] = [];
}
$id = get_post_thumbnail_id();
$url = wp_get_attachment_url($id);
$length = filesize(get_attached_file($id));
$type = get_post_mime_type($id);
$value['enclosure'][] = "$url\n$length\n$type";
}
}
return $value;
}

Zend Framework configuring decorator

if(count($this->form->email->getMessages()) > 0)
{
$e = '<ul>';
$m = $this->form->email->getMessages();
foreach($m as $me)
{
$e .= '<li>';
$e .= $me;
$e .= '</li>';
}
$e .= '</ul>';
echo $e;
unset($e);
unset($m);
}
I'm currenly passing form object to VIEW and echo every elemen manually.
But when comes to errors, it takes a lot of code to write.
Could someone tell, how to output errors for each element without such amount of code?
Thanks!
Here is the picture of all decorators before the output:
Found amazing method:
renderFormErrors();
Just what i was looking for. :)
But for individual outputing, can be used decorator. Found on this forum.
this is impossible since to havent provided your current decorator. However, you should add the helper
Errors
to the decorator.