forum.coppermine-gallery.net

Support => Older/other versions => cpg1.2 Standalone Support => Topic started by: gabIT on April 19, 2004, 09:04:13 pm

Title: how to add custom php script - DOESN'T WORK :(
Post by: gabIT on April 19, 2004, 09:04:13 pm
Hello!

I use phpAdsNew and I need to display the banner in coppermine.

this is the invocation code from phpAdsNew.

<?php
    if (@include(getenv('DOCUMENT_ROOT').'/AdsNew/phpadsnew.inc.php')) {
        if (!isset($phpAds_context)) $phpAds_context = array();
        $phpAds_raw = view_raw ('zone:223', 0, '_blank', '', '0', $phpAds_context);
        $phpAds_context[] = array('!=' => 'bannerid:'.$phpAds_raw['bannerid']);
    }
   
    // Assign the $phpAds_raw['html'] variable to your template
    // echo $phpAds_raw['html'];
?>

I don't know if I have to include a {BANNER} in the template.html or something else in the theme.php

For me it doesn't make difference. I just need the banener shown in my page! :-)

Ciao!
Grazie!
Gabriele

[edit GauGau]
thread subject changed
[/edit]
Title: how to add custom php script - DOESN'T WORK :(
Post by: Casper on April 19, 2004, 09:47:52 pm
Gabriele,

please give this topic a heading which readers will know what they are going to find in the topic.  A '?' or similar is not enough.
Title: how to add custom php script - DOESN'T WORK :(
Post by: Joachim Müller on April 20, 2004, 09:00:28 am
__________________________________________________________

Check if this works as expected and shows "Banner here" where it's expected to be. If yes, modify the last lines and uncomment
Code: [Select]
return $phpAds_raw['html']; - comment out
Code: [Select]
return 'Banner here';instead (make this a two-step process to check first if the insertion itself works and then if your banner rotation does). Report back if this worked for you.

GauGau
Title: WORKS <EDITED>
Post by: gabIT on April 20, 2004, 12:22:59 pm
problem....

this line
Code: [Select]
if (@include(getenv('DOCUMENT_ROOT').'/AdsNew/phpadsnew.inc.php')) {
causes a critical error in the displaying of the albums
"There was an error while processing a database query"
but it shows the banner.

if I use this
Code: [Select]
if (@include(getenv('DOCUMENT_ROOT').'http://domain.com/AdsNew/phpadsnew.inc.php')) {

the page is ok but no banner
Title: how to add custom php script - DOESN'T WORK :(
Post by: gabIT on April 20, 2004, 01:32:43 pm
I am trying to find a solution to have targeted ads...

Do you think it's possible to have a function that checks the category number (either from the database or from the URL) and choose the right "function theme_custom_banner()"?

For istance...
when the album category is 3, then "function theme_custom_banner3()"
where the zone number 'zone:3'

(praferably, the functions are in a file outside theme.php)

THank you very much!
Gabriele
Title: how to add custom php script - DOESN'T WORK :(
Post by: Joachim Müller on April 20, 2004, 11:04:47 pm
sure this is possible, but I won't do customizations, as I already told you.

GauGau
Title: how to add custom php script - DOESN'T WORK :(
Post by: gabIT on April 20, 2004, 11:19:48 pm
I know. Infact I didn't ask for it. I just asked if it was possible to do it.

THank u!
Title: targeted ads in cpg via phpAdsNew
Post by: gabIT on April 20, 2004, 11:41:03 pm
I use phpAdsNew to manage my ads, campaigns, ... and coppermine for my site.

Coppemrmine uses template.html and gaugau told me how to integrate the phpAdsNew invocation codes into coppermine template page.
(read above)

It works but still, not targeted ads.
 

----- THE NEED -----

I have a variable called {BANNER}

the value of this variable is defined by a function that checks which category you are browsing in for which it takes the piece of code with the specific value (ZONE) in it.

So if I have 10 categories I'll have 10 of the following ZONE CODE (XX = unique zone for unique cat.):

Code: [Select]
if (@include(getenv('DOCUMENT_ROOT').'/AdsNew/phpadsnew.inc.php')) {
if (!isset($phpAds_context)) $phpAds_context = array();
$phpAds_raw = view_raw ('zone:XX', 0, '_blank', '', '0',
$phpAds_context);
$phpAds_context[] = array('!=' => 'bannerid:'.$phpAds_raw['bannerid']);
}


Then there will be the function "theme_custom_banner()" that will take the right zone code (above) and give it on screen with something like this:

function theme_custom_banner()
{
if category ID = number XX
then take the ZONE CODE XX
return 'Banner for category XX';
}

So, in this way I will need one external file (external from theme.php) where I'll have all my ZONE CODES in it

I don't know if it's a big work but even if it is I am willing to pay!

Thanks!
Gabriele
Title: [Moderation]
Post by: Joachim Müller on April 20, 2004, 11:44:37 pm
merged threads.

GauGau
Title: Re: how to add custom php script - DOESN'T WORK :(
Post by: shutiri on May 07, 2004, 01:13:51 pm
I don't understand the last instructions:

Quote
If yes, modify the last lines and uncomment
Code:
return $phpAds_raw['html'];
- comment out
Code:
return 'Banner here';
instead (make this a two-step process to check first if the insertion itself works and then if your banner rotation does). Report back if this worked for you.


There are 3 commented lines at the end.  I suppose I should uncomment the last 2.
Where does the phpadsnew code goes ?
Guessing:


Code: [Select]
// Assign the $phpAds_raw['html'] variable to your template
echo $phpAds_raw['html'];
return $phpAds_raw['html'];
return '<?php
    
if (@include(getenv('DOCUMENT_ROOT').'/phpadsnew/phpadsnew.inc.php')) {
        if (!isset(
$phpAds_context)) $phpAds_context = array();
        
$phpAds_raw view_raw ('zone:7'0'_blank''''0'$phpAds_context);
        echo 
$phpAds_raw['html'];
    }
?>

';
}

maybe without the <?php and ?>

thank you
shutiri.
Title: Re: how to add custom php script - DOESN'T WORK :(
Post by: shutiri on May 07, 2004, 01:28:42 pm
Ok, none of them worked (with or without <?php ?>)  I got errors.

then I tried:
Code: [Select]
// Assign the $phpAds_raw['html'] variable to your template
echo $phpAds_raw['html'];
return $phpAds_raw['html'];
//return 'Banner here';
    if (@include(getenv('DOCUMENT_ROOT').'/phpadsnew/phpadsnew.inc.php')) {
        if (!isset($phpAds_context)) $phpAds_context = array();
        $phpAds_raw = view_raw ('zone:7', 0, '_blank', '', '0', $phpAds_context);
        echo $phpAds_raw['html'];
    }


}

then I tried with complete URL : 'http://www.huecos.com/phpadsnew/phpadsnew.inc.php' and didn't worked either.  I don't get any error, just that the banner doesn't shows up.

thank you
shutiri.

Title: Re: how to add custom php script - DOESN'T WORK :(
Post by: Joachim Müller on May 07, 2004, 03:11:09 pm
when uncommeting
Code: [Select]
//return $phpAds_raw['html'];, did you see the ouput "Banner here" on your page?

GauGau
Title: Re: how to add custom php script - DOESN'T WORK :(
Post by: shutiri on May 07, 2004, 09:24:19 pm
Yes,  I went all the way until this, and the "banner here" message is there:  www.huecos.com/fotos

thank you.
shutiri.
Title: Re: how to add custom php script - DOESN'T WORK :(
Post by: Joachim Müller on May 08, 2004, 07:55:32 am
that's the "proof of concept" then - you are able to output things with your theme. If it doesn't work as expected from now on, you'll have to modify your script you're actually including.

GauGau
Title: Re: how to add custom php script - DOESN'T WORK :(
Post by: shutiri on May 08, 2004, 08:48:17 am
Yes, I understand that's the "proof of concept".   I wrote two posts ago some of  the things I tried to actually include the real code I have for the banner (I tried all combinations that came to my head since,  but don't get it working.  Can you please tell me where should I put the banner code ?  That's the last thing I need to get everything working  ;).

Thank you for your patience.
shutiri.
Title: Re: how to add custom php script - DOESN'T WORK :(
Post by: Joachim Müller on May 08, 2004, 11:32:59 am
this would mean I'd actually have to look into the script you're trying to include. As I don't know phpAdsNew I'm reluctant to do so (same thing applies as I have already posted on this thread before, replying to gabIT: I won't do customizations for you).
Coppermine it set up to handle other scripts now, but if you can't get this other script working I can't help you.
Create a fresh file called test.php with this content
Code: [Select]
<?php
    
if (@include(getenv('DOCUMENT_ROOT').'/phpadsnew/phpadsnew.inc.php')) {
        if (!isset(
$phpAds_context)) $phpAds_context = array();
        
$phpAds_raw view_raw ('zone:7'0'_blank''''0'$phpAds_context);
        echo 
$phpAds_raw['html'];
    }
?>
Check if it works (run it in your browser). If it doesn't work as expected, you've come to the wrong place...

GauGau
Title: Re: how to add custom php script - DOESN'T WORK :(
Post by: shutiri on May 08, 2004, 12:46:50 pm
yes, it works... it's the same code I had from phpadsnew code generator.  The banners are set up and working correctly.  My question is how do I "paste" it to the theme.php ?

I suppose I have to put it in one of this lines but I don't really know.

Code: [Select]
echo $phpAds_raw['html'];
return $phpAds_raw['html'];
//return 'Banner here';

Sorry if my question seems too stupid, but I really don't know how to refer to a file (test.php in this case) from the theme.php

thank you,
shutiri.


Title: Re: how to add custom php script - DOESN'T WORK :(
Post by: Joachim Müller on May 08, 2004, 05:29:48 pm
Code: [Select]
function theme_custom_banner()
{
    if (@include(getenv('DOCUMENT_ROOT').'/phpadsnew/phpadsnew.inc.php')) {
        if (!isset($phpAds_context)) $phpAds_context = array();
        $phpAds_raw = view_raw ('zone:7', 0, '_blank', '', '0', $phpAds_context);
        $return = $phpAds_raw['html'];
    }

return $return;
}
Title: Re: how to add custom php script - DOESN'T WORK :(
Post by: shutiri on May 08, 2004, 10:00:57 pm
Ok.  I'm getting closer.  Now I'm having the same problem than gabIT:

Quote
this line

Code: [Select]
if (@include(getenv('DOCUMENT_ROOT').'/AdsNew/phpadsnew.inc.php')) {
causes a critical error in the displaying of the albums
"There was an error while processing a database query"
but it shows the banner.

if I use this

Code: [Select]
if (@include(getenv('DOCUMENT_ROOT').'http://domain.com/AdsNew/phpadsnew.inc.php')) {
the page is ok but no banner

How do I solve that ?

thank you.
shutiri.
Title: Re: how to add custom php script - DOESN'T WORK :(
Post by: Joachim Müller on May 09, 2004, 08:29:06 am
I don't know, because I'm not going to look into phpadsnew, since it's a third-party app! Get help on the support board of phpadsnew, not here. There are scripts that just can't be included though...

GauGau
Title: Re: how to add custom php script - DOESN'T WORK :(
Post by: shutiri on May 09, 2004, 09:30:55 am
ok...  thank you. 
Can I create a new topic with the title "phpadsnew/CPG integration" so if somebody knows or already had this trouble can answer me ?

shutiri.
Title: Re: how to add custom php script - DOESN'T WORK :(
Post by: sigepjedi on June 06, 2004, 08:58:26 pm
GauGau


Ive read through many of the posts regarding phpads, and implementing the banner invokation code into coopermine, and as with many of the others Ive ran into the same problems.

Ive followed all the steps throughout this post regardig the modification of theme.php and creating '{BANNER}' => theme_custom_banner() in the $template_vars portion of this file.

Having said that, and reaching the same road blocks, here is a new piece of information to this puzzel:
Running debug upon reaching the roadblock "There was an error while processing a database query."
Ive come across the following:

------------------------
While executing query "SELECT COUNT(*) from BW_comments, BW_pictures  WHERE approved = 'YES' AND BW_comments.pid = BW_pictures.pid " on 0
mySQL error: Table 'adclicks.bw_comments' doesn't exist
------------------------

'BW' is my prefix for Coopermine, and 'adclicks' is my prefix for my phpads database.

If looks as though calling the invocation code of phpads is placing its database name infront of the remaining calls in coopermine. And then the rest just goes to hell.

Thoughts?

Title: Re: how to add custom php script - DOESN'T WORK :(
Post by: Joachim Müller on June 06, 2004, 10:58:22 pm
yes: the mySQL connection to your banner software hasn't been established properly. I'm not sure if your banner script will work at all - you simply can't combine some sorts of scripts.

GauGau
Title: Re: how to add custom php script - DOESN'T WORK :(
Post by: DefenceTalk.com on June 07, 2004, 01:51:31 pm
Interesting. Use anycontent.php to accomplish this. Take a look at our website. The rotating amazon ads at the bottom. ;)
Title: Re: how to add custom php script - DOESN'T WORK :(
Post by: sigepjedi on June 07, 2004, 05:56:47 pm
Interesting. Use anycontent.php to accomplish this. Take a look at our website. The rotating amazon ads at the bottom. ;)

We are using that method of calling banners. I dont think you are grasping the issue at hand with PHPADS.

GAUGAU:

Is there a way in which to re-set the coppermine DB names, or DB prefixes. I think if i re-set this variable after I make my call to phpads, then everything would be back to normal in the coopermine world following the PHPADS call.
Title: Re: how to add custom php script - DOESN'T WORK :(
Post by: Joachim Müller on June 07, 2004, 06:54:51 pm
I don't understand fully - do you mean you want to end the established connection to the db at some point, or do you want to just rename the prefix once?

GauGau
Title: Re: how to add custom php script - DOESN'T WORK :(
Post by: sigepjedi on June 07, 2004, 08:46:21 pm
in calling the banner.php code, thus initiating the communication link to PHPADS, it apparently sets the DB prefix or connection VAR to its own known variable.

-----------EXAMPLE---------------
While executing query "SELECT COUNT(*) from BW_comments, BW_pictures  WHERE approved = 'YES' AND BW_comments.pid = BW_pictures.pid " on 0
mySQL error: Table 'adclicks.bw_comments' doesn't exist
-----------EXAMPLE---------------

coopermine fires, DB name/prefix =  "BW_"
PHPADS fires, DB name/prefix is modified to: "adclicks.BW_"

apparently it overwrites this prefix variable used in DB connectivity.

After I make my call to PHPADS, can i re-initiate the coppermine DB prefix back to "BW_"?

So my code for banner.php would look something like:

Quote
<?php
// PHPADS BANNER CODE
   if (@include('C:/PHPADS/phpadsnew.inc.php')) {
        if (!isset($phpAds_context)) $phpAds_context = array();
        $phpAds_raw = view_raw ('', 31, '_blank', '', '0', $phpAds_context);
        $phpAds_context[] = array('!=' => 'bannerid:'.$phpAds_raw['bannerid']);
    } 
    // Assign the $phpAds_raw['html'] variable to your template
    echo $phpAds_raw['html'];
   $banner = "<center>$phpAds_raw['html']</center>";
// PHPADS BANNER CODE

//RE-INITIATE THE DB PREFIX HERE

?>

So that once PHPADS was done, and coopermine continues through its processes remaining, it has the correct DB prefix.
Title: Re: how to add custom php script - DOESN'T WORK :(
Post by: Joachim Müller on June 08, 2004, 08:06:03 am
I'm not sure what vars are being reset by phpAds, try re-setting the db prefix after the phpAds code like this:
Code: [Select]
$CONFIG['TABLE_PREFIX'] = "yourCopperminePrefix_";
GauGau
Title: Re: how to add custom php script - DOESN'T WORK :(
Post by: sigepjedi on June 08, 2004, 05:45:43 pm
Negative Ghost-Rider, same thing.

I added to the last line of my Banner.php file the re-setting of the DB prefix var.

DEBUG INFO

There was an error while processing a database query.
Quote
While executing query "SELECT COUNT(*) from BW_comments, BW_pictures  WHERE approved = 'YES' AND BW_comments.pid = BW_pictures.pid " on 0

mySQL error: Table 'adclicks.bw_comments' doesn't exist


File: C:\The\Path\To\MySite\include\functions.inc.php - Line: 101


Notice: Undefined index: pid in C:\The\Path\To\MySite\include\functions.inc.php on line 1098
Notice: Undefined index: pid in C:\The\Path\To\MySite\include\functions.inc.php on line 1098
Notice: Undefined index: pid in C:\The\Path\To\MySite\include\functions.inc.php on line 1098
Notice: Undefined index: pid in C:\The\Path\To\MySite\include\functions.inc.php on line 1098
Notice: Undefined index: pid in C:\The\Path\To\MySite\include\functions.inc.php on line 1098
Notice: Undefined index: pid in C:\The\Path\To\MySite\include\functions.inc.php on line 1098
Notice: Undefined index: pid in C:\The\Path\To\MySite\include\functions.inc.php on line 1098
Notice: Undefined index: pid in C:\The\Path\To\MySite\include\functions.inc.php on line 1098
Notice: Undefined index: pid in C:\The\Path\To\MySite\include\functions.inc.php on line 1098
Notice: Undefined index: pid in C:\The\Path\To\MySite\include\functions.inc.php on line 1098
Notice: Undefined index: pid in C:\The\Path\To\MySite\include\functions.inc.php on line 1098
Notice: Undefined index: pid in C:\The\Path\To\MySite\include\functions.inc.php on line 1098
Notice: Undefined index: pid in C:\The\Path\To\MySite\include\functions.inc.php on line 1098

Line 101 of functions.inc.php contains the following (LN 87- LN 103)
Quote
// Error message if a query failed
function db_error($the_error)
{
        global $CONFIG;

        if (!$CONFIG['debug_mode']) {
            cpg_die(CRITICAL_ERROR, 'There was an error while processing a database query', __FILE__, __LINE__);
        } else {

                $the_error .= "\n\nmySQL error: ".mysql_error()."\n";

                $out = "<br />There was an error while processing a database query.<br /><br/>
                    <form name='mysql'><textarea rows=\"8\" cols=\"60\">".htmlspecialchars($the_error)."</textarea></form>";

            cpg_die(CRITICAL_ERROR, $out, __FILE__, __LINE__);
        }
}

Line 1098 of functions.inc.php contains the following (LN1091 - LN 1102)
Quote
     if((($mode == "normal") || ($mode == 'fullsize')) && ($CONFIG['thumb_method']=='im')){

               // return the url to the wm script
               return "wm.php?pid=".$pic_row["pid"]."&mode=".$mode;

       }else{
               // it's a thumb, don't bother wm'ing
               if (is_null($pic_row['pid']) || !isset($CONFIG['url_mode']) || $CONFIG['url_mode']!='hide')
                return $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);
             return 'get_file.php?pid='.$pic_row['pid'].'&size='.$mode;

       }

and, at the very bottom the SQL Query Debug Info:
Quote
USER:
Array
(
    [ID] => f906caa6dd5e01a219b7fb162eca3287
    [am] => 1
    [liv] => Array
        (
           
  • => 108
  • [1] => 263
                [2] => 78
                [3] => 202
            )

    )

     
    GET :
    Array
    (
    )

     
    POST :
    Array
    (
    )

Thoughts?
Title: Re: how to add custom php script - DOESN'T WORK :(
Post by: jriba on December 19, 2004, 02:26:33 am
GauGau:

What's the PRO/CON of making a function in theme.php for the phpAdsNew code (or any other code for that matter) and then inserting the {BANNER} tag into template.html

vs.

insertint the phpAdsNew code directly into template.html ???
Title: Re: how to add custom php script - DOESN'T WORK :(
Post by: Nibbler on December 19, 2004, 02:45:17 am
Only html can go into the template. PHP goes into the theme.php
Title: Re: how to add custom php script - DOESN'T WORK :(
Post by: lucasnet on December 24, 2004, 01:11:04 am
I have a question. I use this solution but i have 1 problem. When i enetered a this codes script show at the bottom of page. Not where {BLABLA} is but at first, before logo. ??? What i must do ?
Title: Re: how to add custom php script - DOESN'T WORK :(
Post by: Nibbler on December 24, 2004, 01:28:02 am
The code you have added probably outputs using echo or similar. It should return all its output as the result of the function in which it resides. If you can't do this easily you can use output buffering to capture the output.
Title: Re: how to add custom php script - DOESN'T WORK :(
Post by: jriba on January 06, 2005, 05:55:45 am
I have solved this problem!

Add the phpAdsNew "Local Mode" php invocation code to the "../include/functions.inc.php" file.  Add it "AS IS" how the phpAdsNew code generator gives it to you.  Make sure to click on "Store the banner inside a variable so it can be used in a template" before generating the phpAdsNew code.  And add it to functions.inc.php at the very top, before
Code: [Select]
// Decode the user profile contained in a cookie
function user_get_profile()

Thats it for the functions.inc.php file.

Edit themes.php, find:
Code: [Select]
global $CONFIG, $THEME_DIR;replace it with:
Code: [Select]
global $CONFIG, $THEME_DIR, $phpAds_raw;
and find:
Code: [Select]
'{ADMIN_MENU}' => theme_admin_mode_menu()add after:
Code: [Select]
'{BANNER}' => $phpAds_raw['html']
and make sure to add a comma (" , ") at the end of
Code: [Select]
'{ADMIN_MENU}' => theme_admin_mode_menu() to make it look like this
Code: [Select]
'{ADMIN_MENU}' => theme_admin_mode_menu(),since you are adding to the array.

That's it..

Enjoy!
Title: Re: how to add custom php script - DOESN'T WORK :(
Post by: lucasnet on January 06, 2005, 04:32:58 pm
Thanks  ;)
Title: Re: how to add custom php script - DOESN'T WORK :(
Post by: jriba on January 06, 2005, 10:33:09 pm
I should probably also mention 2 things that might be obvious to some, but not others:

1) Remember to put the {BANNER} where ever you want the banner to appear in template.html

2) Remember to take out the first and last lines of the invocation code: "<$php" and "?>", when you put it in functions.inc.php

That's it!