0

Any idea how can I remove this in $vars['closure']; ?

<!-- SiteCatalyst code version: H.19.4 Copyright 1997-2009 Omniture, Inc. More info available at http://www.omniture.com -->
<script type="text/javascript" language="JavaScript" src="/sites/all/themes/mytheme/js/s_code.js"></script>
<script type="text/javascript" language="JavaScript"><!--
/************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/
var s_code=s.t();if(s_code)document.write(s_code)//--></script>
<script language="JavaScript" type="text/javascript"><!--
if(navigator.appVersion.indexOf('MSIE')>=0)document.write(unescape('%3C')+'\!-'+'-')
//--></script><noscript><a href="http://www.omniture.com" title="Web Analytics"><img src="http://server.122.2O7.net/b/ss/frisky/1/H.19.4--NS/0/4256542"
height="1" width="1" border="0" alt="" /></a></noscript><!--/DO NOT REMOVE/-->
<!-- End SiteCatalyst code version: H.19.4 -->

I tried the methods explained by kiamlaluno in this thread but I cant remove the above code in the view source using preg_replace but no luck.

//Remove omniture tags in unpublish node
  if(arg(0) == 'node' && $vars['node']->status == 0) {
    $vars['closure'] = theme('closure');
    $omnitureTags = preg_replace( "/\<!-- SiteCatalyst code version: H\.19\.4 Copyright 1997-2009.+\<!-- End SiteCatalyst code version: H\.19\.4 --\>/si", "", $vars['closure']);
    $vars['closure'] = $omnitureTags;
  } else {
    $vars['closure'] = theme('closure');
  }

The above code is now working according to what I need.

10
  • Yeah. I don't think that would work. I can't put my finger on it but something does not look right. Have you been able to modify $vars['closure'] at all because I am not 100% sure that $vars['closure'] = theme('closure'); belongs there, if at all. But often in Drupal there is more than one way to do things. Of course, I assume you are aware that preprocess_page function only runs on unpublished pages. Good-luck, happy coding. Commented Dec 19, 2011 at 6:55
  • By the way, while we are on topic of parsing html with regex, this answer is a classic that is somewhat on topic. A good read/laugh. Commented Dec 19, 2011 at 7:08
  • 1
    Hmm. Running theme('closure') in here (which I assume is in a module) will certainly build the 'closure' variable, which is ok so far, but then when you preg_replace it, you print it instead of setting it... eg, you should do a $vars['closure']=preg_replace(.....) If this doesn't work, then the module that is putting this in the closure variable is changing or adding it AFTER you've done your stuff, at which point you need to put this in your theme, which runs preprocess after all the modules are done.
    – Jimajamma
    Commented Dec 19, 2011 at 8:04
  • 1
    glad you figured it all out!
    – Jimajamma
    Commented Dec 19, 2011 at 8:06
  • 2
    If it's a bug, fix it. If it's just something you want different, preprocess it.
    – Jimajamma
    Commented Dec 19, 2011 at 8:18

1 Answer 1

1

This is what theme_closure() does (in theme.inc):

function theme_closure($main = 0) {
  $footer = module_invoke_all('footer', $main);
  return implode("\n", $footer) . drupal_get_js('footer');
}

which means it's going to ask every module to run its footer hook plus get all the js to be put in the footer and return it:

$variables['closure'] = theme('closure');

to populate the closure variable. So.... if you can't preg_replace() or regex() it out, why not just find what module is putting in there in the first place (seems pretty obvious) and kill it off there?

EDIT/ADDITION: IF it's a bug, fix it here, otherwise if it's just something you want different, preprocess it. But it seems to me that a node status check might be in order in the module's footer hook.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.