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.