[how-to] Render Box block
Posted
#559
(In Topic #160)
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
1 guest and 0 members have recently viewed this.