Welcome to Geeklog, Anonymous Thursday, April 18 2024 @ 08:41 pm EDT

Geeklog Forums

Staticpage block management


Status: offline

suprsidr

Forum User
Full Member
Registered: 12/29/04
Posts: 555
Location:Champaign, Illinois
While we wait for SOC results for better block management.
I though I'd share an easy way to display blocks wherever you want.
Utilizing the autotags plugin, add these two functions to path_to_geeklog/plugins/autotags/functions.inc
Text Formatted Code

/**
* Display a Geeklog block
*/
    function phpautotags_showBlock($p1, $p2, $fulltag) {
        global $_TABLES;
        $display = '';
        $result = DB_query("SELECT * FROM {$_TABLES['blocks']} WHERE (name = '$p1')");
        $A = DB_fetchArray($result);
        if (! empty($A)) {
            if ($p2 == $p1) {
                $p2 = '';
            }
            $display = AT_formatBlock($A, $p2);
            $display .= "\n";
        } else {
            if (SEC_inGroup('Root')) {
                $display .= COM_startBlock($p1);
                $display .= "<br><strong>Sorry, we cannot find the block you were requesting.</strong><br>";
                $display .= COM_endBlock();
            }
        }
        return $display;
    }

/**
* Formats a Geeklog block
* @param        array     $A          Block Record
* @param        string    $useTemplate    Force block template ie. 'left', 'right', 'list'...
* @param        bool      $noboxes    Set to true if userpref is no blocks
* @return       string    HTML Formated block
*/
        function AT_formatBlock( $A, $useTemplate, $noboxes = false ) {
        global $_CONF, $_TABLES, $_USER, $LANG21;
        $retval = '';
        //$lang = COM_getLanguageId();
        $lang = 'en';
        if (!empty($lang)) {
            $blocksql['mssql']  = "SELECT bid, is_enabled, name, type, title, tid, blockorder, cast(content as text) as content, ";
            $blocksql['mssql'] .= "rdfurl, rdfupdated, rdflimit, onleft, phpblockfn, help, owner_id, ";
            $blocksql['mssql'] .= "group_id, perm_owner, perm_group, perm_members, perm_anon, allow_autotags,UNIX_TIMESTAMP(rdfupdated) AS date ";
            $blocksql['mysql'] = "SELECT *,UNIX_TIMESTAMP(rdfupdated) AS date ";
            $commonsql = "FROM {$_TABLES['blocks']} WHERE name = '"
                       . $A['name'] . '_' . $lang . "'";
            $blocksql['mysql'] .= $commonsql;
            $blocksql['mssql'] .= $commonsql;
            $result = DB_query( $blocksql );
            if (DB_numRows($result) == 1) {
                // overwrite with data for language-specific block
                $A = DB_fetchArray($result);
            }
        }
        if(in_array($useTemplate, array('left', 'right', 'message', 'related', 'list', 'config'))){
            $position = '-' . $useTemplate;
        }else if( array_key_exists( 'onleft', $A ) ) {
            if( $A['onleft'] == 1 ) {
                $position = '-left';
            } else {
                $position = '-right';
            }
        } else {
            $position = '';
        }
        if( $A['type'] == 'portal' ) {
            if( COM_rdfCheck( $A['bid'], $A['rdfurl'], $A['date'], $A['rdflimit'] )) {
                $A['content'] = DB_getItem( $_TABLES['blocks'], 'content',
                                            "bid = '{$A['bid']}'");
            }
        }
        if( $A['type'] == 'gldefault' ) {
            $retval .= COM_showBlock( $A['name'], $A['help'], $A['title'], $position );
        }
        if( $A['type'] == 'phpblock' && !$noboxes ) {
            if( !( $A['name'] == 'whosonline_block' AND DB_getItem( $_TABLES['blocks'], "name='whosonline_block'" ) == 0 )) {
                $function = $A['phpblockfn'];
                $matches = array();
                if (preg_match('/^(phpblock_\w*)\\((.*)\\)$/', $function, $matches) == 1) {
                    $function = $matches[1];
                    $args = $matches[2];
                }
                $blkheader = COM_startBlock( $A['title'], $A['help'],
                        'blockheader'.$position.'.thtml');
                $blkfooter = COM_endBlock( 'blockfooter'.$position.'.thtml');
       
                if( function_exists( $function )) {
                   if (isset($args)) {
                        $fretval = $function($A, $args);
                   } else {
                        $fretval = $function();
                   }
                   if( !empty( $fretval )) {
                        $retval .= $blkheader;
                        $retval .= $fretval;
                        $retval .= $blkfooter;
                   }
                } else {
                    // show error message
                    $retval .= $blkheader;
                    $retval .= sprintf( $LANG21[31], $function );
                    $retval .= $blkfooter;
                }
            }
        }
        if( !empty( $A['content'] ) && ( trim( $A['content'] ) != '' ) && !$noboxes ) {
            $blockcontent = stripslashes( $A['content'] );
       
            // Hack: If the block content starts with a '<' assume it
            // contains HTML and do not call nl2br() which would only add
            // unwanted <br> tags.
       
            if( substr( $blockcontent, 0, 1 ) != '<' ) {
                $blockcontent = nl2br( $blockcontent );
            }
       
            // autotags are only(!) allowed in normal blocks
            if(( $A['allow_autotags'] == 1 ) && ( $A['type'] == 'normal' )) {
                $blockcontent = PLG_replaceTags( $blockcontent );
            }
            $blockcontent = str_replace( array( '<?', '?>' ), '', $blockcontent );
       
            $retval .= COM_startBlock( $A['title'], $A['help'],
                           'blockheader'.$position.'.thtml')
                    . $blockcontent . LB
                    . COM_endBlock( 'blockfooter'.$position.'.thtml');
        }
        return $retval;
    }
 


Then create an autotag in the autotags admin: showBlock with the function phpautotags_showBlock.
Now you can call any block anywhere geeklog allows autotags. Especially handy in staticpages.
Usage:
[showBlock:block_name] - to show a block using its native template left or right depending on its normal position in the block manager.
[showBlock:block_name list] - to render the block using blockheader-list, blockfooter-list.
Available templates: 'left', 'right', 'message', 'related', 'list', 'config'

Easy peasy.

-s
FlashYourWeb and Your Gallery with the E2 XML Media Player for Gallery2 - http://www.flashyourweb.com
 Quote

Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
Yes it's a fantastic feature.

Just a comment for whose are not familiar with autotag plugin, you need to add autotags.PHP rights to Autotags Admin group for exemple to allow php functions in autotags.

And I needed to create an autotag in the autotags admin call showblock to do it work. ShowBlock was not working.

:shakehands: Thanks a lot for this very nice feature.


::Ben
I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
Quote by: suprsidr

While we wait for SOC results for better block management.


Hmm? There isn't/wasn't a GSoC project for better block management. The Admin's Blocks section in 1.6 will be exactly the same as in 1.5.2.

bye, Dirk
 Quote

Status: offline

suprsidr

Forum User
Full Member
Registered: 12/29/04
Posts: 555
Location:Champaign, Illinois
Hmm? There isn't/wasn't a GSoC project for better block management.

Sorry, I thought I read it somewhere.

So.... While we wait for better block management.

And maybe it'll get added to the queue somewhere. Wink

-s
FlashYourWeb and Your Gallery with the E2 XML Media Player for Gallery2 - http://www.flashyourweb.com
 Quote

Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
May it could be added to autotags next version Smile

::Ben
I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

All times are EDT. The time is now 08:41 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content