Opus   Opus 2.30 Publisher's Manual
   Product Overview
   Installation and Set Up
   Customising a Paper 
   Templates
   Using Datacards
   Using Objects
   Author Maintenance
   Activity Logging
   Technical Issues
   Appendices

Note that text shown in this style documents a feature which isn't in the current release but will be in the next release and text shown thus indicates a feature which is being removed in the next release.

If you find anything in this documentation which is wrong or unclear then please use the link at the bottom on the page to comment and we will update the page to correct it or make it clearer.

Search:


Using Objects

Basics

An object in Opus consists of three elements: its name, which can be up to twenty characters, its description, which describes what it is, and its content, which can be up to 64Kbytes of text. This text can include HTML but not Opus mark up.

You can insert the content of an object into a web page in two ways:

There are three sorts of objects: system, user and paper.

System Objects

System objects have names beginning with a "$" and let you insert changing system information from Opus in your web pages. The following system objects are available:

$time-12hmTime now in 12 hour HH:MM format10:11 am
$time-12hmsTime now in 12 hour HH:MM:SS format10:11:55 am
$time-24hmTime now in 24 hour HH:MM format10:11
$time-24hmsTime now in 24 hour HH:MM:SS format10:11:55
$date-isoToday's date in ISO format (YYYY-MM-DD)2026-04-09
$date-dmyToday's date in DD/MM/YY format09/04/26
$date-mdyToday's date in MM/DD/YY format04/09/26
$date-longToday's date in long format9th April, 2026
$date-arpaDate/time in RFC922 (APRA) formatThu, 09 Apr 2026 10:11:55 +0100
$day-shortDay in three letter short formatThu
$day-longDay in long formatThursday
$monthMonth nameApril
$yearYear2026
$copy-yearsRange of years from a year until now e.g. {object:$copy-years>2011}2026
$author-nameThe author's name if the someone is logged onJohn Smith
$opus-releaseCurrent Opus release3.00
$opus-release-fullCurrent Opus release including sub-release number3.00.6
$meta_og'meta property="og:...' tags (needs significant set up)-
$mp3An MP3 player, syntax {object:$mp3>URL of MP3}an MP3 player
$movedPage permanently moved syntax {object:$moved>new URL}Hops reader to new URL - note warning when editing
$pdfThe size of an external PDF, syntax {object:$pdf>250}(Adobe/PDF, 250KB)
$tweetTwitter tweet {object:$tweet>unique_id}a Twitter tweet
$youtubeAn embedded YouTube video {object:$youtube>unique_id}a YouTube video
[Unknown user object ]

 

User Objects

Updating Objects From Within Opus

You can update objects from within Opus using the "Browse objects" option in the author menu.

Updating Objects From Outside Opus

Assuming that you have access to the MySQL server and the right permissions you can update an object from outside Opus using the shell script ./bin/opus_object.sh. This script is a pipe which takes five parameters. You send the content you want to insert to:

where host is the host where the MySQL server lives, user and pass are the username and password for accessing the database, database is the Opus MySQL database you want to update, and name is the name of the object you want to update. You can optionally pass a description in desc and, if you've got more than one paper, you need to identify that by passing the papercode in paper (assumed to be 1 if not passed).

Using PHP in User Objects

Is is possible to embed PHP code within an object. This is a powerful and potentially dangerous feature in the wrong hands so only the publisher can create such objects. An object which uses PHP must begin <?php and end ?>. When the code is run it must set a variable $contents which contains the contents of the object which are to be displayed.

Your web browser isn't the ideal PHP programming editor so it's perfectly possible to include code from a file. We have an object camweather which we use in the Milton Village site which displays the current weather in a text box. The PHP code for this is in a file weather.inc and the object contents are simply:

<?php
include("../web/weather.inc");
?>

Paper Objects

If you want to go beyond the embedding of PHP into a user object you can use a paper object. You would use this if you need to do something complicated in PHP. You create a file objects.inc in your paper's directory.

This should include within it a function paper_object() which takes a single parameter, the name of an object, and returns the value of the object.

Your code can do what it likes, although for safety you should precede any functions you create with a suitable prefix so you don't get function name clashes with Opus - a good choice would be local_.

Having created the object in your function paper_object() you must also define in it Opus. You can do this using the "Browse objects" option in the author menu.

You can now use the object in your templates or articles, prefixed by "#". Here's a simple example of an objects.inc file:

<?php
function paper_object($name)
{
    switch { $name }
    {
        case "test":
            return "Hello world";
        default:
            return "[Unknown object ".$name."]";
    } 
}
?>

You can then refer to this in an article as {object:#test} and will result in the text "Hello world" appearing in the article at the position when it's published.

Note the error message returned if the object name isn't recognised: if you use this exact format then when checking an article an author has written Opus can spot invalid objects.

Why Are Objects Useful?

System objects are useful for inserting information into web pages which changes often, like today's date and the usefulness of paper objects is only limited by your imagination.

User objects are useful for two things: as a shorthand for putting long bits of text into an article which occurs on many pages (but do think about doing this from the template, possibly using an <opustest> ... </opustest> portion of the template). They are also useful for other information which changes often. For example suppose you change the sales executive responsible for modem sales fairly often but you need to refer to that sales executive by name in every web page (i.e. article) about a modem.. Then you can create an object named modem-salesexec and in all your articles about modems you would put:

And then by changing the contents of the modem-salesexec object all the pages referring to it would change automatically.

Comment on this page

Copyright
Privacy Policy