code

Fixing z-index object problems in Google Chrome using wmode

0

Turns out that using z-index on html objects doesn’t work in Google Chrome! Luckily, there’s a quick fix – just add the following param to the object, add the z-index, and you should be good to go:

<param name="wmode" value="transparent">

How to trigger a jQuery Plugin (fancybox) if URL match

0

I currently work for a venue – often times we have shows with multiple acts, so we need to list set times for each artist. Easy enough: I can write a modal-type pop-up window using fancybox that opens when the user clicks a link (“DJ Showtimes here“, for example). But say you want to send an email that links to that list? Since most email clients, web- or desktop-based, don’t allow javascript, I needed to trigger the click based on the URL. Here’s my solution (using a custom jQuery function to avoid conflicts with other libraries in use):


$j('#various2').fancybox({'hideOnContentClick': true, 'hideOnOverlayClick': true, 'showCloseButton': true, 'scrolling': 'auto'}); /* use id of link for fancybox selector */
/* necessary to set if-statement within page ready or load event */
$j(document).ready(function() {
if(document.location.href.indexOf('#various2')>-1){ /* check for anchor text in URL */
$j('#various2').fancybox().trigger('click'); /* chain click trigger on to previously written fancybox declaration */
}});
$j('#fancybox-wrap').css({'margin':'20px auto'}) /* set css for wrapper; safari was centering the inline element to the position of the #various2 element, which was at the top of the page. This resets to 20px top/bottom and in the middle horizontally */

My link looks like this:

DJ Set Times Here

and my content is wrapped with:


CONTENT HERE

Easy, peasy.

Google Analytics Links & Resources

0

gleaned from http://appsumo.com/googlevid/ (must sign up to gain access to [temporarily free] video!

Campaign Tracking Overview:
http://cutroni.com/blog/2006/11/10/google-analytics-campaign-tracking-pt-0-an-overview/

Google Analytics URL Builder:
http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55578

Goals & Funnels:
http://www.google.com/support/analytics/bin/answer.py?answer=55515&hl=en

Site Search:
http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=75817

Google Analytics: Power User Guide:
http://blog.vkistudios.com/index.cfm/2009/6/5/The-Google-Analytics-Power-User-Guide

50 Resources for Getting the Most Out of Google Analytics
http://blog.kissmetrics.com/50-resources-for-getting-the-most-out-of-google-analytics/

The Huge Collection of Google Analytics Tips
http://www.searchenginejournal.com/the-huge-collection-of-google-analytics-tips/7426/

Google Analytics YouTube Channel
http://www.youtube.com/googleanalytics

Blogs about Google Analytics

The Official Google Analytics Blog
http://analytics.blogspot.com/index.html

Advanced Web Metrics
http://www.advanced-web-metrics.com/blog/

Google Analytics Results
http://www.googleanalyticsresults.com/

Luna Metrics Blog
http://www.lunametrics.com/blog/

Analytics Talk
http://www.cutroni.com

301 Redirects in Drupal Pages

0

I recently ran into a problem with a Drupal site I designed and maintain. Here’s a quick explanation of the problem, and then the solution.

The front page has a Views Slideshow Block that grabs node data from custom CCK types. These types contain an image to be displayed in the slideshow (but not the node itself) and a checkbox for enabling or disabling the node from appearing in the Slideshow Block. The slideshow images by default link to the nodes from which they were created.

The problem is linking to a page rendered by Views. Since I can’t add a field for the image or checkbox in a view page (not that I know of, let me know if I’m wrong on this) I had to figure out a different way. And I did, but not without further glitches.

I added the image and checkbox fields to my Page content type and created a node with the appropriate image. It appeared in the slideshow and linked to the page. I then tried several methods to redirect the alias to the correct page. First, the Path Redirect Module. Fail. Then, cpanel’s .htaccess redirect configuration tool. Fail. Then manual .htaccess configuration. Fail.

I don’t really know why the .htaccess failed – I have suspicions it has to do simply with Apache not updating, the fact that I have the Global Redirect Module installed, the clean url directives that already exist in the .htaccess file, or some similar url rewriting conflict.

In a pinch, I added this snippet of code to the body of the page I created:

<?php
 header("HTTP/1.1 301 Moved Permanently");
 header("Location: http://www.mysite.com/aliasname");
 exit();
 ?>

This delicious morsel did the trick, but not without a headache first. You’ll have to have access to posting PHP code, and post it as source, even if you select the PHP option.

Fixing PHPList Delete/Merge Attributes Function

2

I recently installed PHPList v2.10.10 (the latest stable release) to manage an email campaign and ran into a slight problem. PHPList allows users to define their own form fields for lists – name, address, birthday, email, and so on. These fields are referred to as “attributes”. Almost any type of data can be configured by adding an attribute in PHPList. You then create a sign-up page and choose which attributes you want users to enter, and whether or not that attribute is required to complete list sign-up.

I started setting up my attributes and naturally, added one by accident. After finding a button deceivingly named “delete”, I clicked it to correct my error. An http request was sent and the page reloaded – but my attribute was still there, winking at me like an old man who – while sitting on his porch – witnessed your ice cream tumbling off its cone after the first lick.

Luckily, a quick search found a remedy so I pass it along to you, the ethereal inter-web user:

http://forums.phplist.com/viewtopic.php?f=17&t=24502#p67476

Take that, old man.

Inserting a span element into an anchor via Drupal’s $primary_links

0

I previously wrote about how to insert a span into a link, but after testing this method quickly failed when coupled with the Views module. When a Page view is created and assigned to a node url, everything is fine and dandy. The issues arise when you want a link to use an alias. Luckily, I’ve devised a really simple work around:

use the same code to generate your menu:

&lt;?php if (!empty($primary_links)): ?&gt;
&lt;?php print theme('links', $primary_links, array('id' =&gt; 'nav')); ?&gt;
&lt;?php endif; ?&gt;

this calls the links() function inside of includes/theme.inc, which triggers the l() function in the includes/common.inc to write the primary links menu. We can’t override the l() entirely because other code uses it, so we’ll copy the code from theme.inc and override the l() function with a site template specific one. Here’s my code:

theme.inc

function mytheme_links($links, $attributes = array('class' =&gt; 'links')) {
 global $language;
 $output = '';
 $options = array(
 'class' =&gt; '',
 'html' =&gt; FALSE,
 );

 if (count($links) &gt; 0) {
 $output = '&lt;ul' . drupal_attributes($attributes) .'&gt;';

 $num_links = count($links);
 $i = 1;

 foreach ($links as $key =&gt; $link) {
 $class = $key;

 $links['attributes']['title'] = $link['title'];
 // Add first, last and active classes to the list of links to help out themers.
 if ($i == 1) {
 $class .= ' first';
 }
 if ($i == $num_links) {
 $class .= ' signup last';
 $links['attributes']['class'] .= $class;
 }
 if (isset($link['href']) &amp;&amp; ($link['href'] == $_GET['q'] || ($link['href'] == '&lt;front&gt;' &amp;&amp; drupal_is_front_page()))
 &amp;&amp; (empty($link['language']) || $link['language']-&gt;language == $language-&gt;language)) {
 $class .= ' active';
 }
 $output .= '&lt;li' . drupal_attributes(array('class' =&gt; $class)) .'&gt;';

 if (isset($link['href'])) {
 // Pass in $link as $options, they share the same keys.

//here's my call to the overridden function
 $output .= mytheme_l($link['title'], $link['href'], $links);
 }
 else if (!empty($link['title'])) {
 // Some links are actually not links, but we wrap these in &lt;span&gt; for adding title and class attributes
 if (empty($link['html'])) {
 $link['title'] = check_plain($link['title']);
 }
 $span_attributes = '';
 if (isset($link['attributes'])) {
 $span_attributes = drupal_attributes($link['attributes']);
 }
 $output .= '&lt;span'. $span_attributes .'&gt;'. $link['title'] .'&lt;/span&gt;';
 }

 $i++;
 $output .= "&lt;/li&gt;\n";
 }

 $output .= '&lt;/ul&gt;';
 }

 return $output;
}

and now the l() function in common.inc gets changed to mytheme_l():

function mytheme_l($text, $path, $options = array()) {
 global $language;

 // Merge in defaults.
 $options += array(
 'attributes' =&gt; array(),
 'html' =&gt; FALSE,
 );

 // Append active class.
 if (($path == $_GET['q'] || ($path == '&lt;front&gt;' &amp;&amp; drupal_is_front_page())) &amp;&amp;
 (empty($options['language']) || $options['language']-&gt;language == $language-&gt;language)) {
 if (isset($options['attributes']['class'])) {
 $options['attributes']['class'] .= ' active';
 }
 else {
 $options['attributes']['class'] = 'active';
 }
 }

 // Remove all HTML and PHP tags from a tooltip. For best performance, we act only
 // if a quick strpos() pre-check gave a suspicion (because strip_tags() is expensive).
 if (isset($options['attributes']['title']) &amp;&amp; strpos($options['attributes']['title'], '&lt;') !== FALSE) {
 $options['attributes']['title'] = strip_tags($options['attributes']['title']);
 }
 // Inject a span inside the anchor tag for the purposes of this theme - NOTE - May have to remove check_plain() around
 // the $text variable
 return '&lt;a href="'. check_url(url($path, $options)) .'"'. drupal_attributes($options['attributes']) .'&gt;&lt;span&gt;'. ($options['html'] ? $text : check_plain($text)) .'&lt;/span&gt;&lt;/a&gt;';
}

You can see that all I did was include the span element inside the anchor tag using simple php string concatenation. Until I can find a better solution, this does the trick. Don’t ask me about benchmarking, though…

Returning an Alias from primary_links’s links['href'] – or – How I became a Drupal Wizard

0

I’m building a custom template in Drupal for the farm, and needed a way to spit out a custom implementation of primary_links navigation unordered list. I needed something like this:

<ul id="nav">
  <li class="first"><a href="link-goes-here" title="wow, how descriptive"><span>link 1 copy</span></a></li>
  <li><a href="link-goes-here2" title="round 2, FIGHT!"><span>link 2 copy</span></a></li>
</ul>

The spans inside the anchor tag are valid xhtml strict, and necessary for the nested/floating backgrounds. The l() function in drupal does a fine job of spitting out valid code, but I also haven’t found anything to delimit the angle brackets in the span element.
Here’s how I solved the problem.

First, I added a preprocess function in template.php and copied this chunk of code from root/includes/theme.inc:

function theme_links($links, $attributes = array('class' => 'links')) {
 global $language;
 $output = '';

 if (count($links) > 0) {
 $output = '<ul'. drupal_attributes($attributes) .'>';

 $num_links = count($links);
 $i = 1;

 foreach ($links as $key => $link) {
 $class = $key;

 // Add first, last and active classes to the list of links to help out themers.
 if ($i == 1) {
 $class .= ' first';
 }
 if ($i == $num_links) {
 $class .= ' last';
 }
 if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))
 && (empty($link['language']) || $link['language']->language == $language->language)) {
 $class .= ' active';
 }
 $output .= '<li'. drupal_attributes(array('class' => $class)) .'>';

 if (isset($link['href'])) {
 // Pass in $link as $options, they share the same keys.
 $output .= l($link['title'], $link['href'], $link);
 }
 else if (!empty($link['title'])) {
 // Some links are actually not links, but we wrap these in <span> for adding title and class attributes
 if (empty($link['html'])) {
 $link['title'] = check_plain($link['title']);
 }
 $span_attributes = '';
 if (isset($link['attributes'])) {
 $span_attributes = drupal_attributes($link['attributes']);
 }
 $output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
 }

 $i++;
 $output .= "</li>\n";
 }

 $output .= '</ul>';
 }

 return $output;
}

I then modified the code as follows:

function stoneyacresfarm_links($links, $attributes = array('class' => 'links')) {
 global $language;
 $output = '';

 if (count($links) > 0) {
 $output = '<ul'. drupal_attributes($attributes) .'>';

 $num_links = count($links);
 $i = 1;

 foreach ($links as $key => $link) {
 $class = $key;

 // Add first, last and active classes to the list of links to help out themers.
 if ($i == 1) {
 $class .= ' first';
 }
 if ($i == $num_links) {
 $class .= ' last';
 }
 if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))
 && (empty($link['language']) || $link['language']->language == $language->language)) {
 $class .= ' active';
 }
 $output .= '<li'. drupal_attributes(array('class' => $class)) .'>';

 if (isset($link['href'])) {
 // Pass in $link as $options, they share the same keys.
 // here are the modifications
 $temphref = drupal_lookup_path('alias', $link['href'], '');
 $output .= '<a href="' . $temphref . '" title="' . $link['title'] . '"> <span>' . $link['title'] . '</span></a>';
 }
 else if (!empty($link['title'])) {
 // Some links are actually not links, but we wrap these in <span> for adding title and class attributes
 if (empty($link['html'])) {
 $link['title'] = check_plain($link['title']);
 }
 $span_attributes = '';
 if (isset($link['attributes'])) {
 $span_attributes = drupal_attributes($link['attributes']);
 }
 $output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
 }

 $i++;
 $output .= "</li>\n";
 }

 $output .= '</ul>';
 }

 return $output;
}

Lines 29 & 30 are the brilliant bits. I scoured api.drupal.org till I found theĀ  drupal_lookup_path function. Follow the link for the arguments that can be passed in. I specified that I wanted an alias, gave it the path ( links['href'] ), and passed in a blank character for language.

This is all rendered out in my page-front.tpl.php and page.tpl.php files in the standard fashion:

<?php if (!empty($primary_links)): ?>
  <?php print theme('links', $primary_links, array('id' => 'nav')); ?>
<?php endif; ?>

I hope this helps!

Go to Top