Text/Javascript in PHP?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lucasw
Forum Newbie
Posts: 1
Joined: Mon Sep 13, 2010 6:05 pm

Text/Javascript in PHP?

Post by lucasw »

I'm using a WordPress plugin called Photo Galleria. When the page is XHTML-validation checked the plugin causes two errors, both associated with the "<script>" codes. Basically, because text/javascript isn't declared it's not XHTML-valid. The hang-up being that when I declare the script type the plug-in crashes. Any help would be much appreciated. :)

Code: Select all

function photo_galleria_scripts_head(){

	// Retreive our plugin options
	$photo_galleria = get_option( 'photo_galleria' );
	$design = $photo_galleria['design'];
		if ($design == 'classic' || $design == '') {
				$design = '/themes/classic/galleria.classic.js';}
			elseif ($design == 'dots') {
				$design = '/themes/dots/galleria.dots.js';}
			elseif ($design == 'lightbox') {
				$design = '/themes/lightbox/galleria.lightbox.js';}
	$autoplay = $photo_galleria['autoplay'];
		if ($autoplay == 1) { $autoplay = '5000'; }
		if ($autoplay == 0) { $autoplay = 'false'; }
	$height = $photo_galleria['height'];
    if($height=="")
        $height = 500;
	$transition = $photo_galleria['transition'];
	$color = $photo_galleria['color'];
	
	$pluginURI = get_option('siteurl').'/wp-content/plugins/'.dirname(plugin_basename(__FILE__));
	
	if(!is_admin()){
		echo "<script>
			    
  // Load theme
  Galleria.loadTheme('" . $pluginURI . "" . $design . "');
  
  // run galleria and add some options
  jQuery('#galleria').galleria({
  		autoplay: " . $autoplay . ",
      height: " . $height . ",
      transition: '" . $transition . "',
      data_config: function(img) {
          // will extract and return image captions from the source:
          return  {
              title: jQuery(img).parent().next('strong').html(),
              description: jQuery(img).parent().next('strong').next().html()
          };
      }
  });
  </script>
  <style type='text/css'>.galleria-container {background-color: " . $color . "}</style>";
	}
}

add_action('wp_footer','photo_galleria_scripts_head');
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Text/Javascript in PHP?

Post by Jonah Bron »

Try this. I don't know, but you might not have escaped the quotes properly.

Code: Select all

function photo_galleria_scripts_head(){

	// Retreive our plugin options
	$photo_galleria = get_option( 'photo_galleria' );
	$design = $photo_galleria['design'];
		if ($design == 'classic' || $design == '') {
				$design = '/themes/classic/galleria.classic.js';}
			elseif ($design == 'dots') {
				$design = '/themes/dots/galleria.dots.js';}
			elseif ($design == 'lightbox') {
				$design = '/themes/lightbox/galleria.lightbox.js';}
	$autoplay = $photo_galleria['autoplay'];
		if ($autoplay == 1) { $autoplay = '5000'; }
		if ($autoplay == 0) { $autoplay = 'false'; }
	$height = $photo_galleria['height'];
    if($height=="")
        $height = 500;
	$transition = $photo_galleria['transition'];
	$color = $photo_galleria['color'];
	
	$pluginURI = get_option('siteurl').'/wp-content/plugins/'.dirname(plugin_basename(__FILE__));
	
	if(!is_admin()){
		echo "<script type=\"text/javascript\">
			    
  // Load theme
  Galleria.loadTheme('" . $pluginURI . "" . $design . "');
  
  // run galleria and add some options
  jQuery('#galleria').galleria({
  		autoplay: " . $autoplay . ",
      height: " . $height . ",
      transition: '" . $transition . "',
      data_config: function(img) {
          // will extract and return image captions from the source:
          return  {
              title: jQuery(img).parent().next('strong').html(),
              description: jQuery(img).parent().next('strong').next().html()
          };
      }
  });
  </script>
  <style type='text/css'>.galleria-container {background-color: " . $color . "}</style>";
	}
}

add_action('wp_footer','photo_galleria_scripts_head');
Post Reply