Page 1 of 1
External PHP aplication
Posted: Sat Aug 13, 2005 6:47 pm
by Xanthouos
I came across
this nifty code that grabs data from webalizer and displays it to the public so you do not have to let people into cPanel.
I want to use it as a static page, but am getting errors. IF you go streight to the script
http://blog.butlersonline.net/include/bstats.php, it works, but when calling through s9y:
http://blog.butlersonline.net/pages/stats.htm, I get errors.
How would I remedy this?
Thank you!!

Re: External PHP aplication
Posted: Sun Aug 14, 2005 1:57 am
by garvinhicking
The script there is written badly with global variable scopes.
Since embedded PHP applications for serendipity are always run in a function context of a plugin, when you define $user and anything else, it will not be available in the function scope.
Without technobabble, chagne this:
Code: Select all
$user = 'user'; //cpanel username
$pass = 'pass'; //cpanel password
$url = 'www.yourdomain.com'; //do not include 'http://'
into this:
Code: Select all
$GLOBALS['user'] = 'user'; //cpanel username
$GLOBALS['pass'] = 'pass'; //cpanel password
$GLOBALS['url'] = 'www.yourdomain.com'; //do not include 'http://'
and then it should work.
Regards,
Garvin
Posted: Sun Aug 14, 2005 12:00 pm
by Xanthouos
Thank you Garvin, I was certain you would come to the rescue here.

Thank you! I appreciate that you not only give the solution, but also explain how/why.
So, the first page of the Webalizer stats work, but it doesn't work to follow the links for the inuvidual months. I even changed the extension to php, but it didn't help.
Is it possible for the script to work, following the links to display the stats for each month?
http://www.blog.butlersonline.net/pages/stats.php
Thank you!
Posted: Mon Aug 15, 2005 12:27 pm
by garvinhicking
Well...the script is just buggy about recognizing the right month to display. It seems to parse the QUERY_STRING, but then doesn't seem to find the appropriate file. You'll need to contact the author of the code to polish the code a bit more; sadly this is beyond the scope of free serendipity-support I can give. I'm really sorry; if you need this, we might get it worked out (if the original author can't help you) if you might want to consider my amazon wishlist... *gg*
Best regards,
Garvin
(I hope I don't sound too stubborn or what; but I really have very limited time, and s9y is already sucking up much of my time; so I have to cut it somewhere...)
Posted: Mon Aug 15, 2005 11:33 pm
by Xanthouos
Well, it's not
that important, although it would be nice. If I needed it for more s9y sites, I would jump at the oppertunity to get something on your wish list. I actually looked over it and started going through the process of it, but wading through all that German was a bit tough.
Anyway, thank you for helping on the first step and for your generosity of giving some time. I understand completely your not eing able to go further here.
If I do feel the need, maybe I'll paypal you, as that's easier... (
First I'll have to come up with $omething, since I'm not exactly rolling in it)

Posted: Tue Aug 16, 2005 3:22 pm
by garvinhicking
Well...try this script:
Code: Select all
<?php
// See http://www.s9y.org/forums/viewtopic.php?t=2475
// Modifications by Garvin Hicking.
$GLOBALS['user'] = 'user'; // cpanel username
$GLOBALS['pass'] = 'pass'; // cpanel password
$GLOBALS['url'] = 'www.yourdomain.com'; // do not include 'http://'
// retrieves the webalizer file, either .html or .png
function getFile($file) {
return file_get_contents("http://" . $GLOBALS['user'] . ":" . $GLOBALS['pass'] . "@" . $GLOBALS['url'] . ":2082/tmp/" . $GLOBALS['user'] . "/webalizer/" . $file);
}
// alters links, either .html or .png
function changeLinks($subject, $type) {
return preg_replace("/($type=\")(?!http)(.*?)\"/is", "$1" . $_SERVER['PHP_SELF'] . "?$2\"" ,$subject);
}
if (preg_match('@\?(.+)@i', $_SERVER['REQUEST_URI'], $uri)) {
$url = $uri[1];
} else {
$url = $_SERVER['QUERY_STRING'];
}
if (!empty($url)) {
// get file (whether png or html)
$page = getFile($url);
if (strpos($url, '.png') !== false) {
// if png, output appropriate header
header("Content-type: image/png");
} else {
// change the .png src(s)
$page = changeLinks($page, 'src');
}
} else {
// get index
$page = getFile('index.html');
// change links
$page = changeLinks($page, 'href');
// change the usage.png src
$page = changeLinks($page, 'src');
}
// output it
echo $page;
Have fun.
Regards,
Garvin
Posted: Sun Aug 21, 2005 8:43 pm
by Xanthouos
Let me begin by thanking you Garvin for taking another shot at this.
It still doesn't work for the induvidual month stats.
Here is the embedded version. If you mouse over the link, you'll see that it doesn't give the right address, and if you click it, since it's invalid, it just returns to the home page.
This is the old script run directly, and if you click on the month, it'll display the stats.
As it is, displaying only the monthly stats is sufficient. If you are interested in it, as a possible feature or plug-in, and would like to continue working out the code, that would be cool. Otherwise, working as it is is already wonderful.
Keep up the good work!

Posted: Wed Aug 24, 2005 9:18 pm
by Xanthouos
So,
SuperGarv comes to the rescue again!!
If anyone using S9Y (...& everyone should), has
Webalizer on their host, and would like to display the stats for the general public, you can download a Serendipity Plug-in for it here:
serendipity_event_cpanel.zip
You can see the plugin in action
here.
Once agian, Thank you Garvin for your help in this and all those who make this forum a wonderful place with excelent support.
Keep up the good work!
