This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/core/block.class.php

92 lines
1.9 KiB
PHP
Raw Normal View History

<?php
2009-07-19 07:38:13 +00:00
/**
* A basic chunk of a page
*/
class Block {
2009-07-19 07:38:13 +00:00
/**
* The block's title.
2009-07-19 07:38:13 +00:00
*
* @var string
2009-07-19 07:38:13 +00:00
*/
public $header;
2012-03-12 04:39:04 +00:00
2009-07-19 07:38:13 +00:00
/**
* The content of the block.
2009-07-19 07:38:13 +00:00
*
* @var string
2009-07-19 07:38:13 +00:00
*/
public $body;
2012-03-12 04:39:04 +00:00
2009-07-19 07:38:13 +00:00
/**
* Where the block should be placed. The default theme supports
* "main" and "left", other themes can add their own areas.
2009-07-19 07:38:13 +00:00
*
* @var string
2009-07-19 07:38:13 +00:00
*/
public $section;
2012-03-12 04:39:04 +00:00
2009-07-19 07:38:13 +00:00
/**
* How far down the section the block should appear, higher
* numbers appear lower. The scale is 0-100 by convention,
* though any number or string will work.
*
* @var int
2009-07-19 07:38:13 +00:00
*/
public $position;
2012-03-12 04:39:04 +00:00
/**
* A unique ID for the block.
*
* @var string
2012-03-12 04:39:04 +00:00
*/
public $id;
2012-03-12 04:39:04 +00:00
/**
* Construct a block.
*
* @param string $header
* @param string $body
* @param string $section
* @param int $position
* @param null|int $id A unique ID for the block (generated automatically if null).
*/
2012-03-12 04:39:04 +00:00
public function __construct($header, $body, /*string*/ $section="main", /*int*/ $position=50, $id=null) {
$this->header = $header;
$this->body = $body;
$this->section = $section;
$this->position = $position;
2012-03-12 04:39:04 +00:00
$this->id = str_replace(' ', '_', is_null($id) ? (is_null($header) ? md5($body) : $header) . $section : $id);
}
/**
* Get the HTML for this block.
*
* @param bool $hidable
* @return string
*/
2012-03-12 04:39:04 +00:00
public function get_html($hidable=false) {
$h = $this->header;
$b = $this->body;
$i = $this->id;
$html = "<section id='$i'>";
$h_toggler = $hidable ? " shm-toggler" : "";
2012-03-19 19:00:25 +00:00
if(!empty($h)) $html .= "<h3 data-toggle-sel='#$i' class='$h_toggler'>$h</h3>";
if(!empty($b)) $html .= "<div class='blockbody'>$b</div>";
2012-03-12 15:06:07 +00:00
$html .= "</section>\n";
2012-03-12 04:39:04 +00:00
return $html;
}
}
2009-07-19 07:38:13 +00:00
/**
* A generic navigation block with a link to the main page.
*
* Used because "new NavBlock()" is easier than "new Block('Navigation', ..."
*/
class NavBlock extends Block {
public function __construct() {
parent::__construct("Navigation", "<a href='".make_link()."'>Index</a>", "left", 0);
}
}