PHP-based page block: you can make it!

IgorL posted 22nd of March 2010 in Community Voice. 12 comments.

In this post I want to teach you how to create a PHP block on a page.

For example, you want to create a block displaying the membership level of the profile you're viewing.

1) First, you will have to create a simple HTML block. Navigate to '''Builders -> Pages Blocks''' and choose '''Profile''' from the '''Pages''' frop-down list. This is because we want to see this block on the profile page.

Drag the '''HTML Block''' from the '''Samples''' area to either of the columns in the '''Active Blocks''' area and place it under any block (for example under '''Photo Albums''' in the first column).

Now click the '''HTML Block''' you have just dragged. A small window will appear. In this window, you will have to create a language key for this block's '''Caption''' (for example '''_My Membership Type''' - notice that all language keys must have leading underscores).

Then make this block visible or invisible to '''Guests''' or '''Members''' by clicking or un-clicking the corresponding checkboxes.

And now enter any text in the field '''HTML-content'''. This text will not be used, so you can type anything here.

Press '''Save'''.

2) Now let's create the string for the key '''_My Membership Type'''. Navigate to '''Settings -> Language Settings''' and click the '''Add key''' button in the block '''Manage Keys'''.

In the window that will appear, enter the key name '''_My Membership Type''', choose its category, for example '''Boonex Profiler''' and type the corresponding strings for all installed languages, for example '''My Membership Type''' will be used for the English language. Now '''Save''' the window.

3) Ok. Now comes the most interesting part - you will have to turn this HTML block into a PHP block. This can be done in the database, so open phpMyAdmin (I assume once again that you know how to use it) and find the table '''sys_page_compose'''.

In this table you will have to search for the record corresponding to the block you have just created. Just search for its caption which will be '''_My Membership Type'''.

Now edit this record: change the value of the '''Func''' column into '''PHP''' instead of '''Echo'''. And enter your desired PHP code in the column '''Content'''. In our case this code will be:

echo GetMembershipStatus($this->oProfileGen->_iProfileID);

Now save the record (click '''Go''').

4) Now you will only have to recompile the block by moving it a little bit in '''Builders -> Pages Blocks -> Profile'''. And you should of course clean the cache: '''Admin Home -> Cache -> Clean All'''

5) Navigate to someone's profile and enjoy the result.

 
Comments
·Oldest
·Top
Please login to post a comment.
tomakali
Great...
If i can find some download link for this "mod"
id be happy to plugin to my module manager:-)
Audanbal
http://www.boonex.com/unity/extensions/entry/Advanced_Add_Block_Feature_1_0_0
houstonlively
Why don't you guys just add a php block to page builder, so people don't have to go burrowing through their database every time they want to add a php block? I added a ticket for this a LONG time ago, and even posted the code Deano provided to do the job.

In the time it took you to explain this, you could have added this functionality to page builder. This is not an acceptable method. Try again.
hd4real
I am with HL on this. How can you expect us to do this for every php block we need. I am using Deano's method. You guys are giving people more work then needed.
Mulchit
I am wondering if this is possible on a new page that I have created?
AngelusUK
Ok this worked for me - but I have a couple of questions...

When I click on a members profile - it now shows the members level of membership - but it also shows other things like how long they have left at the current level - allowed actions - and in standard membership levels it provides a link to upgrade (which really should only show to the member himself...is there a way to just show the membership level without all of the other stuff?
mauricecano
It is not acceptable to go routing through phpmyadmin to make a php block. Obviously you posted this because you are getting many request about a php block in boonex, meaning you are missing a basic functionality again. Instead close out this ticket: http://www.boonex.com/trac/dolphin/ticket/1578 the code and everything needed to give boonex php block functionality is already there. It will take a few minutes at most and less time then it took to post the blog!
houstonlively
NOTE:

The code for the file, inc/classes/BxDolPageViewAdmin.php has undergone several revisions since I posted it, so anyone wanting to make the changes should refer to Deano's instructions in the thread and NOT use the code posted in the ticket.

The point is... Deano offered this code four months ago, yet this ticket was placed on the D7.1 "Enhancements" pile.

Igor... if you want to do something that really helps, go clear that ticket.
belami25
This is perfect, now I have a block with the type of membership of the member on their profile.

I would like a small improvement

I would add next to the membership type, an icon that I downloaded.

example:

I created a membership type that is: moderator and this is what appears on the profile

Moderator
(View Allowed Actions)
expires: never

All information as well as "moderator" to me are not useful and I would like to add the icon (picture) that I downloaded specifically see more for this type of subscription.

how?
jerardg
4) Now you will only have to recompile the block by moving it a little bit in '''Builders -> Pages Blocks -> Profile'''.
And you should of course clean the cache: '''Admin Home -> Cache -> Clean All'''

Cannot see "Cache" option? in my dashboard? using 6.1.4 thanks
DosDawg
HL,
indeed, this should be fixed instead of setting instructions on the blog to tell those who have no clue what PHP/Mysql are, how to add a php block to their site.

Regards,
DosDawg
CALTRADE
Igor - Just inlude Deano's mod in the base product - he has done you a great service by doing this program. While you are at it, got to the forums and look at all the other nice things your members here have made that could be included. Many of them should have been in the product from the beginning anyway.

@Dosdawg - don't you remember busting my balls for saying exactly what you just said above?
 
 
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.
PET:0.043637037277222