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