Details

A quick guide to Content Types

Processor.xml DEFINES Content Type
Cratr: REGISTERS / EXPLAINS / SETS Content Type
Content.xml IS FORMED according to Content Type
Interpreter OPERATES ACCORDING TO Content Type

PROCESSORS MUST have a Content Type declaration so that each processor within an available class can classify their output.

INTERPRETERS MUST be written according to known Content Type conventions

CRATE.XML conventions

Abbreviations:
G - value set automatically by Cratr
U - value set by User at Forms

<CRATE>

<meta CRATEID=G URL=U&G name=U author=U author_reg=G description=U CRATE_Type=U title_image=U ti_caption=U date_created=G date_modified=G >

<tags>

<tag>U</tag>

</tags>
<interpreters>
Note: These are present for later modification of the crate and to know how the author prefers to present this CRATE

<interpreter />

<interpreters>
<content_stats>

<stat type=G amount=G />

</content_stats>

</meta>

<content>


<[Content Type]-Type processorID=G>

<[Content Type] [ContentType Attributes]=G> [Primary String Associated with File - usually file name]
</[Content Type]>

</[ContentType]-Type>

</content>

</CRATE>

PROCESSOR.XML conventions

<CRATE_PROCESSOR>

<name>[Processor Class Name MUST BE SAME AS FILE NAME]</name>
<processor_ID registered=[Set to FALSE if this processor has not been registered at the CRATES project.>
[Unique ID for this Processor]
</processor_ID>
<version>[Version]</version>
<reldate>[Date this version was released DDMMYYYY]</reldate>
<description>[Description]</descripton>
<icon>[Filename of 130 x 130 px image in current directory]</icon>
<author>[Author information]</author>
<authorsite>[URL of author's site]</authorsite>
<FileType>[Name of group of FileTypes from configuration.php]
</FileType>
<ContentType>[String used as the name of the ContentType of this
Processor]
</ContentType>
<attributes>

<attribute description=[Short description of attribute and source of data (ie "Genre description of MP3 file taken from ID3 tag 'genre'")]>
[Title of attribute to be added to the ContentType node in XML output]
</attribute>

</attributes>
<alternate_types>

<alt_type>[Known ContentType with which Interpreters can be associated to be used with output from this Processor]</alt_type>

<alternate_types>

</CRATE_PROCESSOR>

What a Processor Looks Like:

This is called in generate.php. Has access to configuration.php.

<?php

class processor_name{

public $output = array();

function process(){
$output = $this->output;

// the following two variables are set from this Processor’s
// processor.xml and used to populate $nodeArray

global $attributeTitles;
global $contentType;

// directory containing content
global $dir;

// array of files detected to be compatible with this processor
global $acceptedFiles;

// complete content of <meta> to be used in final crate
global $meta;

foreach ($acceptedFiles as $file){

$nodeArray = array();

// begin populating $nodeArray with [ATTRIBUTE TITLES]=>[PROCESSED VALUE]
// $nodeArray['nodevalue'] is ALWAYS the value of the xml node this will create

## some code that does something to something else and enters
## information into $nodeArray
## At some point it MUST assign $nodeArray['nodevalue']

array_push($output, $nodeArray);

} # end foreach file
return $output;
} #end process

} #end class

?>

INTERPRETER.XML conventions

<CRATE_INTERPRETER>

 <name>[Interpreter Class Name]</name>
<version>[Version]</version>
<reldate>[Date this version was released]</reldate>
<description>[Description]</description>
<icon>[Filename of 130x130 px image in current directory]
</icon>
<author>[Author information]</author>
<authorsite>[URL of author's site]</authorsite>
<accepted_types>
    <ContentType>[ContentType accepted by this     Interpreter]</ContentType>
</accepted_types>
<stylesheets enable_default=[Set to FALSE if this Interpreter does NOT allow the use of stylesheets in CRATES/css. Set to TRUE otherwise.]>
***repeat as necessary***
<stylesheet>[Filename of stylesheet included in current directory]
</stylesheet>
</stylesheets>

</CRATE_INTERPRETER>

What an Interpreter Looks Like

This is sent as an include to the index.php file which is written into the directory of each new CRATE. Has access to configuration.php.

<?php
// location of the interperter.xml file associated with this interpreter
$this_dir = $cratrRoot.$interp_dir.[THIS INTERPRETER’S DIRECTORY]/;
$this_web_dir = $webCratr.$interp_dir.[THIS INTERPRETER’S DIRECTORY];
$interpxml = $this_dir.'interpreter.xml';

if (file_exists($interpxml)){
$inxml = simplexml_load_file($interpxml);
$acceptedTypes = array();
$CSS = array();
foreach($inxml->accepted_types->ContentType as $value){
array_push($acceptedTypes, substr($value, 0));

}
}

if (file_exists('crate.xml')) {

$xml = simplexml_load_file('crate.xml');
$CRATEname = $xml->meta['name'];
$address = $xml->meta['address'];
$CRATEdescription = $xml->meta['description'];
$CRATEauthor = $xml->meta['author'];
$CRATEdate = $xml->meta['dateCreate'];
$CRATEmod = $xml->meta['dateMod'];
$CRATEID = $xml->meta['ID'];
$CRATEtags = array();

$contentNode = $xml->xpath('//content');

// find ContentTypes within crate.xml that are compatible with this interpreter
foreach ($contentNode as $value){
foreach ($value as $innerkey => $innervalue){
foreach ($acceptedTypes as $at){
$atParent = $at.'_Type';
if ($atParent == $innerkey){
$typeNode = $xml->xpath('//content/'.$atParent.'/'.$at);
$firstImg = $xml->xpath('//content/'.$atParent.'/'.$at.'[1]');

 

# code that does something with the information in crate.xml
# there are no requirements

}# end if $atParent

} # end foreach $acceptedTypes

}# end foreach $value
} # end foreach $contentNode

}

else {
exit('Failed to open CRATE');
}

?>

REPORTER.XML conventions

Reporter XML schema will be similar to processor.xml and interpreter.xml, but constructed with consideration to database connections and other web platforms. Input is encouraged.

See master.xml reporter section within generate.php for some basics of what a Reporter will look like.