Welcome to Geeklog, Anonymous Thursday, November 28 2024 @ 07:51 pm EST
Geeklog Forums
Adding a phpblock for scrolling news
Status: offline
andyofne
Forum User
Chatty
Registered: 08/31/02
Posts: 69
A friend is setting up a site and I recommended geeklog because it is fun and easy to manage; unfortunately he wants to use a scrolling news block on the left or right and I can't make it work.
I guess I don't understand the adding the function part in the lib-common.php file.
When I add the php script in a function I end up causing the site to stop working due to errors.
I guess it isn't as simple as adding the entire php script to the lib-common file.
If someone could take a minute or two to expand on the process of creating the function in the lib-common file I would be most appreciative.
I guess I don't understand the adding the function part in the lib-common.php file.
When I add the php script in a function I end up causing the site to stop working due to errors.
I guess it isn't as simple as adding the entire php script to the lib-common file.
If someone could take a minute or two to expand on the process of creating the function in the lib-common file I would be most appreciative.
4
7
Quote
Status: Banned
machinari
Forum User
Full Member
Registered: 03/22/04
Posts: 1512
from the faq..
Quote by faq:.
PHP blocks let you call a PHP function and display that functions' output in the block. The PHP function should be added to the lib-custom.php (not lib-common.php). Please note that the function's name must start with phpblock_ and that it must return the content of the block instead of outputting it directly.
PHP blocks let you call a PHP function and display that functions' output in the block. The PHP function should be added to the lib-custom.php (not lib-common.php). Please note that the function's name must start with phpblock_ and that it must return the content of the block instead of outputting it directly.
9
7
Quote
Status: Banned
machinari
Forum User
Full Member
Registered: 03/22/04
Posts: 1512
Quote by andyofne: I believe I said that I read that and didn't understand it.
where?add your function to lib-custom.php; reference that function when you create a new phpblock from the blocks editor; name your function properly according to the above faq entry; enable the block; done.
if your block doesn't work after that, then your function is flawed.
it doesn't get any simpler than that.
6
7
Quote
Status: offline
knuff
Forum User
Full Member
Registered: 12/17/04
Posts: 340
Location:Sweden
Hi Andy,
Let me try to explain step by step .... because from what I understand you copy / paste a customscrolling news block and you didn´t adapt to the specific geeklog setup.
Have a look at all the custom codes available in lib-custom.php and see the logic of it.
First you need to identify your block in lib-custom.php.
In the block functions you will now call phpblock_mynewblock
After this you insert your custom code, and if you want you can easily call here your newsticker.php page or adapt the code to be completly in custom-lib.php ...
so if you call an external php page it would be something like
Whatever you get from your mynewsticker.php page you just pick up.
Using the approach of a custom php page has the advantage you can take it step by step and see where it goes wrong.
So if your mynewsticker.php has something like
you just want to pick up this variable and return it whenever called from a block.
Make sure your page does not output any HTML when called directly as this will then show up everytime and not only in your block.
To pick up the returned variable, this would be in lib-custom.php
return $retval;
So as also outlined in the help / FAQ, lib-custom.php is called always and should only output when asked for, that is the last step, the return $retval.
Most probably this is causing your problem.
Try to take it step by step, and you most probably figure out where it goes wrong.
Hope I didn´t confused any more,
Boris
Vanrillaer.com - our Family Portal
Let me try to explain step by step .... because from what I understand you copy / paste a customscrolling news block and you didn´t adapt to the specific geeklog setup.
Have a look at all the custom codes available in lib-custom.php and see the logic of it.
First you need to identify your block in lib-custom.php.
Text Formatted Code
function phpblock_mynewblock() {In the block functions you will now call phpblock_mynewblock
After this you insert your custom code, and if you want you can easily call here your newsticker.php page or adapt the code to be completly in custom-lib.php ...
so if you call an external php page it would be something like
Text Formatted Code
include_once($_CONF['path_html'] . "/mynewsticker/index.php"); Whatever you get from your mynewsticker.php page you just pick up.
Using the approach of a custom php page has the advantage you can take it step by step and see where it goes wrong.
So if your mynewsticker.php has something like
Text Formatted Code
function my_news() {you just want to pick up this variable and return it whenever called from a block.
Make sure your page does not output any HTML when called directly as this will then show up everytime and not only in your block.
To pick up the returned variable, this would be in lib-custom.php
Text Formatted Code
$retval = my_news();return $retval;
So as also outlined in the help / FAQ, lib-custom.php is called always and should only output when asked for, that is the last step, the return $retval.
Most probably this is causing your problem.
Try to take it step by step, and you most probably figure out where it goes wrong.
Hope I didn´t confused any more,
Boris
Vanrillaer.com - our Family Portal
9
9
Quote
Status: offline
andyofne
Forum User
Chatty
Registered: 08/31/02
Posts: 69
First, I can see that I didn't directly state that I had read the FAQ... I did read it but still didn't 'get it'.
Thanks for the detailed response. It has helped immeasurably. No I just have to figure out why the scrolling news is outputting to the top of the GL instead of in a block as desired. At least I now have a better understanding of how to address the fuctions in the lib-common file.
Appreciate your reply.
Thanks for the detailed response. It has helped immeasurably. No I just have to figure out why the scrolling news is outputting to the top of the GL instead of in a block as desired. At least I now have a better understanding of how to address the fuctions in the lib-common file.
Appreciate your reply.
9
6
Quote
Status: offline
ScurvyDawg
Forum User
Full Member
Registered: 11/06/02
Posts: 523
You keep saying lib common and they keep saying lib custom.
Why not post the function here for review?
it goes into lib custom NOT lib common.
Why not post the function here for review?
it goes into lib custom NOT lib common.
7
9
Quote
Status: offline
andyofne
Forum User
Chatty
Registered: 08/31/02
Posts: 69
You are correct, I was mistakenly writing lib-common vice lib-custom.
Here is the code that I am trying to put in the block
<?php
$file1 = "./test/HNT/colors.txt";
$lines1 = file($file1);
//$count = count($lines1)
foreach ($lines1 as $line_num1 => $line1)
{
$spos = strpos($line1,'ackground-color="');
if($spos != null && $spos > 0)
{
$spos2 = strpos($line1,'"',($spos+18));
//echo(".....".$spos."------".$spos2);
$str = substr($line1,18,($spos2-($spos+17)));
$bgcol = $str;
//echo($bgcol);
}
$spos1 = strpos($line1,"ont-color=");
if($spos1 != null && $spos1 > 0)
{
$spos2 = strpos($line1,'"',($spos1+12));
//echo(".....".$spos."------".$spos2);
$str = substr($line1,12,($spos2-($spos1+11)));
$fontcol = $str;
$linkcol = $fontcol;
//echo("||".$fontcol);
}
$spos1 = strpos($line1,"ink-color=");
if($spos1 != null && $spos1 > 0)
{
$str = substr($line1,12,(strlen($line1)-15));
$linkcol = $str;
echo("||".$linkcol);
}
$spos = strpos($line1,"crollamount=");
if($spos != null && $spos > 0)
{
$spos2 = strpos($line1,'"',($spos+14));
//echo(".....".$spos."------".$spos2);
$str = substr($line1,14,($spos2-($spos+13)));
$scamount = $str;
//echo("||".$scamount);
}
$spos = strpos($line1,"crolldelay=");
if($spos != null && $spos > 0)
{
$spos2 = strpos($line1,'"',($spos+13));
//echo(".....".$spos."------".$spos2);
$str = substr($line1,13,($spos2 - ($spos+12)));
$scdelay = $str;
//echo("||".$scdelay);
}
$spos = strpos($line1,"idth=");
if($spos != null && $spos > 0)
{
$spos2 = strpos($line1,'"',($spos+7));
//echo(".....".$spos."------".$spos2);
$str = substr($line1,7,($spos2-($spos+6)));
$width = $str;
//echo("||".$width);
}
$spos = strpos($line1,"eight=");
if($spos != null && $spos > 0)
{
$spos2 = strpos($line1,'"',($spos+8));
//echo(".....".$spos."------".$spos2);
$str = substr($line1,8,($spos2-($spos+7)));
$height = $str;
//echo("||".$height);
}
$spos = strpos($line1,"ont-size=");
if($spos != null && $spos > 0)
{
$spos2 = strpos($line1,'"',($spos+11));
//echo(".....".$spos."------".$spos2);
$str = substr($line1,11,($spos2-($spos+10)));
$fsize = $str;
//echo("||".$fsize);
}
}
?>
<table width=<?php echo($width); ?> height=<?php echo($height); ?> >
<tr><td>
<marquee height=<?php echo($height); ?> width=<?php echo($width); ?> bgcolor=<?php echo($bgcol); ?>
scrollamount=<?php echo($scamount); ?> scrolldelay=<?php echo($scdelay); ?> direction=up
onmouseover="this.stop()" onmouseout="this.start()">
<br>
<?php
$file1 = "./test/HNT/news.txt";
$lines = file($file1);
$count = count($lines);
$newsf = false;
$linkf = true;
foreach ($lines as $line_num => $line)
{
if($newsf == false && $linkf == true)
{
$spos = strpos($line,"NEWS=");
if($spos != null && $spos > 0)
{
$spos2 = strpos($line,'"',($spos+7));
$newsstr = substr($line,7,($spos2-($spos+6)));
//echo("<div align=left style="color: ".$fontcol.";" >".$newsstr."</div>");
$newsf = true;
}
}
else if( $linkf == true && $newsf == true)
{
$spos = strpos($line,"LINK=");
if($spos != null && $spos > 0)
{
$spos2 = strpos($line,'"',($spos+7));
$linkstr = substr($line,7,($spos2-($spos+6)));
//echo("<div align=left><a href=".$linkstr." style="color: ".$linkcol."; ">".$linkstr."</a></div><br><br>");
echo("<div align=left style="margin: 10px;"><a href=".$linkstr." style="color: ".$linkcol."; font-size: ".$fsize."; text-decoration: none;
font-weight: bold;">".$newsstr."</a></div><br>");
$newsf = false;
$linkf = true;
}
else
{
$linkf = false;
echo("<div style="color: red; font-weight: bold;"> Improper Usage of HIOX NEWS TICKER </div>");
}
}
}
?>
<br>
</marquee>
<div align=center style="background-color: <?php echo($bgcol); ?>; color: white; font-size: 10px;">
</td></tr>
</table>
Here is the code that I am trying to put in the block
Text Formatted Code
<?php
$file1 = "./test/HNT/colors.txt";
$lines1 = file($file1);
//$count = count($lines1)
foreach ($lines1 as $line_num1 => $line1)
{
$spos = strpos($line1,'ackground-color="');
if($spos != null && $spos > 0)
{
$spos2 = strpos($line1,'"',($spos+18));
//echo(".....".$spos."------".$spos2);
$str = substr($line1,18,($spos2-($spos+17)));
$bgcol = $str;
//echo($bgcol);
}
$spos1 = strpos($line1,"ont-color=");
if($spos1 != null && $spos1 > 0)
{
$spos2 = strpos($line1,'"',($spos1+12));
//echo(".....".$spos."------".$spos2);
$str = substr($line1,12,($spos2-($spos1+11)));
$fontcol = $str;
$linkcol = $fontcol;
//echo("||".$fontcol);
}
$spos1 = strpos($line1,"ink-color=");
if($spos1 != null && $spos1 > 0)
{
$str = substr($line1,12,(strlen($line1)-15));
$linkcol = $str;
echo("||".$linkcol);
}
$spos = strpos($line1,"crollamount=");
if($spos != null && $spos > 0)
{
$spos2 = strpos($line1,'"',($spos+14));
//echo(".....".$spos."------".$spos2);
$str = substr($line1,14,($spos2-($spos+13)));
$scamount = $str;
//echo("||".$scamount);
}
$spos = strpos($line1,"crolldelay=");
if($spos != null && $spos > 0)
{
$spos2 = strpos($line1,'"',($spos+13));
//echo(".....".$spos."------".$spos2);
$str = substr($line1,13,($spos2 - ($spos+12)));
$scdelay = $str;
//echo("||".$scdelay);
}
$spos = strpos($line1,"idth=");
if($spos != null && $spos > 0)
{
$spos2 = strpos($line1,'"',($spos+7));
//echo(".....".$spos."------".$spos2);
$str = substr($line1,7,($spos2-($spos+6)));
$width = $str;
//echo("||".$width);
}
$spos = strpos($line1,"eight=");
if($spos != null && $spos > 0)
{
$spos2 = strpos($line1,'"',($spos+8));
//echo(".....".$spos."------".$spos2);
$str = substr($line1,8,($spos2-($spos+7)));
$height = $str;
//echo("||".$height);
}
$spos = strpos($line1,"ont-size=");
if($spos != null && $spos > 0)
{
$spos2 = strpos($line1,'"',($spos+11));
//echo(".....".$spos."------".$spos2);
$str = substr($line1,11,($spos2-($spos+10)));
$fsize = $str;
//echo("||".$fsize);
}
}
?>
<table width=<?php echo($width); ?> height=<?php echo($height); ?> >
<tr><td>
<marquee height=<?php echo($height); ?> width=<?php echo($width); ?> bgcolor=<?php echo($bgcol); ?>
scrollamount=<?php echo($scamount); ?> scrolldelay=<?php echo($scdelay); ?> direction=up
onmouseover="this.stop()" onmouseout="this.start()">
<br>
<?php
$file1 = "./test/HNT/news.txt";
$lines = file($file1);
$count = count($lines);
$newsf = false;
$linkf = true;
foreach ($lines as $line_num => $line)
{
if($newsf == false && $linkf == true)
{
$spos = strpos($line,"NEWS=");
if($spos != null && $spos > 0)
{
$spos2 = strpos($line,'"',($spos+7));
$newsstr = substr($line,7,($spos2-($spos+6)));
//echo("<div align=left style="color: ".$fontcol.";" >".$newsstr."</div>");
$newsf = true;
}
}
else if( $linkf == true && $newsf == true)
{
$spos = strpos($line,"LINK=");
if($spos != null && $spos > 0)
{
$spos2 = strpos($line,'"',($spos+7));
$linkstr = substr($line,7,($spos2-($spos+6)));
//echo("<div align=left><a href=".$linkstr." style="color: ".$linkcol."; ">".$linkstr."</a></div><br><br>");
echo("<div align=left style="margin: 10px;"><a href=".$linkstr." style="color: ".$linkcol."; font-size: ".$fsize."; text-decoration: none;
font-weight: bold;">".$newsstr."</a></div><br>");
$newsf = false;
$linkf = true;
}
else
{
$linkf = false;
echo("<div style="color: red; font-weight: bold;"> Improper Usage of HIOX NEWS TICKER </div>");
}
}
}
?>
<br>
</marquee>
<div align=center style="background-color: <?php echo($bgcol); ?>; color: white; font-size: 10px;">
</td></tr>
</table>
8
7
Quote
Status: Banned
machinari
Forum User
Full Member
Registered: 03/22/04
Posts: 1512
all that within one function that returns a variable rather than executing code directly... something like this:
$file1 = "./test/HNT/colors.txt";
$lines1 = file($file1);
$retval = '';
foreach ($lines1 as $line_num1 => $line1)
{
$spos = strpos($line1,'ackground-color="');
if(($spos != null) && ($spos > 0))
{
$spos2 = strpos($line1,'"',($spos+18));
$str = substr($line1,18,($spos2-($spos+17)));
$bgcol = $str;
}
$spos1 = strpos($line1,"ont-color=");
if(($spos1 != null) && ($spos1 > 0))
{
$spos2 = strpos($line1,'"',($spos1+12));
$str = substr($line1,12,($spos2-($spos1+11)));
$fontcol = $str;
$linkcol = $fontcol;
}
$spos1 = strpos($line1,"ink-color=");
if(($spos1 != null) && ($spos1 > 0))
{
$str = substr($line1,12,(strlen($line1)-15));
$linkcol = $str;
$retval .= '||' . $linkcol;
}
$spos = strpos($line1,"crollamount=");
if(($spos != null) && ($spos > 0))
{
$spos2 = strpos($line1,'"',($spos+14));
$str = substr($line1,14,($spos2-($spos+13)));
$scamount = $str;
}
$spos = strpos($line1,"crolldelay=");
if($spos != null && $spos > 0)
{
$spos2 = strpos($line1,'"',($spos+13));
$str = substr($line1,13,($spos2 - ($spos+12)));
$scdelay = $str;
}
$spos = strpos($line1,"idth=");
if(($spos != null) && ($spos > 0))
{
$spos2 = strpos($line1,'"',($spos+7));
$str = substr($line1,7,($spos2-($spos+6)));
$width = $str;
}
$spos = strpos($line1,"eight=");
if(($spos != null) && ($spos > 0))
{
$spos2 = strpos($line1,'"',($spos+8));
$str = substr($line1,8,($spos2-($spos+7)));
$height = $str;
}
$spos = strpos($line1,"ont-size=");
if(($spos != null) && ($spos > 0))
{
$spos2 = strpos($line1,'"',($spos+11));
$str = substr($line1,11,($spos2-($spos+10)));
$fsize = $str;
}
}
$retval = '<table width='.$width.' height='.$height.'><tr><td>';
$retval .= '<marquee height='.$height.' width='.$width.' bgcolor='.$bgcol.' scrollamount='.$scamount.' scrolldelay='.$scdelay.' direction=up onmouseover="this.stop()" onmouseout="this.start()"><br>';
$file1 = './test/HNT/news.txt';
$lines = file($file1);
$count = count($lines);
$newsf = false;
$linkf = true;
foreach ($lines as $line_num => $line)
{
if(($newsf == false) && ($linkf == true))
{
$spos = strpos($line,"NEWS=");
if(($spos != null) && ($spos > 0))
{
$spos2 = strpos($line,'"',($spos+7));
$newsstr = substr($line,7,($spos2-($spos+6)));
$newsf = true;
}
}
elseif(($linkf == true) && ($newsf == true))
{
$spos = strpos($line,"LINK=");
if(($spos != null) && ($spos > 0))
{
$spos2 = strpos($line,'"',($spos+7));
$linkstr = substr($line,7,($spos2-($spos+6)));
$retval .= '<div align=left style="margin: 10px;"><a href="'.$linkstr.'" style="color: '.$linkcol.'; font-size: '.$fsize.'; text-decoration: none; font-weight: bold;">'.$newsstr.'</a></div><br>';
$newsf = false;
$linkf = true;
}
else
{
$linkf = false;
$retval .= '<div style="color: red; font-weight: bold;"> Improper Usage of HIOX NEWS TICKER </div>';
}
}
}
$retval .= '<br></marquee>';
$retval .= '<div align=center style="background-color: '.$bgcol.'; color: white; font-size: 10px;">';
$retval .= '</td></tr></table>';
return $retval;
}
so put that function into lib-custom.php and create a new php block from your admin > blocks > new block editor...
name that block "phpblock_scrollnews" making sure not to use parentheses.
whether or not this function works, I don't know... I only put it into a variable for you and made a few minor changes to syntax.
hope all goes well
Text Formatted Code
function phpblock_scrollNews(){$file1 = "./test/HNT/colors.txt";
$lines1 = file($file1);
$retval = '';
foreach ($lines1 as $line_num1 => $line1)
{
$spos = strpos($line1,'ackground-color="');
if(($spos != null) && ($spos > 0))
{
$spos2 = strpos($line1,'"',($spos+18));
$str = substr($line1,18,($spos2-($spos+17)));
$bgcol = $str;
}
$spos1 = strpos($line1,"ont-color=");
if(($spos1 != null) && ($spos1 > 0))
{
$spos2 = strpos($line1,'"',($spos1+12));
$str = substr($line1,12,($spos2-($spos1+11)));
$fontcol = $str;
$linkcol = $fontcol;
}
$spos1 = strpos($line1,"ink-color=");
if(($spos1 != null) && ($spos1 > 0))
{
$str = substr($line1,12,(strlen($line1)-15));
$linkcol = $str;
$retval .= '||' . $linkcol;
}
$spos = strpos($line1,"crollamount=");
if(($spos != null) && ($spos > 0))
{
$spos2 = strpos($line1,'"',($spos+14));
$str = substr($line1,14,($spos2-($spos+13)));
$scamount = $str;
}
$spos = strpos($line1,"crolldelay=");
if($spos != null && $spos > 0)
{
$spos2 = strpos($line1,'"',($spos+13));
$str = substr($line1,13,($spos2 - ($spos+12)));
$scdelay = $str;
}
$spos = strpos($line1,"idth=");
if(($spos != null) && ($spos > 0))
{
$spos2 = strpos($line1,'"',($spos+7));
$str = substr($line1,7,($spos2-($spos+6)));
$width = $str;
}
$spos = strpos($line1,"eight=");
if(($spos != null) && ($spos > 0))
{
$spos2 = strpos($line1,'"',($spos+8));
$str = substr($line1,8,($spos2-($spos+7)));
$height = $str;
}
$spos = strpos($line1,"ont-size=");
if(($spos != null) && ($spos > 0))
{
$spos2 = strpos($line1,'"',($spos+11));
$str = substr($line1,11,($spos2-($spos+10)));
$fsize = $str;
}
}
$retval = '<table width='.$width.' height='.$height.'><tr><td>';
$retval .= '<marquee height='.$height.' width='.$width.' bgcolor='.$bgcol.' scrollamount='.$scamount.' scrolldelay='.$scdelay.' direction=up onmouseover="this.stop()" onmouseout="this.start()"><br>';
$file1 = './test/HNT/news.txt';
$lines = file($file1);
$count = count($lines);
$newsf = false;
$linkf = true;
foreach ($lines as $line_num => $line)
{
if(($newsf == false) && ($linkf == true))
{
$spos = strpos($line,"NEWS=");
if(($spos != null) && ($spos > 0))
{
$spos2 = strpos($line,'"',($spos+7));
$newsstr = substr($line,7,($spos2-($spos+6)));
$newsf = true;
}
}
elseif(($linkf == true) && ($newsf == true))
{
$spos = strpos($line,"LINK=");
if(($spos != null) && ($spos > 0))
{
$spos2 = strpos($line,'"',($spos+7));
$linkstr = substr($line,7,($spos2-($spos+6)));
$retval .= '<div align=left style="margin: 10px;"><a href="'.$linkstr.'" style="color: '.$linkcol.'; font-size: '.$fsize.'; text-decoration: none; font-weight: bold;">'.$newsstr.'</a></div><br>';
$newsf = false;
$linkf = true;
}
else
{
$linkf = false;
$retval .= '<div style="color: red; font-weight: bold;"> Improper Usage of HIOX NEWS TICKER </div>';
}
}
}
$retval .= '<br></marquee>';
$retval .= '<div align=center style="background-color: '.$bgcol.'; color: white; font-size: 10px;">';
$retval .= '</td></tr></table>';
return $retval;
}
so put that function into lib-custom.php and create a new php block from your admin > blocks > new block editor...
name that block "phpblock_scrollnews" making sure not to use parentheses.
whether or not this function works, I don't know... I only put it into a variable for you and made a few minor changes to syntax.
hope all goes well
10
8
Quote
Status: Banned
machinari
Forum User
Full Member
Registered: 03/22/04
Posts: 1512
Quote by andyofne: Actually, that seems to work fine. Thank you very much. Do you have a paypal account!?
glad it works. ...and yes I do! lower right column at summitpages.ca.
7
7
Quote
All times are EST. The time is now 07:51 pm.
- Normal Topic
- Sticky Topic
- Locked Topic
- New Post
- Sticky Topic W/ New Post
- Locked Topic W/ New Post
- View Anonymous Posts
- Able to post
- Filtered HTML Allowed
- Censored Content