Examples - Gargaj/contentifier GitHub Wiki

Simple setup

<?php
include_once("contentifier/contentifier.php");

class MyContentifier extends Contentifier
{
  public function sqlpass() { return "contentifier123"; }
}

$contentifier = new MyContentifier();
$contentifier->run();
?>

Using SQLite

<?php
include_once("contentifier/contentifier.php");

class MyContentifier extends Contentifier
{
  public function sqldsn() { return "sqlite:test.db"; }
  public function sqlpass() { return null; }
}

$contentifier = new MyContentifier();
$contentifier->run();
?>

Explicit SQL credentials

<?php
include_once("contentifier.min.php");

class MyContentifier extends Contentifier
{
  public function sqldsn() { return "mysql:dbname=myotherdatabase"; }
  public function sqluser() { return "myusername"; }
  public function sqlpass() { return "mypass"; }
}

$contentifier = new MyContentifier();
$contentifier->run();
?>

Using a more complex template

<?php
include_once("contentifier/contentifier.php");

class MyContentifier extends Contentifier
{
  public function sqlpass() { return "contentifier123"; }
  public function render() { include_once("template.inc.php"); }
}

$contentifier = new MyContentifier();
$contentifier->run();
?>

In template.inc.php:

<?php
$content = $this->content();
if ($content === false || $content === null)
{
  header("HTTP/1.1 404 Not Found");
  $content = "<h1>404</h1><p>Page '".$this->escape($this->slug)."' not found</p>";
}
?>
<!DOCTYPE html>
<html>
<head><link href="<?=$this->rooturl()?>design/style.css" rel="stylesheet" media="all"></head>
<body>
  <nav><?=$this->menu()?></nav>
  <div id="content"><?=$content?></div>
</body>
</html>

Basic plugins

<?php
include_once("contentifier/contentifier.php");

class MyPagePlugin extends ContentifierPagePlugin
{
  public function id() { return "year"; }
  public function adminmenuitem() { return null; }

  // This plugin will handle pages at e.g. http://mysite/year/1994
  public function slugregex() { return "year\/([0-9]{4})"; }
  // The matches above are passed down as parameter here
  public function content($match) { return "The year is ".$match[1]."."; }
}

class MySCPlugin extends ContentifierShortCodePlugin
{
  public function __construct($contentifier) { $this->contentifier = $contentifier; }
  public function id() { return "sc"; }
  public function adminmenuitem() { return "SC"; }

  public function shortcode() { return "shortcode"; }
  public function content($p)
  { 
    $out = "[start shortcode]\n";
    if (count($p)>=2) $out .= sprintf("%d * %d = %d\n",$p[0],$p[1],$p[0]*$p[1]); 
    $out .= "user count: " . $this->contentifier->sql->SelectRow("select count(*) as c from users")->c."\n";
    $out .= "[end shortcode]\n";
    return $out;
  }
}

class MyContentifier extends Contentifier
{
  public function sqlpass() { return "contentifier123"; }
}

$contentifier = new MyContentifier();
$contentifier->addplugin( new MyPagePlugin() );
$contentifier->addplugin( new MySCPlugin($contentifier) );
$contentifier->run();
?>
⚠️ **GitHub.com Fallback** ⚠️