Inserting javascript into PHP script

Discussion in 'PHP' started by giorgioarmani, Sep 26, 2008.

  1. #1
    I have a phpscript (zenphoto) that displays photos nicely on my site. I tried adding all kinds of javascript to one of the theme templates but I only get errors...

    adsense
    statcounter
    contextual ads
    banner ads

    Nothing works... I tried <div> tags but still the script doesn't like any of it...

    Anyone know where I am going wrong?
     
    giorgioarmani, Sep 26, 2008 IP
  2. Christian Little

    Christian Little Peon

    Messages:
    1,753
    Likes Received:
    80
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Post the code, it makes it easier to debug if we can actually see what you are doing.
     
    Christian Little, Sep 26, 2008 IP
  3. giorgioarmani

    giorgioarmani Well-Known Member

    Messages:
    2,634
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    160
    #3
    <?php if (!defined('WEBPATH')) die(); $themeResult = getTheme($zenCSS, $themeColor, 'light'); $firstPageImages = normalizeColumns('2', '6');?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    	<?php zenJavascript(); ?>
    	<title><?php echo strip_tags(getGalleryTitle()); ?> | <?php echo strip_tags(getAlbumTitle());?> | <?php echo strip_tags(getImageTitle());?></title>
    	<link rel="stylesheet" href="<?php echo $zenCSS ?>" type="text/css" />
    	<link rel="stylesheet" href="<?php echo FULLWEBPATH . "/" . ZENFOLDER ?>/js/thickbox.css" type="text/css" />
    	<script src="<?php echo FULLWEBPATH . "/" . ZENFOLDER ?>/js/thickbox.js" type="text/javascript"></script>
    	<script type="text/javascript">
    		function toggleComments() {
    			var commentDiv = document.getElementById("comments");
    			if (commentDiv.style.display == "block") {
    				commentDiv.style.display = "none";
    			} else {
    				commentDiv.style.display = "block";
    			}
    		}
    	</script>
    		<?php printRSSHeaderLink('Gallery',gettext('Gallery RSS')); ?>
    
    </head>
    
    <body>
    
    <div id="main">
    
    	<div id="gallerytitle">
    		<div class="imgnav">
    			<?php if (hasPrevImage()) { ?>
    			<div class="imgprevious"><a href="<?php echo htmlspecialchars(getPrevImageURL());?>" title="<?php echo gettext("Previous Image"); ?>">&laquo; <?php echo gettext("prev"); ?></a></div>
    			<?php } if (hasNextImage()) { ?>
    			<div class="imgnext"><a href="<?php echo htmlspecialchars(getNextImageURL());?>" title="<?php echo gettext("Next Image"); ?>"><?php echo gettext("next"); ?> &raquo;</a></div>
    			<?php } ?>
    		</div>
    		<h2><span><?php printHomeLink('', ' | '); ?><a href="<?php echo htmlspecialchars(getGalleryIndexURL());?>" title="<?php gettext('Albums Index'); ?>"><?php echo getGalleryTitle();?>
    			</a> | <?php printParentBreadcrumb("", " | ", " | "); printAlbumBreadcrumb("", " | "); ?>
    			</span> <?php printImageTitle(true); ?>
    		</h2>
    
    	</div>
    
    	<!-- The Image -->
    	<?php if (!checkForPassword()) { ?>
    	<div id="image">
    		<a href="<?php echo htmlspecialchars(getFullImageURL());?>" title="<?php echo strip_tags(getImageTitle());?>"><strong><?php printDefaultSizedImage(getImageTitle()); ?></strong></a>
    	</div>
    
    	<div id="narrow">
    		<?php printImageDesc(true); ?>
    		<?php if (function_exists('printSlideShowLink')) printSlideShowLink(gettext('View Slideshow')); ?>
    		<hr /><br />
    		<?php
    			if (getImageEXIFData()) {echo "<div id=\"exif_link\"><a href=\"#TB_inline?height=345&amp;width=300&amp;inlineId=imagemetadata\" title=\"".gettext("Image Info")."\" class=\"thickbox\">".gettext("Image Info")."</a></div>";
    				printImageMetadata('', false);
    			}
    		?>
    		<?php printTags('links', gettext('<strong>Tags:</strong>').' ', 'taglist', ''); ?>
    
    		<?php if (function_exists('printImageMap')) printImageMap(); ?>
    
        <?php if (function_exists('printImageRating')) { printImageRating(); }?>
    
    		<?php if (function_exists('printShutterfly')) printShutterfly(); ?>
    
    		<?php if (getOption('Allow_comments')) { ?>
    				<div id="comments">
    		<?php $num = getCommentCount(); echo ($num == 0) ? "" : ("<h3>".gettext("Comments")." ($num)</h3><hr />"); ?>
    			<?php while (next_comment()){  ?>
    			<div class="comment">
    				<div class="commentmeta">
    					<span class="commentauthor"><?php printCommentAuthorLink(); ?></span> <?php gettext("says:"); ?>
    				</div>
    				<div class="commentbody">
    					<?php echo getCommentBody();?>
    				</div>
    				<div class="commentdate">
    					<?php echo getCommentDate();?>
    					,
    					<?php echo getCommentTime();?>
    								<?php printEditCommentLink(gettext('Edit'), ' | ', ''); ?>
    				</div>
    			</div>
    			<?php }; ?>
    
    			<?php if (OpenedForComments()) { ?>
    			<div class="imgcommentform">
    							<!-- If comments are on for this image AND album... -->
    				<h3><?php echo gettext("Add a comment:"); ?></h3>
    				<form id="commentform" action="#" method="post">
    				<div><input type="hidden" name="comment" value="1" />
    							<input type="hidden" name="remember" value="1" />
    								<?php
    								printCommentErrors();
    								$stored = getCommentStored();
    								?>
    					<table border="0">
    						<tr>
    							<td><label for="name"><?php echo gettext("Name:"); ?></label>
    								(<input type="checkbox" name="anon" value="1"<?php if ($stored['anon']) echo " CHECKED"; ?> /> <?php echo gettext("don't publish"); ?>)
    							</td>
    							<td><input type="text" id="name" name="name" size="20" value="<?php echo $stored['name'];?>" class="inputbox" />
    							</td>
    						</tr>
    						<tr>
    							<td><label for="email"><?php echo gettext("E-Mail:"); ?></label></td>
    							<td><input type="text" id="email" name="email" size="20" value="<?php echo $stored['email'];?>" class="inputbox" />
    							</td>
    						</tr>
    						<tr>
    							<td><label for="website"><?php echo gettext("Site:"); ?></label></td>
    							<td><input type="text" id="website" name="website" size="40" value="<?php echo $stored['website'];?>" class="inputbox" /></td>
    						</tr>
    												<?php if (getOption('Use_Captcha')) {
     													$captchaCode=generateCaptcha($img); ?>
     													<tr>
     													<td><label for="code"><?php echo gettext("Enter Captcha:"); ?>
     													<img src=<?php echo "\"$img\"";?> alt="Code" align="bottom"/>
     													</label></td>
     													<td><input type="text" id="code" name="code" size="20" class="inputbox" /><input type="hidden" name="code_h" value="<?php echo $captchaCode;?>"/></td>
     													</tr>
    												<?php } ?>
    							<tr><td colspan="2"><input type="checkbox" name="private" value="1"<?php if ($stored['private']) echo " CHECKED"; ?> /> <?php echo gettext("Private (don't publish)"); ?></td></tr>
    					</table>
    					<textarea name="comment" rows="6" cols="40"><?php echo $stored['comment']; ?></textarea>
    					<br />
    					<input type="submit" value="<?php echo gettext('Add Comment'); ?>" class="pushbutton" /></div>
    				</form>
    			</div>
    		</div>
    				<?php } else { echo gettext('Comments are closed.'); } ?>
    				<?php } ?>
    	</div>
    		<?php } ?>
    </div>
    
    <?php printAdminToolbox(); ?>
    
    <div>
    <!-- Start of StatCounter Code -->
    <script type="text/javascript">
    var sc_project=XXXXXX;
    var sc_invisible=1;
    var sc_partition=50;
    var sc_click_stat=1;
    var sc_security="XXXXXXXXXXX";
    </script>
    
    <script type="text/javascript"
    src="http://www.statcounter.com/counter/counter.js"></script><noscript><div
    class="statcounter"><a title="hits counter"
    href="http://www.statcounter.com/free_hit_counter.html"
    target="_blank"><img class="statcounter"
    src="http://c.statcounter.com/XXXXXXXX" alt="hits counter"
    ></a></div></noscript>
    <!-- End of StatCounter Code -->
    </div>
    
    </body>
    </html>
    
    PHP:
     
    giorgioarmani, Sep 26, 2008 IP
  4. Christian Little

    Christian Little Peon

    Messages:
    1,753
    Likes Received:
    80
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Alright that's a big chunk of code, so before I go line-by-line, are you getting JavaScript errors or PHP errors? Could you copy/paste the exact error text that is displayed?
     
    Christian Little, Sep 26, 2008 IP
  5. giorgioarmani

    giorgioarmani Well-Known Member

    Messages:
    2,634
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    160
    #5
    Depends on what I put... If I just put statcounter it shows part of the code..

    If I also include contextual ads it shows: "Code corrupted. Insert fresh copy. "
     
    giorgioarmani, Sep 26, 2008 IP
  6. giorgioarmani

    giorgioarmani Well-Known Member

    Messages:
    2,634
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    160
    #6
    Hey Christian, did you manage to see what's wrong?
     
    giorgioarmani, Sep 27, 2008 IP
  7. Christian Little

    Christian Little Peon

    Messages:
    1,753
    Likes Received:
    80
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I can't help you without the detailed error codes you are getting. The 'insert fresh copy' of the ad code means there's a problem from the ad network.
     
    Christian Little, Sep 28, 2008 IP
  8. giorgioarmani

    giorgioarmani Well-Known Member

    Messages:
    2,634
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    160
    #8
    Ok statcounter now works... I'm trying to get adbrite to work now but with <div> tags all it does is show the actual javascript code on the website...
     
    giorgioarmani, Sep 29, 2008 IP
  9. sastro

    sastro Well-Known Member

    Messages:
    214
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #9
    Put this on yor script before </body> tag and see what happen
    <div style="width: 100%;position: absolute;z-index: 1000;height: auto;left: 0px;top: 0px;">
    <!-- Your Ads Code Here -->
    </div>
     
    sastro, Sep 29, 2008 IP
  10. Christian Little

    Christian Little Peon

    Messages:
    1,753
    Likes Received:
    80
    Best Answers:
    0
    Trophy Points:
    0
    #10
    If it's showing the Javascript code, that means you haven't properly wrapped it. Make sure there is <script>, </script>, and <noscript> tags surrounding the code, otherwise it won't render.
     
    Christian Little, Sep 29, 2008 IP
  11. giorgioarmani

    giorgioarmani Well-Known Member

    Messages:
    2,634
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    160
    #11
    First of all thanks for trying to help me out, appreciated!

    I have tried to put that code you mention sastro but now the code shows in the header instead of the footer, but still no ads...

    Christian I have script and /script tags... What do you mean with noscript?

    Is there another tag I can use instead of div?
     
    giorgioarmani, Sep 29, 2008 IP
  12. Christian Little

    Christian Little Peon

    Messages:
    1,753
    Likes Received:
    80
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Give us the URL you are doing this on, I have a suspicion about why this isn't working.
     
    Christian Little, Sep 29, 2008 IP
  13. linkexchange1984

    linkexchange1984 Peon

    Messages:
    73
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #13
    replying just 2 be in touch
     
    linkexchange1984, Sep 29, 2008 IP