View Full Version : Modifying Pausing up-down scroller
Script Title: Pausing Up-Down Scroller
Script URL (on DD): http://www.dynamicdrive.com/dynamicindex2/crosstick.htm (http://www.dynamicdrive.com/dynamicindex2/crosstick.htm)
Hi!
I want to be able to use this pretty script on a website powered by website baker (http://websitebaker.org), but can't seem to get it to work. The CMS has a function
<?php page_content(x)?> where x stands for the number of content block you want to show. This command returns the page in html. When replacing the original "News content"
var pausecontent=new Array()
pausecontent[0]='<a href="http://www.javascriptkit.com">JavaScript Kit</a><br />Comprehensive JavaScript tutorials and over 400+ free scripts!'
with the
<?php show_pagecontent(x) ?> as follows
var pausecontent=new Array()
pausecontent[0]='<?php show_pagecontent(x) ?>', where "X" stands for the content block (i.e 2) I want to show, the scroller disapears from my site. When I'm viewing the source generated, everything looks OK (the text in pausecontent[0] seems just fine, with the same formatting as the example text.)
Any ideas?
Regards Vidar
jscheuer1
08-27-2006, 06:29 AM
This may not be the problem but, could well be:
First a mini lesson in delimiters. In this script's code the apostrophe is used to delimit (red) the string variables that make up the array:
pausecontent[0]='<a href="http://www.javascriptkit.com">JavaScript Kit</a><br />Comprehensive JavaScript tutorials and over 400+ free scripts!'
and:
pausecontent[0]='<?php show_pagecontent(x) ?>'
If you have an apostrophe in the variable string (green), it must be escaped with the down slash (\):
pausecontent[0]='That\'s Right'
If the server side string represented by:
<?php show_pagecontent(x) ?>
contains one or more apostrophes, They each must be escaped in the same manner in the source for that string.
Hi John!
Thank you for your reply! :)
I've checked the string returned by the php script (using view source), and it does not contain any apostrophes. Even if I try to return the same string as in the original code, the script does not show. (But viewing the code, everything looks 100% like the example code).
Vidar
jscheuer1
08-27-2006, 09:29 AM
Perhaps a link to your problem page or a demo of the problem would help me figure it out. It may not as, PHP does obscure some things from a view source but, usually enough information is present to make a determination.
Hi!
I've set up a demo on http://test.hallais.no
Edit: Writing a post without <br /> tag works just fine!? Why? There are <br /> tags in the default content, and this works fine?
Does the string variable have to be declared in one line?
Regards Vidar
blm126
08-27-2006, 07:13 PM
Newlines strike again.
Change
<?php show_pagecontent(x) ?>
to
<?php
ob_start();
show_pagecontent(x)
$output = ob_get_contents();
ob_end_clean();
$output = str_replace("\n", "", $output);
$output = str_replace("\r", "", $output);
echo $output;
?>
Hi blm126!
When replacing
<?php show_pagecontent(x) ?> with
<?php
ob_start();
show_pagecontent(x)
$output = ob_get_contents();
ob_end_clean();
$output = str_replace("\n", "", $output);
$output = str_replace("\r", "", $output);
echo $output;
?>
the whole page disapear (blank page, nothing parsed)... The beginning of the script then looks like this
<script type="text/javascript">
/*Example message arrays for the two demo scrollers*/
var pausecontent=new Array()
pausecontent[0]='<?php
ob_start();
show_pagecontent(x)
$output = ob_get_contents();
ob_end_clean();
$output = str_replace("\n", "", $output);
$output = str_replace("\r", "", $output);
echo $output;
?> '
pausecontent[1]='<a href="http://www.codingforums.com">Coding Forums</a><br />Web coding and development forums.'
pausecontent[2]='<a href="http://www.cssdrive.com" target="_new">CSS Drive</a><br />Categorized CSS gallery and examples.'
Regards Vidar
blm126
08-27-2006, 09:56 PM
My bad, I forgot a semi colon. Try this
<?php
ob_start();
show_pagecontent(x);
$output = ob_get_contents();
ob_end_clean();
$output = str_replace("\n", "", $output);
$output = str_replace("\r", "", $output);
echo $output;
?>
I've tried that, still problems. When opening the page, only the background images and colors are displayed. Viewing the source gives me this:
<!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" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<link href="http://test.hallais.no/templates/hatex_fremside/screen.css" rel="stylesheet" type="text/css" media="screen" />
<link href="http://test.hallais.no/templates/hatex_fremside/print.css" rel="stylesheet" type="text/css" media="print" />
<style type="text/css">
<!--
@import url("screen.css");
-->
</style>
<style type="text/css">
/*Example CSS for the two demo scrollers*/
#pscroller1{
width: 200px;
height: 100px;
border: 1px solid black;
padding: 5px;
background-color: lightyellow;
}
#pscroller2{
width: 350px;
height: 20px;
border: 1px solid black;
padding: 3px;
}
#pscroller2 a{
text-decoration: none;
}
.someclass{ //class to apply to your scroller(s) if desired
}
</style>
<script language="JavaScript">
<!--
function SymError()
{
return true;
}
window.onerror = SymError;
var SymRealWinOpen = window.open;
function SymWinOpen(url, name, attributes)
{
return (new Object());
}
window.open = SymWinOpen;
//-->
</script>
<script type="text/javascript">
/*Example message arrays for the two demo scrollers*/
var pausecontent=new Array()
pausecontent[0]='
<script language="JavaScript">
<!--
var SymRealOnLoad;
var SymRealOnUnload;
function SymOnUnload()
{
window.open = SymWinOpen;
if(SymRealOnUnload != null)
SymRealOnUnload();
}
function SymOnLoad()
{
if(SymRealOnLoad != null)
SymRealOnLoad();
window.open = SymRealWinOpen;
SymRealOnUnload = window.onunload;
window.onunload = SymOnUnload;
}
SymRealOnLoad = window.onload;
window.onload = SymOnLoad;
//-->
</script>
As you can see, the script is "cut of" where the red letters are...
jscheuer1
08-28-2006, 03:14 PM
viewing the code, everything looks 100% like the example code
Not at: http://test.hallais.no/
This (from above link's source):
<script type="text/javascript">
/*Example message arrays for the two demo scrollers*/
<script type="text/javascript">var pausecontent=new Array()pausecontent[]='<a href='http://test.hallais.no/pages//posts/flere-nyheter3.php">Flere nyheter</a><br />njcldsvhdjskavhsdgjakVC.GHJASK.'pausecontent[]='<a href='http://test.hallais.no/pages//posts/test-nyhet2.php">Test nyhet</a><br />Javell! Dette e ein liden testnyhet, for å se kordan det virke.'pausecontent[]='<a href='http://test.hallais.no/pages/.php"></a><br />'</script>
Should be like this:
<script type="text/javascript">
var pausecontent=new Array();
pausecontent[0]='<a href="http://test.hallais.no/pages//posts/flere-nyheter3.php">Flere nyheter</a><br />njcldsvhdjskavhsdgjakVC.GHJASK.';
pausecontent[1]='<a href="http://test.hallais.no/pages//posts/test-nyhet2.php">Test nyhet</a><br />Javell! Dette e ein liden testnyhet, for å se kordan det virke.';
pausecontent[2]='<a href="http://test.hallais.no/pages/.php"></a><br />';
</script>
And, in the quoted source, there are apostrophes (red) inside the delimiters, ex:
pausecontent[]='<a href='http://te . . .
That one, rather than being escaped, as I mentioned before, should just be changed to a quote("). Notice also the missing number from the square brackets (green).
blm126
08-28-2006, 03:19 PM
Has your demo been updated?
blm126
08-28-2006, 03:22 PM
jsheuer1: That contains one of the PHP codes I posted(not sure which on)
vidi: Change the PHP portion to this.
<?php
ob_start();
show_pagecontent(x);
$output = ob_get_contents();
ob_end_clean();
$output = str_replace("\n", "", $output);
$output = str_replace("\r", "", $output);
$output = str_replace("'", "\'", $output);
echo $output;
?>
Hi John!
I have modifyed the template a littlebit since the last post, sorry for not putting the changes out here. But now, the code looks like this:
<script type="text/javascript">
/*Example message arrays for the two demo scrollers*/
<?php
ob_start(); // start output buffer
global $database;
$query = "SELECT post_id,title,content_short,group_id,link FROM ".TABLE_PREFIX."mod_news_posts ORDER BY position DESC LIMIT 0, 5;";
$error = mysql_error();
if (!$result = mysql_query($query)) {
print "$error";
exit;
}
while($data = mysql_fetch_object($result)){
$title = $data->title;
$id = $data->post_id;
$link = $data->link;
$short = $data->content_short;
echo "pausecontent[]='<a href='";
echo WB_URL.'/pages/'.$link.PAGE_EXTENSION.'">'.$title.'</a><br />'.$short;
echo "'";
}
$foo=ob_get_contents(); // put outputbuffer in $foo
ob_end_clean(); // clear outputbuffer
if ($foo<>"") { // some code to execute cause there is some block
echo '<script type="text/javascript">';
echo 'var pausecontent=new Array()';
echo $foo;
echo '</script>';
} else { // some code for no info
}
?>
This is almost working, but I have the problems you mentioned. I have tried to add a $counter variable, without luck, in the braces, like this:
<script type="text/javascript">
/*Example message arrays for the two demo scrollers*/
<?php
ob_start(); // start output buffer
global $database;
$query = "SELECT post_id,title,content_short,group_id,link FROM ".TABLE_PREFIX."mod_news_posts ORDER BY position DESC LIMIT 0, 5;";
$error = mysql_error();
if (!$result = mysql_query($query)) {
print "$error";
exit;
$counter = 0;
}
while($data = mysql_fetch_object($result)){
$title = $data->title;
$id = $data->post_id;
$link = $data->link;
$short = $data->content_short;
echo "pausecontent["counter"]='<a href='";
echo WB_URL.'/pages/'.$link.PAGE_EXTENSION.'">'.$title.'</a><br />'.$short;
echo "'";
counter++;
}
$foo=ob_get_contents(); // put outputbuffer in $foo
ob_end_clean(); // clear outputbuffer
if ($foo<>"") { // some code to execute cause there is some block
echo '<script type="text/javascript">';
echo 'var pausecontent=new Array()';
echo $foo;
echo '</script>';
} else { // some code for no info
}
?>
but then the page goes blank again....
Regards Vidar
blm126
08-28-2006, 03:53 PM
Try this.
<script type="text/javascript">
/*Example message arrays for the two demo scrollers*/
<?php
ob_start(); // start output buffer
global $database;
$query = "SELECT post_id,title,content_short,group_id,link FROM ".TABLE_PREFIX."mod_news_posts ORDER BY position DESC LIMIT 0, 5;";
$error = mysql_error();
if (!$result = mysql_query($query)) {
print "$error";
exit;
}
$i = 0;
while($data = mysql_fetch_object($result)){
$title = $data->title;
$id = $data->post_id;
$link = $data->link;
$short = $data->content_short;
echo "pausecontent[".$i."]='<a href=\"".WB_URL.'/pages/'.$link.PAGE_EXTENSION.'">'.$title.'</a><br />'.$short."'"."\n";
$i++;
}
$foo=ob_get_contents(); // put outputbuffer in $foo
ob_end_clean(); // clear outputbuffer
if ($foo<>"") { // some code to execute cause there is some block
echo '<script type="text/javascript">'."\n";
echo 'var pausecontent=new Array()'."\n";
echo $foo;
echo '</script>';
} else { // some code for no info
}
?>
I have now used the last code from blm126, and everything looks fine in the source (from view source) (in my opinion), but still, nothing is displayed...
Edit: Sorry, that was my fault! I had too many declarations of <script type="text/javascript">, removed these, and everything is working perfect!
Thank you very much everyone!! :)
Regards Vidar
blm126
08-28-2006, 05:26 PM
Glad we could help(eventually) :)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.