/** * Format the output * - depends on optional URL parameter 'format' * * @param Object $object - the data to format * @return string */ function format_output($object) { global $FORMAT, $CFG, $ERROR, $LNG, $HUB_FLM; $method = optional_param("method", "", PARAM_ALPHA); if ($FORMAT && $FORMAT->allowed_methods() != null && !$object instanceof error) { if (!in_array($method, $FORMAT->allowed_methods())) { $ERROR = new error(); $ERROR->createInvalidMethodForTypeError(); include $HUB_FLM->getCodeDirPath("api/formaterror.php"); die; } } if ($FORMAT) { return $FORMAT->format($object); } else { // Fix for when this is called from a ui window without a format setup first. $format = optional_param('format', 'xml', PARAM_ALPHA); $classfile = $HUB_FLM->getCodeDirPath("core/formats/" . $format . ".php"); if (file_exists($classfile)) { include_once $classfile; } else { echo $LNG->CORE_FORMAT_INVALID_SELECTION_ERROR; die; } $classname = 'format_' . $format; $FORMAT = new $classname(); return $FORMAT->format($object); } }