Documentation

PHP Integration

The following PHP class can be used to pull KitGUI content and can be placed within any include file as part of a utility script of your website.

Simplest approach:

<?php
class KitGUI {
    /**** replace with your own KitGUI CMS Account Key ****/
    const accountKey = "00000000000000000000000000000000";
    public static function getContent($contentID, $contentType) {
        if (preg_match('/^[a-zA-Z]+[a-zA-Z0-9\\-_]*$/',$contentID) == 0) {
            throw new Exception('KitGUI content ID must begin with a letter ([A-Za-z]) and ' .
            'may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_")'); 
         }
         $url = "http://s3.amazonaws.com/kitgui/clients/" . KitGUI::accountKey .  "/ids/" . $contentID . ".txt";
         $raw = file_get_contents($url);
         if (isset($_COOKIE["kitgui"]) && $_COOKIE["kitgui"] == "1") {
            return "<div style=\"display:inline-block\" class=\"kitgui-id-" . $contentID . " " .
                 "kitgui-content-type-" . $contentType . "\">" . $raw . "</div>";
        } else {
            return $raw;
        }
    }
}
?>

 

Alternative approach if you desire caching:

Requires APC for caching ( http://php.net/manual/en/book.apc.php )

<?php
class KitGUI {
    /**** replace with your own KitGUI CMS Account Key ****/
    const accountKey = "00000000000000000000000000000";
    public static function getContent($contentID, $contentType) {
        if (preg_match('/^[a-zA-Z]+[a-zA-Z0-9\\-_]*$/',$contentID) == 0) { 
            throw new Exception('KitGUI content ID must begin with a letter ([A-Za-z]) and ' .
            'may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_")'); 
        }
        $editMode = (isset($_COOKIE["kitgui"]) && $_COOKIE["kitgui"] == "1");        
        if (!$editMode) {
            $raw = apc_fetch($contentID);
        }
        if ($editMode || empty($raw)) { // invalidates cache if in edit mode
            $url = "http://s3.amazonaws.com/kitgui/clients/" . KitGUI::accountKey . "/ids/" . $contentID . ".txt";
            $raw = file_get_contents($url);
            app_store($raw,$contentID,3600); // cache for an hour
        }
        if ($editMode) {
            return "<div style=\"display:inline-block\" class=\"kitgui-id-" . $contentID . " " .  
            "kitgui-content-type-" . $contentType . "\">" . $raw . "</div>";
        } else {
            return $raw;
        }
    }
}
?>
 
The following is an example of using the above class on a PHP page to pull in content ID "your-content-id" that is of content type "HTML".

<body>
    <?php echo KitGUI::getContent("your-content-id","HTML"); ?>
</body>


You can dynamically set this content ID as it does not have to exist. It will only exist once saved when in edit mode. This means using dynamic URLs is very interesting if you set the content ID by the URL.