Make a Lasting Impression

Get Involved!

Who's Online

14 user(s) are online (2 user(s) are browsing ImpressCMS Blog)

Members: 0
Guests: 14

more...
ImpressCMS proudly uses SourceForge
ImpressCMS on Ohloh.net
ImpressCMS Blog > Updating myblocksadmin to work with 1.2

Updating myblocksadmin to work with 1.2

Some of you have used the myblocksadmin patch from GiJoe in your modules and have learned it won't work in 1.2. Well, I have found the magic that will allow you to continue to use this in your modules, with just a few little changes.

First, a little background and why this has changed.



As ImpressCMS began to move on its own path, several changes have come about, with more to come. An integral part of the ImpressCMS core is the IcmsPersistableObject Framework. This provides a common foundation for all object creation and management, handling the majority of the work for the core and module developers. We have also begun to apply stricter coding standards to everything in the core. All the new features make use of the framework (IPF) and now, blocks admin has been converted to the new framework.


Now, on to the specifics! Myblocksadmin consists of 3 files you copy into your module's admin folder - myblocksadmin.php, mygroupperm.php and mygrouppermform.php - and 1 file you copy into your module's include folder - blocksadmin.inc.php. There are different versions of myblocksadmin and a few different files, but these are the ones I use.


Let's start with the changes to admin/myblocksadmin.php


At the beginning fo the file, there are several other files included. Now, here is where our first realization of the duplication of code in the core. There is class/xoopsblock.php and kernel/block.php that both declare the class XoopsBlock. You can only use one, but with one? If you look at class/xoopsblock.php in 1.2, you will see that it is empty, except for including kernel/block.php. If you ever see a line in code that looks like $handler =& xoops_gethandler('block'), you will be loading a file from the kernel folder with the name passed as the argument to the function. In this case - block.php. So, that will be the proper file to include going forward, but for backwards compatibility, you will need to use class/xoopsblock.php. So, here is the beginning of admin/myblocksadmin.php -


/** include the control panel header */ 
include_once '../../../include/cp_header.php' ; 
/** include the group permissions form */ 
include_once 'mygrouppermform.php'; 
/** include the blocks class */ include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php'; /* for backwards compatibility through ICMS 1.1.3 */ 
//include_once XOOPS_ROOT_PATH.'/kernel/block.php'; /* this is the proper location going forward */


So far, this will work in all our versions. But, in 1.2, the object is separated from its object handler. This is the right way to do things, so we will need a way to determine which version of ImpressCMS is being used. While we would like everyone to be on the latest version of ICMS, that isn't always the case. ImpressCMS has a value store in ICMS_VERSION_BUILD that is updated with each release. Using it, we can determine the version of the core we're dealing with. Farther down in myblocksadmin.php, you'll find a section that determines the blocks that belong to the module. Here's how this needs to change to work in 1.2 and also support previous versions of ICMS -


// get blocks owned by the module

if ( defined('ICMS_VERSION_BUILD') && ICMS_VERSION_BUILD > 27  ) { /* ImpressCMS 1.2+ */

  $block_handler =& xoops_gethandler ('block');

  $block_arr =& $block_handler->getByModule ($xoopsModule->mid());

} else { /* legacy support */

  $block_arr =& XoopsBlock::getByModule( $xoopsModule->mid() ) ; /* from class/xoopsblock.php */

}


You see that in 1.2 and later, we'll use the handler to work with blocks, but in older versions, we use methods defined for the block class. Just after that section, the list_blocks function is declared - you'll need to add $block_handler as a global.


function list_blocks()

{

	global $block_arr, $block_handler ;


Farther down in that function, you'll need to make 1 more adjustment, as we gather up the available block positions -


     /* Block positions - ImpressCMS 1.0+ */

        if ( defined('ICMS_VERSION_BUILD') && ICMS_VERSION_BUILD > 27  ) { /* ImpressCMS 1.2+ */

          $posarr = $block_handler->getBlockPositions (true);

        } else {

          $posarr = XoopsBlock::getBlockPositions ( true );

        }


That's it for the modifications to myblocksadmin.php Next, there are some changes to include/blocksadmin.inc.php to complete this update.


First, the includes do have to be changed


include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php'; /* future: '/kernel/block.php' */

$file = XOOPS_ROOT_PATH.'/modules/system/admin/blocksadmin/blocksadmin.php';

if (file_exists($file)){

   include XOOPS_ROOT_PATH.'/modules/system/admin/blocksadmin/blocksadmin.php';

} else {

  include ICMS_ROOT_PATH . '/modules/system/admin/blocksadmin/class/blocksadmin.php';

}


Again, the proper class file needs to be included and, then, the proper location of the blocksadmin file, based on the version of ImpressCMS. The if statement looks for it in the old location first and then the new location. The rest of the changes are in the function icms_update_block. First, add $xoopsDB as a global, then use the proper handler/method based on the current version of the core


    function icms_update_block($bid, $bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bcachetime, $bmodule, $options=array())

    {

        global $xoopsConfig, $xoopsDB;

        if (empty($bmodule)) {

            xoops_cp_header();

            xoops_error(sprintf(_AM_NOTSELNG, _AM_VISIBLEIN));

            xoops_cp_footer();

            exit();

        }

        if ( defined('ICMS_VERSION_BUILD') && ICMS_VERSION_BUILD > 27  ) { /* ImpressCMS 1.2+ */

          $myblock_handler = new IcmsBlockHandler($xoopsDB); /* Will only work in ImpressCMS 1.2+ */

          $myblock = $myblock_handler->get($bid);

        } else { /* legacy support */

          $myblock = new XoopsBlock($bid);

        }


That should do it for you! With these changes, myblocksadmin will work with ImpressCMS 1.2

All posts by skenow
Subscribe to latest posts
The comments are owned by the poster. We aren't responsible for their content.
Poster Thread
thomas
Posted: 2009/11/7 15:16  Updated: 2009/11/7 15:16
Home away from home
Joined: 2008/1/2
From:
Posts: 1239
 Re: Updating myblocksadmin to work with 1.2
Thanks for the heads up Steve! You said "There are different versions of myblocksadmin and a few different files, but these are the ones I use."

Do you have a link to your specific version of myblocksadmin or should we just use 0.43 from

http://xoops.peak.ne.jp/md/mydownlo ... php?lid=12
skenow
Posted: 2009/11/7 18:11  Updated: 2009/11/7 18:11
Home away from home
Joined: 2007/12/4
From:
Posts: 2886
 Re: Updating myblocksadmin to work with 1.2
If you use the download directly from GiJoe, you will have other changes to make. I suggest either using the files from the SimplyWiki or imLinks module. I believe McDonald has used the 0.43 version and made that compatible for ImpressCMS.
FaYsSaL
Posted: 2009/11/13 10:56  Updated: 2009/11/13 10:56
Home away from home
Joined: 2008/1/9
From:
Posts: 235
 Re: Updating myblocksadmin to work with 1.2
what about 1.1! it doesnt work either! those changes will work too?
skenow
Posted: 2009/11/15 0:16  Updated: 2009/11/15 0:16
Home away from home
Joined: 2007/12/4
From:
Posts: 2886
 Re: Updating myblocksadmin to work with 1.2
Both McDonald and I have released modules where myblocksadmin works in 1.1 - there is a forum thread were this is outlined.
McDonald
Posted: 2009/11/15 9:13  Updated: 2009/11/15 9:13
Home away from home
Joined: 2007/12/4
From: Abyss
Posts: 1638
 Re: Updating myblocksadmin to work with 1.2
The block function has been removed from imLinks, Impression and MyTube a few month ago.