Global blocks - or how to get the same content on every page

kweitzel

@weiry: above code is working as designed, it is meant to do this! If no content assigned to this div call the hidden div.

You can just try to hard-code an include if you don't want this feature ... set the "hidden" page to template blank and then:
<?php include WB_URL.'/pages/name_of_hidden_page.php'?>

If include does not work (disabled), use the cURL (if installed on server) like described further above instead.

cheers

Klaus

mr-fan

link? more details? code?.......my telephaty-power is burst up.... :-D

weiry

I have found that this code works fine for calling in a block on every page that I have created on a hidden page.

However, if I have content already on another the page in that div area i.e. on the Contact Us page, the block I want on every page disappears and the text on the Contact Us page is there okay in that div area.

I am sure that it is a quick php thing, but can't see how to fix.

Any thoughts?

mr-fan

               <!-- global block starts here -->
               <div id="topleft"> <!-- change to your favorite css #id -->
               <?php
                ob_start
();
                
page_content(2); //INFOBOX PAGE CONTENT 2 in my case
                
$topl=ob_get_contents();
                
ob_end_clean();
                if (
$topl=="") {
                
$section_id 65// ID from the section that stays always if pagecontent 2 has no content
                
$query_sec $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE section_id = '$section_id' ");
                if(
$query_sec->numRows() > 0) {
                
$section $query_sec->fetchRow();
                
$section_id $section['section_id'];
                
$module $section['module'];
                require(
WB_PATH.'/modules/'.$module.'/view.php');
                }
                } else {
                echo 
'<div align="center">';
                echo 
$topl;
                echo 
'</div>';
                }
                
?>

               </div>
               <!-- end of the global block -->



Hi guys,

i use this piece of code for global blocks!

I've got it from vyni!

The Trick is that you can have default view for a global block (with the section_id you choose) and if you want another content on one or more sites only set up a section and set it up to the content of the global block - and on this page the content is like you want it!

regards martin

lousou76

Well it's really very simple.

If you want to display content from another page (regardless of what type of module it is) you only need to know the page_id ans the section_id of the content you need to show.

Lets say you are on /admin/pages/modify.php?page_id=16

and you want to show content from page_id=14 section_id=2.

You just add a code section on the current page and put the code

global $wb;
$wb->page_id = 14;
page_content(2);
$wb->page_id = 16;  //I am not sure this is really necessary but just in case.


This will display the exact type of module and content on the current section with page_id=14 and section_id=2.

Regards,
LS

lousou76

Excellent work Klaus!

It's a nice way of using global block sections that could be edited once instead of copying content form one page to another.

I guess the best way to do this would be a new nice page_content() function that could take 2 arguments instead of one. The page_id and the section_id.

That way you could just use for example <? page_content(1,3);  ?> to display content from another page on your site. You could also add this code on a Code section anywhere on your current page and show the same content with some other page.

I would advise against using curl to do this. If it hangs or it delays the page never loads or loads empty.

So lets see how to slightly change the page_content function, or add a new one that does what we want so we can have global blocks anywhere.

I ll have more on that later..

Regards,
LS
 

kweitzel

That works as well if fopen is allowed on the host. Sometimes you find this one to be disabled as well.

Info: http://phpsec.org/projects/phpsecinfo/tests/allow_url_fopen.html

cheers

Klaus

masju

Hi!

If your server does not allow the include-command in your template's index.php
<?php include (WB_URL."/pages/blocks/block1.php"); ?>
due to security-settings, try this instead:

<?php
$handle = fopen (WB_URL."/pages/blocks/block1.php", "r");
while (!feof($handle))
   {
    $buffer = fgets($handle, 4096);
    print_r ($buffer);
   }
?>

Works well :-)

greets masju

kweitzel

Since cURL is actually an Wrapper for URLs you obviously will need to feed it with an URL and not a path. It will also only work, if it is activated on the Server.

cheers

Klaus

sare

Same here.

Nothing worked with the normal include, at best it showed the wrong template with the include and broke all page_content-functions that were after that in the template code.

This cURL code worked like magic after finding the right URL for it to use.

If you can't get the cURL code to work, try with and without the www-part in the WB_URL. I didn't use it at first, and got 404's (not found).

Hope this saves somebody else the 3 hours I spent scrathing my head...

weiry

Quote from: kweitzel on February 21, 2007, 06:56:46 PM
if it does not work, try curl instead:


$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, WB_URL.'/pages/pagename.php');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
// display file
echo $file_contents;


cheers

Klaus
Thank you for this option Klaus. No matter what I did, I couldn't get it to work with the other options, even after reading numerous related threads. But this curl worked straight away.

Cheers.

aggiedad

Can this be used with more than two blocks?

I was trying this technique with more than two blocks and it caused my site to hang-up. First I tried it by just adding an additional block. Then when that didn't work, tried a second hidden page -- things still didn't work.

Any thoughts?

Thanks!

Don Simmons
Texas

kweitzel

Hmm... haven't tried it yet multiple times (no need to). For which types of info do you still need it?

cheers

Klaus

eddyfever

And when i use more blocks in my template do i have to change then something in the script?
this because now it doesnt load theright site of my template when i use it more times in my template.

eddyfever

can you maybe explain how i can use this?

Nevermind: it works with your solution!!!!

Vielen herzlichen Dank. Abende lang hab ich gesucht und endlich hat es geklappt!!!!!!!

kweitzel

if it does not work, try curl instead:


$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, WB_URL.'/pages/pagename.php');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
// display file
echo $file_contents;


cheers

Klaus

eddyfever

So strange this never with me, it looks like it is not alloud to insert a .php or something.
does anybody know what it can be.

preview: under title (poll)
http://www.rawrock.nl/site

DGEC

Quote from: pcwacht on January 08, 2006, 03:55:48 PM

                    ....
5 - change your current template's index.php by adding the two pages you just made

<?php include (WB_URL."/pages/blocks/block1.php"); ?> and
<?php include (WB_URL."/pages/blocks/block2.php"); ?>
at the position you want it.


One suggestion about this code: rather than using the literal  /pages/, everyone should probably get in the habit of using the WB_PATH variable, especially for templates, snippets, modules, etc. That way if someone has a different path or no path, your brilliant code will still work  :-D

So instead of:

     <?php include (WB_URL."/pages/blocks/block1.php"); ?>

you would instead code  (I think - this isn't tested yet)

     <?php include (WB_URL WB_PATH "/blocks/block1.php"); ?>


pcwacht

QuoteThat's not an absolute path. An absolute path would be http://www.etcetc.

Path = filebased
URL is webserver based

http://www.somedomain.com/somepath/somefile.php = absolute url
/home/sites/site300/web/somepath/somefile.php = absolute path (on linux)
../somepath/somefile.php = relative (path or url)


John

rabsaul

Quote from: Wirus on May 09, 2006, 12:47:51 PM
Is possible make second block without absolute path ?

Defined NOT as:
<?php include (WB_URL."/pages/blocks/block2.php"); ?>

but something like this:
<?php include ("../pages/blocks/block2.php"); ?>

Absolute url fopen is often forbiden by server...

Thanks
That's not an absolute path. An absolute path would be http://www.etcetc.

pcwacht

Have you seen my other solution?
This don't need path's etc...

http://forum.websitebaker.org/index.php/topic,3217.0.html

Another option would be to abslote the link, something like /home/somepath/http/pages/page12.php


John

Wirus

Including complete URL is forbiden on my server. (security hole) I can include only local path. This is possible but system dont change template of included page (is set to blank) and include it with template of actual page (round).

pcwacht

Don't think it can be done

I tried to but got warnings about missing config(.)php in the called file


But why do you need it?

John

Wirus

Is possible make second block without absolute path ?

Defined NOT as:
<?php include (WB_URL."/pages/blocks/block2.php"); ?>

but something like this:
<?php include ("../pages/blocks/block2.php"); ?>

Absolute url fopen is often forbiden by server...

Thanks

kickarse

Good idea! I think I'm going to use this on a site I'm developing now.