Deano's Add PHP Block Hack

This is a post that Deano provided us in Beta and RC's

==================================================================================================

This is a rewrite of the D6 mod to enable PHP blocks to be dragged into a page from the page builders.


First we start by adding a entry to the database. Open phpmyadmin and execute the following SQL query to add the Block to the page builder.

INSERT INTO `sys_page_compose` (`Page`, `PageWidth`, `Desc`, `Caption`, `Column`, `Order`, `Func`, `Content`, `DesignBox`, `ColWidth`, `Visible`, `MinWidth`) VALUES ('', '998px', 'Simple PHP Block', '_PHP Block', 0, 0, 'Sample', 'PHP', 1, 0, 'non,memb', 0)


Now we need to add 3 new language keys.

Log into your sites admin panal, go to Settings -> Language Settings.

Now add these 3 new keys.

Click the Add Key button.

Key Name:  _adm_pbuilder_PHP_Block

String Text: PHP Block

Click save and repeat for the next 2 keys.

Key Name:  _adm_pbuilder_PHP_content

String Text: PHP-Content

Key Name:  _PHP Block
String Text: PHP Block



Now we need to make all the changes to the code to enable the block to be edited and deleted.

Open the file inc\classes\BxDolPageViewAdmin.php Make a backup of that file before you change it. So you can revert back to the old one if something goes wrong.


NOTE: Line numbers below may not exactly match what you have. Use the code as a visual aid to make sure you have the right spot.


Around line 246 will be the following code.

if( $sFunc == 'RSS' )
$sContentUpd = "`Content` = '" . process_db_input($aData['Url'], BX_TAGS_STRIP) . '#' . (int)$aData['Num'] . "',";
elseif( $sFunc == 'Echo')
$sContentUpd = "`Content` = '" . process_db_input($aData['Content'], BX_TAGS_NO_ACTION) . "',";
elseif( $sFunc == 'XML' ) {
$iApplicationID = (int)$aData['application_id'];
$sContentUpd = "`Content` = '" . $iApplicationID . "',";
} else
$sC alt= '';


Make it look like this by adding the lines marked block.

if( $sFunc == 'RSS' )
$sContentUpd = "`Content` = '" . process_db_input($aData['Url'], BX_TAGS_STRIP) . '#' . (int)$aData['Num'] . "',";
elseif( $sFunc == 'Echo')
$sContentUpd = "`Content` = '" . process_db_input($aData['Content'], BX_TAGS_NO_ACTION) . "',";
elseif( $sFunc == 'PHP')
$sContentUpd = "`Content` = '" . process_db_input($aData['Content'], BX_TAGS_NO_ACTION) . "',";

elseif( $sFunc == 'XML' ) {
$iApplicati alt= (int)$aData['application_id'];
$sC alt= "`Content` = '" . $iApplicationID . "',";
} else
$sC alt= '';

Continue down to to about line 260. Look for this.

function showPropForm($iBlockID) {
$sNoPropertiesC = _t('_adm_pbuilder_This_block_has_no_properties');
$sProfileFieldsC = _t('_adm_pbuilder_Profile_Fields');
$sHtmlBlockC = _t('_adm_pbuilder_HTML_Block');
$sXmlBlockC = _t('_adm_pbuilder_XML_Block');
$sRssBlockC = _t('_adm_pbuilder_RSS_Feed');
$sSpecialBlockC = _t('_adm_pbuilder_Special_Block');
$sHtmlContentC = _t('_adm_pbuilder_HTML_content');
$sXmlPathC = _t('_adm_pbuilder_XML_path');


Make it look like this. Adding the marked lines.

function showPropForm($iBlockID) {
$sNoPropertiesC = _t('_adm_pbuilder_This_block_has_no_properties');
$sProfileFieldsC = _t('_adm_pbuilder_Profile_Fields');
$sHtmlBlockC = _t('_adm_pbuilder_HTML_Block');
$sPHPBlockC = _t('_adm_pbuilder_PHP_Block');
$sXmlBlockC = _t('_adm_pbuilder_XML_Block');
$sRssBlockC = _t('_adm_pbuilder_RSS_Feed');
$sSpecialBlockC = _t('_adm_pbuilder_Special_Block');
$sHtmlContentC = _t('_adm_pbuilder_HTML_content');
$sPHPC alt= _t('_adm_pbuilder_PHP_content');
$sXmlPathC = _t('_adm_pbuilder_XML_path');



Continue to about line 396

Find this.


switch( $aItem['Func'] ) {
case 'PFBlock': $sBlockType = $sProfileFieldsC; break;
case 'Echo':    $sBlockType =$sHtmlBlockC; break;
case 'XML':     $sBlockType =$sXmlBlockC; break;
case 'RSS':     $sBlockType =$sRssBlockC; break;
default:        $sBlockType =$sSpecialBlockC; break;
}



Make it look like this.

switch( $aItem['Func'] ) {
case 'PFBlock': $sBlockType = $sProfileFieldsC; break;
case 'Echo':    $sBlockType =$sHtmlBlockC; break;
case 'PHP':    $sBlockType =$sPHPBlockC; break;
case 'XML':     $sBlockType =$sXmlBlockC; break;
case 'RSS':     $sBlockType =$sRssBlockC; break;
default:        $sBlockType =$sSpecialBlockC; break;
}


About a half dozen lines below that look for this.

$sDeleteButton = ($aItem['Func'] == 'RSS' or $aItem['Func'] == 'Echo' or $aItem['Func'] == 'XML') ? '<input type="reset" value="Delete" name="Delete" />' : '';


Make it look like this.

$sDeleteButton = ($aItem['Func'] == 'RSS' or $aItem['Func'] == 'Echo' or $aItem['Func'] == 'XML' or $aItem['Func'] == 'PHP') ? '<input type="reset" value="Delete" name="Delete" />' : '';

Now move down to around line 460. Look for this.


if( $aItem['Func'] == 'Echo') {
$aForm['inputs']['Content'] = array(
'type' => 'textarea',
'html' => true,
'name' => 'Content',
'value' => $sBlockContent,
'caption' => $sHtmlContentC,
'required' => true,
);
} elseif( $aItem['Func'] == 'XML' ) {
$aExistedApplications = BxDolService::call('open_social', 'get_admin_applications', array());

$aForm['inputs']['Applications'] = array(
'type' => 'select',
'name' => 'application_id',
'caption' => _t('_osi_Existed_applications'),
'values' => $aExistedApplications
);



Make it look like this.

if( $aItem['Func'] == 'Echo') {
$aForm['inputs']['Content'] = array(
'type' => 'textarea',
'html' => true,
'name' => 'Content',
'value' => $sBlockContent,
'caption' => $sHtmlContentC,
'required' => true,
);
} elseif( $aItem['Func'] == 'PHP' ) {
$aForm['inputs']['Content'] = array(
'type' => 'textarea',
'html' => true,
'name' => 'Content',
'value' => $sBlockContent,
'caption' => $sPHPContentC,
'required' => true,
);

} elseif( $aItem['Func'] == 'XML' ) {
$aExistedApplications = BxDolService::call('open_social', 'get_admin_applications', array());

$aForm['inputs']['Applications'] = array(
'type' => 'select',
'name' => 'application_id',
'caption' => _t('_osi_Existed_applications'),
'values' => $aExistedApplications
);


Now Move to line 520 or so. Look for this.


if ($aItem['Func'] == 'RSS' or $aItem['Func'] == 'Echo' or $aItem['Func'] == 'XML') {
$aForm['inputs']['Delete'] = array(
'type' => 'reset',
'name' => 'Delete',
'caption' => 'Delete',
'value' => 'Delete',
);
}


Make it look like this.

if ($aItem['Func'] == 'RSS' or $aItem['Func'] == 'Echo' or $aItem['Func'] == 'XML' or $aItem['Func'] == 'PHP') {
$aForm['inputs']['Delete'] = array(
'type' => 'reset',
'name' => 'Delete',
'caption' => 'Delete',
'value' => 'Delete',
);
}



Thats it. It's not as easy as the D6 mod. There are more code changes. Make a backup of that file before you change it. So you can revert back to the old one if something goes wrong.

You should now see a PHP Block in the page builders that you can drag onto any page just like the HTML block.

When a GIG is not enough --> Terabyte Dolphin Technical Support - Server Management and Support
Quote · 18 Mar 2010

Thanks so much for this.
Way better than the way i have been doing it...if only you knew lol
It works great.

Be a dolphin, be creative in you own way and you will attract a audience
Quote · 20 Mar 2010

it's a small error on one line of code in this post

You will find it here:
Continue down to to about line 260. Look for this.
Make it look like this. Adding the marked lines.
$sPHPC alt= _t('_adm_pbuilder_PHP_content');

it should have been
$sPHPContentC = _t('_adm_pbuilder_PHP_content');


can be ok and have it correct if anyone should have problems with it

Quote · 5 Apr 2010

Actually that should be.

$sPHPContentC = _t('_adm_pbuilder_PHP_content');


Its for the caption and is referenced in the second to the last part of the code.

The original code is here. http://www.boonex.com/unity/forums/#topic/Add-PHP-blocks-to-Pagebuilder-for-D7.htm

Looks fine there, so the forums must have done some stripping when it was pasted here.

https://www.deanbassett.com
Quote · 5 Apr 2010

RE:

Actually that should be.

$sPHPContentC = _t('_adm_pbuilder_PHP_content');


Its for the caption and is referenced in the second to the last part of the code.

The original code is here. http://www.boonex.com/unity/forums/#topic/Add-PHP-blocks-to-Pagebuilder-for-D7.htm

Looks fine there, so the forums must have done some stripping when it was pasted here.

I tried to post some html code yesterday, and absolutely could not get it to post without it being mutilated.... even using the code wrapper.  This can all be traced back to when AlexT fixed an issue that allowed divs to placed anywhere on the screen and even allowed z-index.  You could basically create a div with a black background and cover the entire screen with it, if you wanted to.

That problem has gone away, but unfortunately, it's impossible to post code sometimes.  I've posted a bunch of stuff recently, and I can't help but wonder if it's any good.

My opinions expressed on this site, in no way represent those of Boonex or Boonex employees.
Quote · 7 Apr 2010

Trying this in 7.3? I got the php block showing in the pages builder but I'm not sure what file the rest of the code goes in since it's not named the same. Can someone point me in the right direction? Thanks for any help in advance

Quote · 29 Apr 2017

Dolphin 7.3.3 already has PHP block functionality, you can enable it by opening the following URL:

http://example.com/administration/pageBuilder.php?action_sys=addCodeBlock

Then you can use new "Code block"

Rules → http://www.boonex.com/terms
Quote · 1 May 2017

Thank you sir,that just made my day.

Quote · 1 May 2017
 
 
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.