1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94:
<?php
$plugin_is_filter = 500 | ADMIN_PLUGIN | THEME_PLUGIN;
$plugin_description = gettext('Create default codeblocks.');
$plugin_author = "Stephen Billard (sbillard)";
$plugin_category = gettext('Misc');
$option_interface = 'defaultCodeblocks';
zp_register_filter('codeblock', 'defaultCodeblocks_codebox');
class defaultCodeblocks {
var $codeblocks;
function __construct() {
$blocks = query_single_row("SELECT id, `aux`, `data` FROM " . prefix('plugin_storage') . " WHERE `type` = 'defaultCodeblocks'");
if ($blocks) {
$this->codeblocks = $blocks['data'];
} else {
$this->codeblocks = serialize(array());
$sql = 'INSERT INTO ' . prefix('plugin_storage') . ' (`type`,`aux`,`data`) VALUES ("defaultCodeblocks","",' . db_quote($this->codeblocks) . ')';
query($sql);
}
}
function getOptionsSupported() {
$list = array(gettext('Gallery') => 'defaultCodeblocks_object_gallery', gettext('Album') => 'defaultCodeblocks_object_albums', gettext('Image') => 'defaultCodeblocks_object_images');
if (extensionEnabled('zenpage')) {
$list = array_merge($list, array(gettext('News category') => 'defaultCodeblocks_object_news_categories', gettext('News') => 'defaultCodeblocks_object_news', gettext('Page') => 'defaultCodeblocks_object_pages'));
}
$options = array(gettext('Objects') => array('key' => 'defaultCodeblocks_objects', 'type' => OPTION_TYPE_CHECKBOX_UL,
'order' => 0,
'checkboxes' => $list,
'desc' => gettext('Default codeblocks will be applied for the checked objects.')),
gettext('Codeblocks') => array('key' => 'defaultCodeblocks_blocks', 'type' => OPTION_TYPE_CUSTOM,
'order' => 2,
'desc' => gettext('Codeblocks to be inserted when the one for the object is empty.'))
);
return $options;
}
function handleOption($option, $currentValue) {
codeblocktabsJS();
printCodeblockEdit($this, 0);
}
function handleOptionSave($themename, $themealbum) {
if (zp_loggedin(CODEBLOCK_RIGHTS)) {
$this->setCodeblock(processCodeblockSave(0));
}
return false;
}
function getCodeblock() {
return unTagURLs($this->codeblocks);
}
function setCodeblock($cb) {
$this->codeblocks = tagURLs($cb);
$sql = 'UPDATE ' . prefix('plugin_storage') . ' SET `data`=' . db_quote($this->codeblocks) . ' WHERE `type`="defaultCodeblocks"';
query($sql);
}
}
function defaultCodeblocks_codebox($current, $object, $number) {
if (empty($current) && getOption('defaultCodeblocks_object_' . $object->table)) {
$defaultCodeBlocks = new defaultCodeblocks();
$blocks = getSerializedArray($defaultCodeBlocks->getCodeblock());
if (isset($blocks[$number])) {
$current = $blocks[$number];
}
}
return $current;
}
?>