[how-to] Render Box block
Posted
#504
(In Topic #106)

Site director

In this tutorial, I will show you how to make a simple block which can create/render a box of virtually any kind of Composr content via. meta_aware hooks.
Difficulty to implement: EasyDifficulty to use: Easy-moderate
Implementation
sources_custom/blocks/main_render_box.php
Include the following in the file:
Code (php)
<?php
class Block_main_render_box
{
public function info()
{
$info = array();
$info['author'] = 'Patrick Schmalstig';
$info['organisation'] = 'The Lovinity Community+';
$info['hacked_by'] = null;
$info['hack_version'] = null;
$info['version'] = 1;
$info['locked'] = false;
$info['parameters'] = array('content_type','content_id');
return $info;
}
public function run($map)
{
i_solemnly_declare(I_UNDERSTAND_SQL_INJECTION | I_UNDERSTAND_XSS | I_UNDERSTAND_PATH_INJECTION);
require_code('content');
$ob=get_content_object($map['content_type']);
list($content_title, $poster_id, $cma_info, $content_row, $content_url) = content_get_details($map['content_type'], $map['content_id']);
return $ob->run($content_row, get_module_zone($cma_info['module']));
}
}
?>
class Block_main_render_box
{
public function info()
{
$info = array();
$info['author'] = 'Patrick Schmalstig';
$info['organisation'] = 'The Lovinity Community+';
$info['hacked_by'] = null;
$info['hack_version'] = null;
$info['version'] = 1;
$info['locked'] = false;
$info['parameters'] = array('content_type','content_id');
return $info;
}
public function run($map)
{
i_solemnly_declare(I_UNDERSTAND_SQL_INJECTION | I_UNDERSTAND_XSS | I_UNDERSTAND_PATH_INJECTION);
require_code('content');
$ob=get_content_object($map['content_type']);
list($content_title, $poster_id, $cma_info, $content_row, $content_url) = content_get_details($map['content_type'], $map['content_id']);
return $ob->run($content_row, get_module_zone($cma_info['module']));
}
}
?>
Save.
Usage
To use, simply "add block" in your content, find the Main Blocks, Misc section, and click Render Box.You will need to fill in content type and content ID fields.
Content type related to the content meta_aware hook name found in sources[_custom]/hooks/systems/content_meta_aware . For example, if you're rendering a forum topic, the type is topic. Forum post is type post. Comcode page type is comcode_page . Wiki+ page type is wiki_page . And so on.
Content ID is the ID of the item you're rendering. For forum post, it's the post ID #. For topic, it's the topic ID number. And so on. You may need to do a little searching to find it.
Demo
To see this in action, go to https://lovinity.org/news/view/front-page/the-lovinity-community-7?select=8&blog=0
Last edit: by Chris Graham
- Need support for version 10? The core development team is no-longer offering it for free (unless it's a critical bug that breaks your entire site or a serious security hole). Please consider hiring me instead if you need v10 support or a non-critical bug fix. Or, ask the community in the forums!
- Do you enjoy Composr? Please consider contributing your talent to the project or recommending Composr to others. Even small contributions make a big impact in the Composr community.
- Do you have feedback for us? You can report bugs, suggest features, or give feedback on the Free support options page.
- Do you need professional service with your Composr website? Please consider contracting me for your needs through my company, PDStig, LLC. Doing so will also help fund Composr development.
- Want to watch live streams of me developing Composr CMS? Please subscribe to me on Twitch to be notified when I stream. Composr development streams are usually spontaneous / not scheduled in advance as work priorities come first.
1 guest and 0 members have just viewed this.