How to enable PHP block in the Page Builder

newdreamers posted 3rd of December 2008 in Community Voice. 31 comments.

This is based on an earlier post (and great finding) from jtadeo

http://www.boonex.com/unity/blog/entry/How_to_Add_PHP_in_a_BLOCK

This small 4-steps guide allows you to enable PHP blocks in the Page Builders interface, allowing you to, well, insert PHP inside your pages, as simple as that!


Note: I strongly recommend you backup your BxDolPageViewAdmin.php just in case...

--------------------
STEP 1
--------------------

Run the following Insert query in the pageCompose table:

INSERT INTO `PageCompose` ( `ID` , `Page` , `PageWidth` , `Desc` , `Caption` , `Column` , `Order` , `Func` , `Content` , `DesignBox` , `ColWidth` , `Visible` , `MinWidth` )
VALUES (NULL , '', '960px', 'PHP Block', '_PHP Block', '0', '0', 'Sample', 'PHP', '1', '0', 'non,memb', '0');

The key field is "Func", being set to "Sample". Any record set to "Sample" in this table will make the relevant block appear among the Samples(!) in the "page builders" section. Try and look at any page from the Page Builders screen, you'll now see the PHP block displayed as Sample.

--------------------
STEP 2
--------------------


Edit the following file:
./inc/classes/BxDolPageViewAdmin.php

Update the saveItem function (starting line 174) by modifying line 187:

FROM: elseif( $sFunc == 'Echo' )
TO: elseif( $sFunc == 'Echo' or $sFunc == 'PHP' )

This will enable the PHP code to be saved from the admin interface.

--------------------
STEP 3
--------------------


Modify line 553:

FROM: if( $aItem['Func'] == 'RSS' or $aItem['Func'] == 'Echo' ) {
TO: if( $aItem['Func'] == 'RSS' or $aItem['Func'] == 'Echo' or $aItem['Func'] == 'PHP' ) {

This will enable the "Delete" button in the PHP blocks popup form

--------------------
STEP 4
--------------------


Search for :

if( $aItem['Func'] == 'Echo' )

This IF condition defines what fields to display in the block popup form, based on the block type/func. You just need to insert the following on line 533
(just before the end of the IF condition for the HTML blocks):

... etc etc...
<?
// THE INSERT STARTS HERE

} elseif( $aItem['Func'] == 'PHP' ) {
?>
<tr>
<td class="form_label">PHP-code:</td>
<td>&nbsp;</td>
</tr>
<tr>
<td class="form_colspan" colspan="2">
<textarea style="width: 450px; height: 350px;" name="Content"><?= htmlspecialchars_adv( $aItem['Content'] ) ?></textarea>
</td>
</tr>
<?

// THE INSERT FINISHES HERE
} elseif( $aItem['Func'] == 'RSS' ) {
... etc etc...

--------------------
ET VOILA!
--------------------


Now you can manage PHP blocks straight from the admin section without having to fiddle with MySQL or other geeky stuff!

Personally I can think of loads of new blocks I'm gonna create... right now actually!

Dunno what's coming up with 6.2, hope fully they'll incorporate this by default :-)

HAVE FUN!

--------------------
DISCLAIMER
--------------------

- Don't make the modif if you're not comfortable with PHP
- This "hack" might get overridden/overwritten by future releases

 
Comments
·Oldest
·Top
Please login to post a comment.
jtadeo
ding ding ding that is a mighy-cool-thing.

Kudos newdreamers for sharing and posting this.

If you really want a challenge, do a Shindig install and run OpenSocial apps from it ;D

...sip...
okweb
Thanks for sharing...
works great.
frankij
Thank you , thank you, made my day lol!
miskam
Hello,
can I insert a language string in to this php block?

example:
I already made a new langstring in database, dont know how to insert it?
A user from UK see in this block a link with name "ocean" and the other user from Germany see "oZean".
than you
newdreamers
Hi miskam, here's the code your need to insert language strings below. Save it as a separate file then insert it within your php block as an "include" for example:

// START
require_once( 'inc/header.inc.php' );
require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' );
echo _t( "_MY_LANGUIAGE_KEY" );
// END
miskam
Thank you very much :-D
@newdreamers
works fine!
meovino
@newdreamers - big ups on this! Thanks!
alienbee
did all the above..usung 6.1.4 and for some reason the blocks mentioned that should be inside of PageBuilder ..is not showing ..

is there a fix? did boon decide to block this from happening?
newdreamers
Hi there,

Sorry for the late reply, been away for a while. Just tried on a fresh install of Dolphin 6.1.4, applied the 4 steps above and it worked fine for me.

Let me know if I can be of any assistance.
francisca_carv
You are the best, thank you SOOO much! Ah, and thanks for sharing, of course! Works great!
wonell
works fantastic
thanks!!!
glany222
Hi... this technique is even beeter than previous one..
thanx newdreamers...
zak2008
i am on 6.1.2 but getting :


Parse error: syntax error, unexpected '<' in /home/ethiomys/public_html/inc/classes/BxDolPageView.php(308) : eval()'d code on line 1
zak2008
i am on 6.1.2 but getting error for just a simple php test code <?php echo “Hello world”; ?>

Parse error: syntax error, unexpected '<' in /home/ethiomys/public_html/inc/classes/BxDolPageView.php(308) : eval()'d code on line 1
newdreamers
That's because you mustn't include the PHP start/end delimiters.

This will work:

echo "Hello world";

This will not:

<?php echo "Hello world"; ?>
zak2008
Thanks newdreamer...it worked
do i still need to do this if im using 6.1.4
westmerch
aaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhh james t

i did it yesssssssssssssss!

i tried the first tuto but couldn't achieve step 2 from the first tuto;

so i went on with this second tuto; so now i have a block in my page builder, i need to add a php code; im still learning about this...

thank you so much; lol at first when reading this kind of tuts i thought i was about to "piewk" lol;

next is "php code";

so lets see...
westmerch
one more question, if lets say what about that php block; can i have it for other pages? like profile etc?

thank you!
westmerch
Bobbo2111!

yeah im using 6.1.4, and it works i just have the php box enbale in my admin page builder ;

havent tried yet to add a php code!

in my case with this tuto, i tried to add a second block.

the only thing i did after accompliching the two tuto, i did step 1 with php my admin only, without redoing other steps; and i have a second block added to my admin page!
Westmetch,
thanks for letting me know...
man i suck, i cant get pass step 1, can anyone offer any further explanation? im on the insert tab in phpmyAdmin under my DB and Table: PageCompose and then there is a long table with Field Type Function Null Value headers. , im brand new so im not sure where to insert step 1
man i suck, i cant get pass step 1, can anyone offer any further explanation? im on the insert tab in phpmyAdmin under my DB and Table: PageCompose and then there is a long table with Field Type Function Null Value headers. , im brand new so im not sure where to insert step 1
newdreamers
Hello,

You need to run the SQL query specified in Step 1 from the "SQL" tab in phpMyAdmin, not the "Insert" one.

Be careful though, because if you're stuck at this stage then things might get quite ugly further down the process... good luck!
ThinkArchimedes
This...is...an...AMAZING tutorial (!) Great job!!! I think all of you guys are brilliant beyond comprehension for being able to think outside of the box on this kind of stuff. This is why I love programming and, in this case, dolphin! Keep up the good work friends.
jymick75
Hi ,

I did all the above..using 6.1.4.
I have the new php block in page page builder but how can i add php code into the block ??

Thanks
pinayabroad
any update for Dolphin 7?
billmarks
I followed the directions on my 6.1.4 install, but when I click on Pagebuilder/Homepage/PHP Block, (there are two PHP Block fields) I get "This block has no properties" coming up in red letters.
billmarks
Please disregard my last question. However, I did manage to get the Quotes field showing on the home page. But with the error:

Daily Quotes

Parse error: syntax error, unexpected T_STRING in /home/billmark/public_html/prayerchainbook.com/inc/classes/BxDolPageView.php(561) : eval()'d code on line 3
I think I must be the first to have the following problem. I have a the PHP block in my page builder, I can put it on a page and put code in it but it doesn't save it. If I put code in the block and click Save and immediately re-open the block for editing it's not there. Any idea what's wrong? Info: I'm using Dolphin 7.0.7. There's no table 'PageCompose' so I tried inserting that SQL into sys_page_compose
Solution for D7: http://www.boonex.com/forums/topic/Add-PHP-blocks-to-Pagebuilder-for-D7.htm
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.
PET:0.076527118682861