HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


Minimodules

The ocPortal minimodule feature lets you create new ocPortal pages very easily. You don't need to code to any particular structure or API, just write plain PHP and output as normal from it. You have full access to ocPortal's APIs for when you need to interface with the rest of ocPortal.

Minimodules allow:
  • PHP programmers with no experience with ocPortal to hit the ground running
  • experienced ocPortal developers to develop simple pages without any coding overhead
  • easier porting of third-party PHP scripts into ocPortal (you may need to change some links around, and remove HTML header tags – but it's a lot easier than doing a rewrite)

We will present 3 examples. To try each out, simply save the code into a site/pages/minimodules_custom/example_page.php file, then call it up via http://yourbaseurl/site/index.php?page=example_page.
As you can see, site/pages/minimodules_custom/example_page.php corresponds to a page called example_page, in the site zone.

As minimodules are just a kind of ocPortal page, you can control access to them using normal ocPortal page permissions (i.e. set from Admin Zone > Security > Permission Tree Editor).

Example 1

The standard introductory example, Hello World.

PHP code

<?php

echo 'Hello World';

Example 2

Now let's do some simple ocPortal API calls.

PHP code

<?php

$username
=$GLOBALS['FORUM_DRIVER']->get_username(get_member());
echo 
'<p>Hello, '.htmlentities($username).'.</p>';

$time=get_timezoned_date(time());
echo 
'<p>It is '.htmlentities($time).'.</p>';

Example 3

Need to output a simple spreadsheet? You are allowed to set headers and exit(); within your page, so that ocPortal doesn't continue doing anything more after your spreadsheet has output and your code has run.

PHP code

<?php

header
('Content-type: text/plain');
header('Content-disposition: attachment; filename="example.csv"');

// Some arbitrary data to output
$example_data=array(
    array(
        
'country'=>'UK',
        
'capital'=>'London',
    ),
    array(
        
'country'=>'France',
        
'capital'=>'Paris',
    ),
);

foreach (
$example_data as $i=>$row)
{
    
// If first row, show show headings
    
if ($i==0)
    {
        foreach (
array_keys($row) as $heading)
        {
            echo 
csv_escape($heading).',';
        }
        echo 
"\n";
    }

    
// Show values
    
foreach ($row as $value)
    {
        echo 
csv_escape($value).',';
    }
    echo 
"\n";
}

exit();

function 
csv_escape($value)
{
    return 
str_replace('"','""',$value);
}

Integrations

You may wish to integrate with another database (i.e. not ocPortal's main database), third-party web-services, or other programming languages.

These complexities can be dealt with in the same way as any PHP programmer would deal with them, while making use of ocPortal's APIs only as is convenient.

For example, you can use:
  • standard PHP database functionality to open a new connection (MySQL, SQL Server, Oracle, …)
  • PHP's file_get_contents function to download from REST web services
  • PHP's file_get_contents function to download from scripts written in another language, bridging their output over into the ocPortal page
  • PHP's SOAP support to integrate with more complex REST services (assuming the PHP SOAP extension is installed)
  • PHP's COM support to integrate to ASP code (assuming the PHP COM extension is installed)

Example 4

This simple example shows how to bridge one web system, to another. The example embeds Google into your page. Naturally, this is a silly example, but the same technique can be used to bridge your own scripts, should you be more comfortable programming in a language other than PHP.

PHP code

<?php

echo '<div style="position: relative; overflow: hidden">';
echo 
file_get_contents('http://google.com/');
echo 
'</div>';

Note I had to add a little CSS to stop Google trying to render parts of its layout on-top of the ocPortal website.

There are no pages beneath this page

There are no posts yet

CEDI change-log Post