add('name', PLUGIN_EVENT_INCLUDEENTRY_NAME);
$propbag->add('description', PLUGIN_EVENT_INCLUDEENTRY_DESC);
$propbag->add('stackable', false);
$propbag->add('author', 'Garvin Hicking');
$propbag->add('version', '2.17');
$propbag->add('scrambles_true_content', true);
$propbag->add('requirements', array(
'serendipity' => '2.0',
'smarty' => '2.6.7',
'php' => '4.1.0'
));
$propbag->add('page_configuration', $this->config);
$propbag->add('event_hooks', array(
'frontend_display' => true,
'backend_sidebar_entries_event_display_staticblocks' => true,
'backend_sidebar_entries' => true,
'backend_entryform' => true,
'frontend_display:html:per_entry' => true,
'backend_display' => true,
'backend_publish' => true,
'backend_save' => true,
'frontend_display_cache' => true
));
$propbag->add('groups', array('MARKUP'));
$this->markup_elements = array(
array(
'name' => 'ENTRY_BODY',
'element' => 'body',
),
array(
'name' => 'EXTENDED_BODY',
'element' => 'extended',
),
array(
'name' => 'COMMENT',
'element' => 'comment',
),
array(
'name' => 'HTML_NUGGET',
'element' => 'html_nugget',
)
);
$conf_array = array();
$conf_array[] = 'enabled_categories';
$conf_array[] = 'randomize';
$conf_array[] = 'first_show';
$conf_array[] = 'show_skip';
$conf_array[] = 'show_multi';
foreach($this->markup_elements as $element) {
$conf_array[] = $element['name'];
}
$propbag->add('configuration', $conf_array);
$ec = (array)explode(',', $this->get_config('enabled_categories', false));
$this->enabled_categories = array();
foreach($ec AS $cid) {
if ($cid === false || empty($cid)) {
continue;
}
$this->enabled_categories[$cid] = true;
}
}
function introspect_config_item($name, &$propbag)
{
switch($name) {
case 'show_multi':
$propbag->add('type', 'boolean');
$propbag->add('name', STATICBLOCK_SHOW_MULTI);
$propbag->add('description', STATICBLOCK_SHOW_MULTI_DESC);
$propbag->add('default', false);
return true;
break;
case 'randomize':
$propbag->add('type', 'boolean');
$propbag->add('name', STATICBLOCK_RANDOMIZE);
$propbag->add('description', STATICBLOCK_RANDOMIZE_DESC);
$propbag->add('default', false);
return true;
break;
case 'first_show':
$propbag->add('type', 'string');
$propbag->add('name', STATICBLOCK_FIRST_SHOW);
$propbag->add('description', STATICBLOCK_FIRST_SHOW_DESC);
$propbag->add('default', '1');
return true;
break;
case 'show_skip':
$propbag->add('type', 'string');
$propbag->add('name', STATICBLOCK_SHOW_SKIP);
$propbag->add('description', STATICBLOCK_SHOW_SKIP_DESC);
$propbag->add('default', '1');
return true;
break;
case 'enabled_categories':
$propbag->add('type', 'content');
$propbag->add('default', $this->getCategories());
return true;
break;
case 'ENTRY_BODY':
case 'EXTENDED_BODY':
case 'COMMENT':
case 'HTML_NUGGET':
$propbag->add('type', 'boolean');
$propbag->add('name', constant($name));
$propbag->add('description', sprintf(APPLY_MARKUP_TO, constant($name)));
$propbag->add('default', 'true');
return true;
break;
}
return false;
}
function introspect_item($name, &$propbag) {
global $serendipity;
switch($name) {
case 'title':
$propbag->add('type', 'string');
$propbag->add('name', TITLE);
$propbag->add('description', '');
$propbag->add('default', '');
break;
case 'body':
$propbag->add('type', 'html');
$propbag->add('name', ENTRY_BODY);
$propbag->add('description', '');
$propbag->add('default', '');
break;
case 'extended':
$propbag->add('type', 'html');
$propbag->add('name', EXTENDED_BODY);
$propbag->add('description', '');
$propbag->add('default', '');
break;
case 'template':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_EVENT_INCLUDEENTRY_FILENAME_NAME);
$propbag->add('description', PLUGIN_EVENT_INCLUDEENTRY_FILENAME_DESC);
$propbag->add('default', 'plugin_staticblock.tpl');
$propbag->add('only_type', 'block');
break;
case 'apply_markup':
$propbag->add('type', 'boolean');
$propbag->add('name', sprintf(APPLY_MARKUP_TO, 'Block'));
$propbag->add('description', '');
$propbag->add('default', true);
$propbag->add('only_type', 'block');
break;
}
return true;
}
function generate_content(&$title) {
$title = $this->title;
}
function parse(&$element) {
global $serendipity;
$element = preg_replace_callback(
"@\[(s9y-include-entry|s9y-include-block):([0-9]+):?([^:]+)?\]@isUm",
array($this, 'parseCallback'),
$element
);
return true;
}
function set_config($name, $value, $implodekey = '^')
{
$fname = $this->instance . '/' . $name;
if (is_array($value)) {
$dbval = implode(',', $value);
} else {
$dbval = $value;
}
$_POST['serendipity']['plugin'][$name] = $dbval;
return serendipity_set_config_var($fname, $dbval);
}
function &getCategories() {
global $serendipity;
$html = (($serendipity['version'][0] < 2) ? '' . CATEGORIES . '
' : '') ."\n";
$all_valid = false;
if (is_array($serendipity['POST']['plugin']['enabled_categories'])) {
$valid = $this->enabled_categories = array();
foreach ($serendipity['POST']['plugin']['enabled_categories'] AS $idx => $id) {
$valid[$id] = true;
$this->enabled_categories[$id] = true;
}
} else {
$valid =& $this->enabled_categories;
if (count($valid) == 0) {
$all_valid = true;
}
}
$html .= ''."\n";
return $html;
}
function parseCallback($buffer) {
global $serendipity;
if (!isset($buffer[3]) || empty($buffer[3])) {
$buffer[3] = 'body';
}
$id = (int)$buffer[2];
switch($buffer[1]) {
case 's9y-include-block':
$this->fetchStaticBlock($id);
if ($buffer[3] == 'template') {
$newbuf = $this->smartyParse($this->staticblock['template']);
} else {
$newbuf = $this->staticblock[$buffer[3]];
}
break;
default:
case 's9y-include-entry':
if (preg_match('/^prop[=:]/', $buffer[3])) {
$entry = serendipity_fetchEntryProperties($id);
$propname = preg_replace('/^prop[=:]/', '', $buffer[3]);
$newbuf = $entry[$propname];
} else {
$entry = serendipity_fetchEntry('id', $id, true, 'true');
$newbuf = $entry[$buffer[3]];
}
break;
}
return $newbuf;
}
function install() {
$this->check();
}
function check() {
global $serendipity;
$built = $this->get_config('db_built', null);
if (empty($built)) {
$q = "CREATE TABLE IF NOT EXISTS {$serendipity['dbPrefix']}staticblocks (
id {AUTOINCREMENT} {PRIMARY},
title varchar(255) not null default '',
type varchar(255) not null default '',
body text,
extended text,
template varchar(255) not null default '',
apply_markup int(1) default '0',
author varchar(20) default null,
authorid int(11) default null,
last_modified int(10) {UNSIGNED} default null,
timestamp int(10) {UNSIGNED} default null) {UTF_8}";
serendipity_db_schema_import($q);
$this->set_config('db_built', '1');
}
}
function showForm($type = 'template') {
global $serendipity;
if (!function_exists('serendipity_emit_htmlarea_code')) {
include_once S9Y_INCLUDE_PATH . 'include/functions_entries_admin.inc.php';
}
if ($serendipity['version'][0] < 2) {
include 'oldform.inc.php';
} else {
include 'form.inc.php';
}
}
// This function checks the values of a staticblock entry, and maybe adjusts the right values to use.
function checkBlock() {
global $serendipity;
if (empty($this->staticblock['template'])) {
$this->staticblock['template'] = 'plugin_staticblock.tpl';
}
if (empty($this->staticblock['timestamp'])) {
$this->staticblock['timestamp'] = time();
}
if (empty($this->staticblock['last_modified'])) {
$this->staticblock['last_modified'] = time();
}
if (empty($this->staticblock['authorid'])) {
$this->staticblock['authorid'] = $serendipity['authorid'];
}
if (empty($this->staticblock['author'])) {
$this->staticblock['author'] = $serendipity['serendipityUser'];
}
if (empty($this->staticblock['type'])) {
if (isset($serendipity['POST']['type'])) {
$this->staticblock['type'] = $serendipity['POST']['type'];
} else {
$this->staticblock['type'] = 'template';
}
}
}
function fetchStaticBlock($id, $order = '') {
global $serendipity;
$q = "SELECT *
FROM {$serendipity['dbPrefix']}staticblocks
WHERE id = " . (int)$id . "
LIMIT 1";
$block = serendipity_db_query($q, true, 'assoc');
if (is_array($block)) {
$this->staticblock =& $block;
$this->checkBlock();
}
}
function updateStaticBlock() {
global $serendipity;
$this->checkBlock();
if (empty($this->staticblock['apply_markup'])) {
$this->staticblock['apply_markup'] = '0';
}
if (!isset($this->staticblock['id'])) {
$result = serendipity_db_insert('staticblocks', $this->staticblock);
if (is_string($result)) {
if ($serendipity['version'][0] < 2) {
echo '