How do I get additional banner-ads on pages without sidebars in Zen Cart? - zen-cart

I am trying to ad a banner ad to the left side of the footer so I have something like this:
[ banner ] [ footer information ]
This is the code that was in the basic banner module:
<div class="content">
<?php
$content = '';
// if no active banner in the specified banner group then the box will not show
if ($banner = zen_banner_exists('dynamic', $banner_box_group)) {
$content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent centeredContent">';
$content .= zen_display_banner('static', $banner);
$content .= '</div>';
}
echo $content;
?>
</div>
Which works fine on the home page (it displays an ad like I expect it to). It does not however display any ads on some of the other pages. I expect that it is something to do with the sidebar as it is turned off on the pages that the ads choose not to display. What am I missing?

Ah, it turns out that
$banner_box_group
needs to be a string of banner groups separated by colons, so something like:
'BannersAll:Sidebox-Banners'

Related

Facebook API images not downloading

First post here,
i am developing a app to fetch and download facebook images from user's account.
I have a basic code till now as follows..
Need help as to why only the 1 file keeps downloading alone...in the zip i create
it is the only image without the ?oh= concatenation, all others with the oh parameter dont get
downloaded...
<?php
set_time_limit(0);
$url='https://graph.facebook.com/me/photos/uploaded?access_token=CAACEdEose0cBAEGw8R4QOGfN3bfX8qtuZCCy8FX6g5Sil8CKaYlp9x8lZAiNFEGJXhh9MYOWdZAJR1x2M627rc5I3n3AauVe8nJtYBsehjUZAljMLkQMMxP03VVXknZBa81Nk1S23z7SnyTkIlgt2oZC1euoFNCTuGesAap1uQUGZAX7LnILlBwyj3V7IVo9QQCNv66Lv8UcA86wYn9jlJE';
$result = file_get_contents($url);
$a=json_decode($result, true);
$files = array();
echo '<div class="col-lg-12">';
$num= count($a['data']);
echo "<table class='table table-hover table-responsive'>";
for($o=0;$o<$num;$o++)
{
$files_to_zip[$o]=$a['data'][$o]['source'];
if($a['data'][$o]['source']!="")
{
echo "<tr><td><img src='".$a['data'][$o]['source']."' id=".$o." width='200' height='200' /></td></tr>";
array_push($files,$a['data'][$o]['source']);
//echo $files_to_zip[$o]."<br/><br/><br/><br/>";
}
}
echo '</table></div><br/>';
?>

How to capitalize $2 in preg_replace?

I run a community site (built by hand using html, css, and php) for my wow guild. Recently, my members have demanded the ability to use tags like #username in their posts, which would then link to the users page. I already have this script, as listed below:
<?php
$string = '#user really?';
if (preg_match('/(^|\s)#([a-z0-9_]+)/i', $string))
{
$string = preg_replace('/(^|\s)#([a-z0-9_]+)/i', '#$2', $string);
echo $string;
}
else {
echo $string;
}
?>
This works fine, and I notice that the $2 is the user's name, but, since all user's names start with capital letters, the $2 needs to be capitalized, and not everyone does that. Is there a way to code it to automatically capitalize $2, or should I just tell users to remember to capitalize?
Thanx in advance,
Steven
use ucfirst ($2) to capitalize the first character
and strtoupper($2) if you want it all capital
I added more preg_replace and it now links to user no matter how u type name, as long as u have # symbol (#user, #USER, #User, #uSER, etc...). for anyone needing my solution, I will post it below:
<?php
$proper_str = "going to battle with #ADROK";
$proper_str = ucfirst(strtolower($proper_str));
$proper_str = preg_replace('/#[a-z]/e', 'ucfirst(strtoupper("$0"))', $proper_str);
$proper_str = preg_replace('/(^|\s)#([a-z0-9_]+)/i', ' #$2', $proper_str);
echo $proper_str;
?>
and if you change somethings around and make it:
<?php
$proper_str = "going to battle with e#mail.com";
if (preg_match('/(^|\s)#([a-z0-9_]+)/i', $proper_str))
{
$proper_str = ucfirst(strtolower($proper_str));
$proper_str = preg_replace('/#[a-z]/e', 'ucfirst(strtoupper("$0"))', $proper_str);
$proper_str = preg_replace('/(^|\s)#([a-z0-9_]+)/i', ' #$2', $proper_str);
echo $proper_str;
} else {
$proper_str = ucfirst("$proper_str");
echo $proper_str;
}
?>
Then it will leave email addresses alone and make sure first letter of post is capitalized!

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;
}

Is it possible with jquery to use the nth-child() selector on an 'a' or an 'a:hover', not just 'li'?

Ive created a navigation bar where the hover state of each link has be a different color so im trying to select the a:hover states with jquerys nth-child() selector. i can get it to select the li element but not the a or the a:hover. Currently all the hovers are blue.
here is the jquery code im trying to use:
jQuery(document).ready(function() {
jQuery('#leftbar li:nth-child(3)').css('border-bottom', '#000000 5px solid');
});
Hi the navigation is generated with php, here it is:
<ul id="leftbar">
<?php
$pagepath = "content/pages/";
$legalpath = "content/legals/";
$mainnavpath = "content/.system-use/navigation/";
$mainnavfile = $mainnavpath."mainnav.inc";
if (file_exists($mainnavfile)) {
require $mainnavfile;
sort ($mainfiles);
for($i=0; $i<count($mainfiles); $i++)
{
if (!preg_match("/XX-/",$mainfiles[$i])) {
$displayname = preg_replace("/\.inc/i", "", $mainfiles[$i]);
$displayname = substr($displayname, 3);
echo "<li>";
echo "<a ";
if ($page==$displayname) {echo ' class="active"';} else {echo ' class="prinav"';}
echo "title='$displayname' href='";
if ($useredirect=="yes"){echo '/'.$displayname.'/';} else {echo '/index.php?page='.$displayname;}
echo"' ";
echo "><span>$displayname</span></a></li>\n";
}}
}
else { echo "<strong>No Navigation - Please Login to your Admin System and set the Page Order</strong>"; }
?>
here is the site im working on:
http://entourageuk.com/
Cheers!
Paul
You can't select using a CSS pseudo selector like :hover, but yes, you can select an <a> element.
Whether :nth-child is appropriate depends on your markup. I'm going to assume that each <a> is a child of the <li> elements you're selecting.
If that's the case, then you would just add a to the selector.
jQuery('#leftbar li:nth-child(3) > a').css(...
This uses the > child selector, and is basically saying that I want the <a> element(s) that is a direct child of the <li> element(s) that is the third child of its container and is a descendant of leftbar.