vBadvanced Forums  
Go Back   vBadvanced Forums > vBadvanced Products > vBadvanced CMPS > vBa CMPS v1.x (Archive - Closed for Posting) > Troubleshooting / "How do I..." Questions

 
 
Thread Tools Display Modes
  #1  
Old 06-15-2004, 09:32 PM
maximux1 maximux1 is offline
Senior Member
 
Join Date: Feb 2004
Posts: 101
Default PHP in module - just cant get it?

I have a very simple PHP RSS reader that I want to include in a module.

PHP Code:
//marijuana_newsfeed.php

<?
   
include('/some/path/html/RSS/RSS.php');
   
$rss = new RSS();
   
$rss->display('http://www.domain.com/path/to/newsfeeds/aggragator.php');
?>
Here is the output of the above script when called directly;

http://www.marijuana.com/420/modules...a_newsfeed.php

Script works, modules dont?

I've tried to create a new module, then use the drop down menu to select 'marijuana_newsfeed.php' and regardless of where I place the module on the page the php output always shows up at the very top of the page, prior to navbar or anything else.

My first thought was a broken table somewhere, so I removed all table formatting from the php script output - That made no difference.

Is there no way to just do a nice "include()" call into a module and spit out the contents of the php script? I've been working on this a few hours and have tried everything in the vBa CMPS manual - even changing any echo() statements to '$variable .=' and using $variable in a custom template, as suggested in a thread I researched.

If anyone has any ideas on this, I would greatly appreciate your help!

Thanks,
Max
__________________
"There are two ways of being creative. One can sing and dance. Or one can create an environment in which singers and dancers flourish."
-- Warren G. Bennis (b. 1925), American writer, educator, University of Southern California sociologist

Last edited by maximux1; 06-15-2004 at 09:34 PM.
  #2  
Old 06-15-2004, 10:33 PM
maximux1 maximux1 is offline
Senior Member
 
Join Date: Feb 2004
Posts: 101
Default Re: PHP in module - just cant get it?

aiy - this is maddening. I must just be overlooking something simple.
__________________
"There are two ways of being creative. One can sing and dance. Or one can create an environment in which singers and dancers flourish."
-- Warren G. Bennis (b. 1925), American writer, educator, University of Southern California sociologist
  #3  
Old 06-16-2004, 12:32 AM
maximux1 maximux1 is offline
Senior Member
 
Join Date: Feb 2004
Posts: 101
Arrow Re: PHP in module - just cant get it?

Oh, now I get it -

ok, I have figured my problem out. It mainly had to do with my php outputting straight to the buffer instead of being stored in a string.

Here's my new module php code - I include this when creating a new module in CMPS, via php file. I add 'adv_portal_marijuana_feed' to the cached templates field on the create module page.

PHP Code:
<?

   ob_start
();
   include(
'/SOME/PATH/html/RSS/RSS.php');
   
$rss = new RSS();
   
$rss->display('http://www.marijuana.com/newsfeeds/aggragator.php?q=marijuana&num=10&f=marijuana');
   
$string ob_get_contents();
   
ob_end_clean();   
   eval(
'$home[$mods[\'modid\']][\'content\'] = "' fetch_template('adv_portal_marijuana_feed') . '";');

?>
Notice the use of ob_start() and family. This ultimely was the solution to my problem. ob_start() is well documented at php.net and I advise you to read it if you are incorporating your own php modules. In a nutshell, ob_start() (http://www.php.net/manual/en/function.ob-start.php) will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer.

We can then assisgn the contents of the buffer to $string and use that in our template called from custom php mods.

Hope this helps someone else.

Max
Marijuana.Com
__________________
"There are two ways of being creative. One can sing and dance. Or one can create an environment in which singers and dancers flourish."
-- Warren G. Bennis (b. 1925), American writer, educator, University of Southern California sociologist

Last edited by maximux1; 06-16-2004 at 12:36 AM.
  #4  
Old 06-16-2004, 02:14 AM
maximux1 maximux1 is offline
Senior Member
 
Join Date: Feb 2004
Posts: 101
Default Re: PHP in module - just cant get it?

ran into another neat little problem of redclaring classes when I tried to include multiple modules using the same php class. Found a nice and simple solution if anyone runs into the same issue -

Simply surround your class with the following code, like so;

PHP Code:
if ( !class_existsmyclassname ) ) {

     class 
myclassname {
          ...
     }

This just checks to see if the class has already been declared and if so does not redeclare it, thus avoiding the "Class already declared" error.
__________________
"There are two ways of being creative. One can sing and dance. Or one can create an environment in which singers and dancers flourish."
-- Warren G. Bennis (b. 1925), American writer, educator, University of Southern California sociologist

Last edited by maximux1; 06-16-2004 at 02:18 AM.
  #5  
Old 10-19-2004, 09:55 AM
Jack_B Jack_B is offline
Junior Member
 
Join Date: Jun 2004
Posts: 1
Default Re: PHP in module - just cant get it?

I know, this thread is kinda old, even though you helped me out with the same problem. thank you - nice solution ...
  #6  
Old 10-19-2004, 11:33 AM
jugo jugo is offline
Junior Member
 
Join Date: Jun 2004
Posts: 22
Default Re: PHP in module - just cant get it?

Threads like this should be put into a FAQ type of Setting....the most useful threads.....
  #7  
Old 02-17-2005, 09:44 AM
diades diades is offline
Junior Member
 
Join Date: Jun 2004
Posts: 27
Default Re: PHP in module - just cant get it?

Hi

Could you help me out here? I seem to be missing something (like my brain).
I have created a php file that deilvers, in string form, markup.
I create a page and a template for it that calls the file from the droplist.
and add adv_portal_mypage to the cached file list.

The script from above I edit thus (in my php file)

PHP Code:
<? 
   ob_start
(); 
   
$x "<p>Blah</p>"
   
$string ob_get_contents(); 
   
ob_end_clean();     
   eval(
'$home[$mods[\'modid\']][\'content\'] = "' fetch_template('adv_portal_mypage') . '";'); 
?>
am I correct?
__________________
Thanks,

Keith
The City Forums
  #8  
Old 02-17-2005, 09:50 AM
Brian's Avatar
Brian Brian is offline
Administrator
 
Join Date: Jan 2004
Location: Georgia, USA
Posts: 34,240
Default Re: PHP in module - just cant get it?

Did you put $string in your 'adv_portal_mypage' template?
  #9  
Old 02-17-2005, 10:13 AM
diades diades is offline
Junior Member
 
Join Date: Jun 2004
Posts: 27
Default Re: PHP in module - just cant get it?

Hi Brian

This is what I have:

The page:
Title: Browser Archive Page
Page Identifier:browserarchive
Page Template:adv_portal_browser_archive_page

Module:
Module Title:Browser Archive Repository
File to Include:browserpart.php
Active: Yes
Templates Used:adv_portal_browser_archiv_page

Template:adv_portal_browser_archive_page
content:
PHP Code:
.....
           <
tbody id="collapseobj_opera" style="$collapseobj_opera">
             <
tr>
               <
td>
<!--
start adv_portal_browser_archive
-->
$browserString
<!--
end adv_portal_browser_archive
-->
               </
td>
             </
tr>
           </
tbody
browserpart.php
PHP Code:
<?
error_reporting
(E_ALL);
ob_start();
include(
$_SERVER['DOCUMENT_ROOT']."/forums/modules/global_functions.php");
function 
insertLinks(){
$fname $_SERVER['DOCUMENT_ROOT']."/forums/modules/browser.xml";
$flag "r";
$fileHandle openfile($fname,$flag);
$supplier getStruct($fileHandle);
$cnt 0;
foreach(
$supplier as $browser){
  if(
$browser["tag"] == "BROWSER"){
    
$cnt++;
  }
}
$browserString '<!-- Start browser input list --><div class="brDiv"><table summary="">';
$name "";
$type "";
$version "";
$country "";
$browserString "";
foreach(
$supplier as $supp){
  if(
$supp["type"] == "open" && $supp["tag"] == "MANUFACTURER"){
  
$name $supp["attributes"]["NAME"];
  
$type $supp["attributes"]["TYPE"];
  
$version $supp["attributes"]["VERSION"];
    
$browserString .= '<tr><td class="thead">';
    
$browserString .= $supp["attributes"]["NAME"].' '.$supp["attributes"]["TYPE"].' v'.$supp["attributes"]["VERSION"];
    
$browserString .= '</td></tr>';
  }else if(
$supp["type"] == "open" && $supp["tag"] == "LANGUAGE"){
  
$country $supp["attributes"]["COUNTRY"];
    
$browserString .= '<tr><td class="alt2">';
    
$browserString .= $supp["attributes"]["COUNTRY"];
    
$browserString .= '</td></tr>';
  }else if(
$supp["type"] == "complete" && $supp["tag"] == "BROWSER"){
    
$browserString .= '<tr><td class="alt1">';
    
$browserString .= '<a href="'.$supp["attributes"]["HREF"].'" title="'.$supp["attributes"]["BLAH"].'">Download '.$name.' '.$type.' v'.$version.' ('.$country.') '.$supp["attributes"]["BLAH"].'</a>';
    
$browserString .= '</td></tr>';
  }else{
  }
}
$browserString .= '</table></div><!-- End browser input list -->';
return 
$browserString;
}
$browserString ob_get_contents();
ob_end_clean();
eval(
'$home[$mods[\'modid\']][\'content\'] = "' fetch_template('adv_portal_browser_archive_page') . '";'); 
?>
and ... nothing
__________________
Thanks,

Keith
The City Forums
  #10  
Old 02-17-2005, 10:28 AM
Brian's Avatar
Brian Brian is offline
Administrator
 
Join Date: Jan 2004
Location: Georgia, USA
Posts: 34,240
Default Re: PHP in module - just cant get it?

Try removing the ob_start() and ob_end_clean() stuff. Then replace this:

$browserString = ob_get_contents();

With this:

$browserString = insertLinks();

And see if that works any better.
  #11  
Old 02-17-2005, 10:43 AM
diades diades is offline
Junior Member
 
Join Date: Jun 2004
Posts: 27
Default Re: PHP in module - just cant get it?

Gotcha!


Many thanks Brian!:tup:
__________________
Thanks,

Keith
The City Forums
  #12  
Old 02-17-2005, 12:32 PM
diades diades is offline
Junior Member
 
Join Date: Jun 2004
Posts: 27
Default Re: PHP in module - just cant get it?

Expanding on the theme, if I wanted to return different sections for various parts of the template (One per collapse section) would I have to create a php page and module to include for each or could I return an array and then use
browserString[0] ??
__________________
Thanks,

Keith
The City Forums
  #13  
Old 02-17-2005, 01:00 PM
Brian's Avatar
Brian Brian is offline
Administrator
 
Join Date: Jan 2004
Location: Georgia, USA
Posts: 34,240
Default Re: PHP in module - just cant get it?

If I'm thinking right here, you could probably do that by using a foreach statement and faking a moduleid. Something like this...

PHP Code:
$fakemodid 1000;
foreach (
$browserString AS $bstring)
{
    eval(
'$home[$fakemodid][\'content\'] = "' fetch_template('adv_portal_browser_archive_page') . '";');
    
$fakemodid++;

Then replace $browserString in your template with $bstring.
  #14  
Old 02-17-2005, 01:15 PM
diades diades is offline
Junior Member
 
Join Date: Jun 2004
Posts: 27
Default Re: PHP in module - just cant get it?

or, perhaps, just add the collapsable elements to the mix and import those also?
PHP Code:
$string '<!-- adv_portal_browser_archive Block -->'
.'<table align="center" border="0" cellpadding="$stylevar[cellpadding]"'
.'cellspacing="$stylevar[cellspacing]" class="tborder"width="100%">'
.'<thead>'
.'<tr>'
.'<td class="tcat">'
.'<a style="float:$stylevar[right]" href="#top" onclick="return toggle_collapse('browser')"><img id="collapseimg_feeds" src="$stylevar[imgdir_button]/collapse_tcat$collapseimg_browser.gif" alt="" border="0" /></a>'
.'<span class="smallfont"><strong>$vba_options[portal_blockbullet] Browser archive</strong></span></td>'
.'</tr>'
.'</thead>'
.'<tbody id="collapseobj_browser" style="$collapseobj_browser">'
.'<tr>'
.'<td class="alt2">'
.$browserSting.
.
'</td>'
.'</tr>'
.'<tr>'
.'<td class="alt1">'
.'<p style="font-size:0.8em"><a href="http://www.webxpertz.net/index.php?page=browserarchive">Download browsers</a></p></td>'
.'</td>'
.'</tr>'
.'</tbody>'
.'</table>'
.'<br />'
.'<!-- End adv_portal_browser_archive Block -->'
__________________
Thanks,

Keith
The City Forums
  #15  
Old 02-17-2005, 01:23 PM
Brian's Avatar
Brian Brian is offline
Administrator
 
Join Date: Jan 2004
Location: Georgia, USA
Posts: 34,240
Default Re: PHP in module - just cant get it?

Should work.
  #16  
Old 02-17-2005, 01:28 PM
diades diades is offline
Junior Member
 
Join Date: Jun 2004
Posts: 27
Default Re: PHP in module - just cant get it?

I will give it a whirl
__________________
Thanks,

Keith
The City Forums
  #17  
Old 02-17-2005, 04:23 PM
diades diades is offline
Junior Member
 
Join Date: Jun 2004
Posts: 27
Default Re: PHP in module - just cant get it?

Hi,

I have edited the script but it causes something nasty enough to cause the page to be mia
I am wondering if the variables called in the template are causing a problem when supplied in this manner?
PHP Code:
<?
error_reporting
(E_ALL);
include(
$_SERVER['DOCUMENT_ROOT']."/forums/modules/global_functions.php");
function 
insertLinks($sName){
  
$fname $_SERVER['DOCUMENT_ROOT']."/forums/modules/".$sName.".xml";
  
$flag "r";
  
$fileHandle openfile($fname,$flag);
  
$supplier getStruct($fileHandle);
  
$cnt 0;
  
$templateString = array();
  foreach(
$supplier as $browser)if($browser["tag"] == "BROWSER")$cnt++;
  
$templateString '<!-- Start browser input list --><div class="brDiv"><table summary="">';
  
$type "";
  
$version "";
  
$country "";
  foreach(
$supplier as $supp){
    if(
$supp["type"] == "open" && $supp["tag"] == strtoupper($sName)){
      
$type $supp["attributes"]["TYPE"];
      
$version $supp["attributes"]["VERSION"];
      
$templateString .= '<tr><td class="thead">';
      
$templateString .= ucfirst($sName).' '.$supp["attributes"]["TYPE"].' v'.$supp["attributes"]["VERSION"];
      
$templateString .= '</td></tr>';
    }else if(
$supp["type"] == "open" && $supp["tag"] == "LANGUAGE"){
      
$country $supp["attributes"]["COUNTRY"];
      
$templateString .= '<tr><td class="alt2">';
      
$templateString .= $supp["attributes"]["COUNTRY"];
      
$templateString .= '</td></tr>';
    }else if(
$supp["type"] == "complete" && $supp["tag"] == "BROWSER"){
      
$templateString .= '<tr><td class="alt1">';
      
$templateString .= '<a href="'.$supp["attributes"]["HREF"].'" title="'.$supp["attributes"]["BLAH"].'">Download '.ucfirst($sName).' '.$type.' v'.$version.' ('.$country.') '.$supp["attributes"]["BLAH"].'</a>';
      
$templateString .= '</td></tr>';
    }else{
      continue;
    }
  }
  
$templateString .= '</table></div><!-- End browser input list -->';
  return 
$templateString;
}
function 
fillBlocks(){
  
$supplier = array(=> "microsoft",=> "mozilla",=> "netscape",=> "opera");
  
$blocks = array(insertLinks("microsoft"),insertLinks("mozilla"),insertLinks("netscape"),insertLinks("opera"));
  
$templateString "";
  foreach(
$supplier as $key => $manuf){
    
$templateString .= '<table class="tborder" cellpadding="$stylevar[cellpadding]" width="100%"><thead><tr><td class="tcat"><a href="#top" style="float:$stylevar[right]"';
    
$templateString .= 'onclick="return toggle_collapse(\''.$manuf.'\')"><img';
    
$templateString .= 'id="collapseimg_'.$manuf.'"';
    
$templateString .= 'src="$stylevar[imgdir_button]/collapse_tcat$vbcollapse[collapseimg_'.$manuf.'].gif"';
    
$templateString .= 'alt="" border="0" /></a><strong>'.ucfirst($manuf).' repository</strong>';
    
$templateString .= '</td></tr></thead>';
    
$templateString .= '<tbody id="collapseobj_'.$manuf.'" style="$vbcollapse[collapseobj_'.$manuf.']">';
    
$templateString .= '<tr><td>'.$blocks[$key].'</td></tr></tbody></table><br />';
  }
  return 
$templateString;
}
$templateString fillBlocks();
eval(
'$home[$mods[\'modid\']][\'content\'] = "' fetch_template('adv_portal_browser_archive_page') . '";'); 
?>
__________________
Thanks,

Keith
The City Forums
  #18  
Old 02-17-2005, 06:39 PM
diades diades is offline
Junior Member
 
Join Date: Jun 2004
Posts: 27
Default Re: PHP in module - just cant get it?

Hi,

I got the page back but I am also now back to square 2, it is displaying at the start of the page.
The reason is that a string is not supplied now as the function writes the markup direct to the page. Is there any way to place it where required using this method?
__________________
Thanks,

Keith
The City Forums
  #19  
Old 02-17-2005, 06:55 PM
Brian's Avatar
Brian Brian is offline
Administrator
 
Join Date: Jan 2004
Location: Georgia, USA
Posts: 34,240
Default Re: PHP in module - just cant get it?

Can you post the code you have in the file now?
  #20  
Old 02-17-2005, 07:04 PM
diades diades is offline
Junior Member
 
Join Date: Jun 2004
Posts: 27
Default Re: PHP in module - just cant get it?

Hi Brian

Yes, here:
PHP Code:
<?
error_reporting
(E_ALL);
include(
$_SERVER['DOCUMENT_ROOT'].'/forums/modules/global_functions.php');
function 
insertLinks($sName){
  
$fname $_SERVER['DOCUMENT_ROOT'].'/forums/modules/'.$sName.'.xml';
  
$flag 'r';
  
$fileHandle openfile($fname,$flag);
  
$supplier getStruct($fileHandle);
  
$cnt 0;
  
$templateString = array();
  foreach(
$supplier as $browser)if($browser['tag'] == 'BROWSER')$cnt++;
  
$templateString '<!-- Start browser input list --><div class="brDiv"><table summary="">';
  
$type '';
  
$version '';
  
$country '';
  foreach(
$supplier as $supp){
    if(
$supp['type'] == 'open' && $supp['tag'] == strtoupper($sName)){
      
$type $supp['attributes']['TYPE'];
      
$version $supp['attributes']['VERSION'];
      
$templateString .= '<tr><td class="thead">';
      
$templateString .= ucfirst($sName).' '.$supp['attributes']['TYPE'].' v'.$supp['attributes']['VERSION'];
      
$templateString .= '</td></tr>';
    }else if(
$supp['type'] == 'open' && $supp['tag'] == 'LANGUAGE'){
      
$country $supp['attributes']['COUNTRY'];
      
$templateString .= '<tr><td class="alt2">';
      
$templateString .= $supp['attributes']['COUNTRY'];
      
$templateString .= '</td></tr>';
    }else if(
$supp['type'] == 'complete' && $supp['tag'] == 'BROWSER'){
      
$templateString .= '<tr><td class="alt1">';
      
$templateString .= '<a href="'.$supp['attributes']['HREF'].'" title="'.$supp['attributes']['BLAH'].'">Download '.ucfirst($sName).' '.$type.' v'.$version.' ('.$country.') '.$supp['attributes']['BLAH'].'</a>';
      
$templateString .= '</td></tr>';
    }else{
    }
  }
  
$templateString .= '</table></div><!-- End browser input list -->';
  return 
$templateString;
}
function 
createBlocks(){
  
$supplier = array(=> 'microsoft',=> 'mozilla',=> 'netscape',=> 'opera');
  
$blocks = array(=> insertLinks('microsoft'),=> insertLinks('mozilla'),=> insertLinks('netscape'),=> insertLinks('opera'));
  
$templateString '';
  
$cnt 0;
  foreach(
$supplier as $manuf){
?>
    <table class="tborder" cellpadding="$stylevar[cellpadding]" width="100%">
      <thead>
        <tr>
          <td class="tcat"><a href="#top" style="float:$stylevar[right]" 
            onclick="return toggle_collapse('<? echo($manuf);?>')"><img id="collapseimg_<? echo($manuf);?>" src="$stylevar[imgdir_button]/collapse_tcat$vbcollapse[collapseimg_<? echo($manuf);?>].gif" alt="" border="0" /></a>
            <strong><? echo(ucfirst($manuf));?> repository</strong>
          </td>
        </tr>
      </thead>
      <tbody id="collapseobj_<? echo($manuf);?>" style="$vbcollapse[collapseobj_<? echo($manuf)?>">
        <tr>
          <td><? echo($blocks[$cnt++]);?></td>
        </tr>
      </tbody>
    </table>
  <br />
<?
  

//  return $templateString;

createBlocks();
eval(
'$home[$mods[\'modid\']][\'content\'] = "' fetch_template('adv_portal_browser_archive_page') . '";'); 
?>
I was thinking perhaps of replacing the var in the template with eval('createBlocks()') and eval('$home[$mods[\'modid\']][\'content\'] = "' . fetch_template('adv_portal_browser_archive_page') . '";');

Thanks for you effort in this, it is much appreciated.
__________________
Thanks,

Keith
The City Forums
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Basic Module cLord Add-On Modules & Modifications 55 04-24-2006 08:45 AM
Module: Countdown to certain date 58sniper Add-On Modules & Modifications 36 10-26-2005 01:57 PM
PayPal Module cLord Add-On Modules & Modifications 36 09-21-2005 01:08 AM
Module: Virus Map 58sniper Add-On Modules & Modifications 9 06-05-2005 05:14 AM
Google Module cLord Add-On Modules & Modifications 22 05-03-2005 04:49 PM


All times are GMT -4. The time now is 02:52 AM.

Forums Powered by vBulletin, Copyright ©2000-2009, Jelsoft Enterprises Ltd.
Please note that vBadvanced is in no way affiliated with Jelsoft Enterprises Ltd, nor will Jelsoft be able to provide any support for our products.