The secure CMS.

Welcome to Geeklog
Saturday, February 11 2012 @ 09:36 AM EST

PHP Block How-To

AnnouncementsOk, so 1.3 has been on the market now for a few weeks and many of you have started tweaking your site by modifying the templates and what not. But now what? Well, I thought I'd write a quick how-to with a real life example on using a Geeklog PHP block. Overview

PHP Blocks give you the power of letting a Geeklog block execute some code to generate dynamic output. To make it more secure, you are not allowed to add PHP code directly to the content of your block but, instead, must add a function to your /path/to/geeklog/lib-custom.php and then assign your PHP block to execute that function. To keep someone from executing arbitrary PHP functions we require PHP block functions to start with the phpblock_ prefix.

Once your function is called you have the full power of PHP at your disposal to do what ever you little heart desire.

Example

To drive the power of this home, let's try a real-world example that I recently added to Iowa Outdoors. This example will put a "refer this site" form on your site so others can refer your Geeklog website to others.

1) First, code the function in your lib-custom.php (remember function name must start with phpblock_ prefix). You can get the code for this how-to here.

2) Create the PHP block via the Geeklog block administration page:

  • Navigate to http://www.mygeeklogsite.com/admin/block.php
  • Click on the "New Block" link
  • Enter the block name, title, blockorder, side and be sure to select php_block from the block type drop-down
  • Scroll Down To PHP Block Options and enter the name of your function (for our example it would be phpblock_refer_site)
  • Assign appropriate permissions
  • Save it and you are done!
  • Other Information

    The function in the code-sample stores the number of referrals made in the database. If you want to ever find out how many referrals you have or want to add this to your stats.php page the SQL you would need is:
    SELECT value FROM vars WHERE name = 'num_site_referrals'

    Was this easy enough to follow?

    Story Options

    PHP Block How-To | 5 comments | Create New Account
    The following comments are owned by whomever posted them. This site is not responsible for what they say.
    custom code file
    Authored by: DoctorWho on Thursday, January 03 2002 @ 08:04 PM EST

    Where do we find the file to place custom php code
    functions in?
    I have seen it reffered to as lib-custom.php in this how-
    to and as custom_code.php in the GL-1.3
    Administration controlpanel for blocks.
    Can we use functions found in the custom file in the
    header.thtml and footer.thtml files?

    lib-custom.php
    Authored by: Tony on Friday, January 04 2002 @ 06:54 AM EST

    the file to add PHP Block code to is /path/to/geeklog/system/lib-custom.php

    I have updated admin/block.php so that the block editor instructions refer to that file instead of the old custom_code.php file.

    phpblock refer site html form code
    Authored by: DoctorWho on Friday, January 04 2002 @ 01:39 PM EST

    Can we see the html form code that is in the block for
    this refer a friend a site?

    PHP Block How-To
    Authored by: die:ikku on Monday, October 21 2002 @ 07:32 AM EDT

    it doesn\'t work and i don\'t know why...

    i wanted the journal block and the only result i get is this error on the frontpage:

    1146: Table \'ikku1.journal_entry\' doesn\'t exist

    can you help me???

    ---
    be my angel kiss my soul with your shape

    PHP Block How-To
    Authored by: Anonymous on Thursday, March 18 2010 @ 01:15 AM EDT

    Hi,

    I thought I would try out the refer site phpblock, but it doesn't seem to be working. It all comes up on the site and I can enter e-mail address but the message does not get sent on to the e-mail entered.

    Is there something else I need to be doing to make it work?

    Lizard.

    ---
    Give a person a fish and you feed them for a day.
    Teach a person to fish and you feed them for a lifetime.