1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: use Xoops\Core\Kernel\Criteria;
13: use Xoops\Core\Kernel\CriteriaCompo;
14: use Xoops\Core\Kernel\Handlers\XoopsBlock;
15: use Xoops\Core\FixedGroups;
16:
17: 18: 19: 20: 21: 22: 23: 24: 25: 26:
27: class SystemBlockForm extends Xoops\Form\ThemeForm
28: {
29: 30: 31:
32: private $obj = null;
33:
34: 35: 36: 37: 38:
39: public function __construct(XoopsBlock $obj)
40: {
41: $this->obj = $obj;
42: }
43:
44: 45: 46: 47: 48: 49: 50:
51: public function getForm($mode = 'edit')
52: {
53: $xoops = Xoops::getInstance();
54: $xoops->loadLanguage('blocks', 'system');
55: if ($this->obj->isNew()) {
56: $title = SystemLocale::ADD_BLOCK;
57: $modules = array(-1);
58: $groups = array(FixedGroups::USERS, FixedGroups::ANONYMOUS, FixedGroups::ADMIN);
59: $this->obj->setVar('block_type', XoopsBlock::BLOCK_TYPE_CUSTOM);
60: $this->obj->setVar('visible', 1);
61: $op = 'save';
62: } else {
63: $title = '';
64: $modules = array();
65:
66: $blockmodulelink_handler = $xoops->getHandlerBlockModuleLink();
67: $criteria = new CriteriaCompo(new Criteria('block_id', $this->obj->getVar('bid')));
68: $blockmodulelink = $blockmodulelink_handler->getObjects($criteria);
69:
70: foreach ($blockmodulelink as $link) {
71: $modules[] = $link->getVar('module_id');
72: }
73:
74: $groupperm_handler = $xoops->getHandlerGroupPermission();
75: $groups = $groupperm_handler->getGroupIds('block_read', $this->obj->getVar('bid'));
76: switch ($mode) {
77: case 'edit':
78: $title = SystemLocale::EDIT_BLOCK;
79: break;
80: case 'clone':
81: $title = SystemLocale::CLONE_BLOCK;
82: $this->obj->setVar('bid', 0);
83: if ($this->obj->isCustom()) {
84: $this->obj->setVar('block_type', XoopsBlock::BLOCK_TYPE_CUSTOM);
85: } else {
86: $this->obj->setVar('block_type', XoopsBlock::BLOCK_TYPE_CLONED);
87: }
88: break;
89: }
90: $op = 'save';
91: }
92: parent::__construct($title, 'blockform', 'admin.php', 'post', true);
93: if (!$this->obj->isNew()) {
94: $this->addElement(new Xoops\Form\Label(XoopsLocale::NAME, $this->obj->getVar('name')));
95: }
96:
97: $side_select = new Xoops\Form\Select(XoopsLocale::SIDE, 'side', $this->obj->getVar('side'));
98: $side_select->addOptionArray(array(
99: 0 => XoopsLocale::LEFT,
100: 1 => XoopsLocale::RIGHT,
101: 3 => SystemLocale::TOP_LEFT,
102: 4 => SystemLocale::TOP_RIGHT,
103: 5 => SystemLocale::TOP_CENTER,
104: 7 => SystemLocale::BOTTOM_LEFT,
105: 8 => SystemLocale::BOTTOM_RIGHT,
106: 9 => SystemLocale::BOTTOM_CENTER
107: ));
108: $this->addElement($side_select);
109:
110: $weight = new Xoops\Form\Text(XoopsLocale::WEIGHT, 'weight', 1, 5, $this->obj->getVar('weight'), '');
111: $weight->setPattern('^\d+$', XoopsLocale::E_YOU_NEED_A_POSITIVE_INTEGER);
112: $this->addElement($weight, true);
113:
114: $this->addElement(new Xoops\Form\RadioYesNo(XoopsLocale::VISIBLE, 'visible', $this->obj->getVar('visible')));
115:
116: $mod_select = new Xoops\Form\Select(XoopsLocale::VISIBLE_IN, 'modules', $modules, 5, true);
117: $criteria = new CriteriaCompo(new Criteria('hasmain', 1));
118: $criteria->add(new Criteria('isactive', 1));
119: $module_list = $xoops->getHandlerModule()->getNameList($criteria);
120: $module_list[-1] = XoopsLocale::TOP_PAGE;
121: $module_list[0] = XoopsLocale::ALL_PAGES;
122: ksort($module_list);
123: $mod_select->addOptionArray($module_list);
124: $this->addElement($mod_select);
125:
126: $this->addElement(new Xoops\Form\Text(XoopsLocale::TITLE, 'title', 5, 255, $this->obj->getVar('title')), false);
127: if ($this->obj->isNew() || $this->obj->isCustom()) {
128: $editor_configs = array();
129: $editor_configs["name"] = "content_block";
130: $editor_configs["value"] = $this->obj->getVar('content', 'e');
131: $editor_configs["rows"] = 15;
132: $editor_configs["cols"] = 6;
133: $editor_configs["editor"] = $xoops->getModuleConfig('blocks_editor', 'system');
134: $this->addElement(new Xoops\Form\Editor(XoopsLocale::CONTENT, "content_block", $editor_configs), true);
135: if (in_array($editor_configs["editor"], array('dhtmltextarea', 'textarea'))) {
136: $ctype_select = new Xoops\Form\Select(SystemLocale::CONTENT_TYPE, 'c_type', $this->obj->getVar('c_type'));
137: $ctype_select->addOptionArray(array(
138: XoopsBlock::CUSTOM_HTML => XoopsLocale::HTML,
139: XoopsBlock::CUSTOM_PHP => SystemLocale::PHP_SCRIPT,
140: XoopsBlock::CUSTOM_SMILIE => SystemLocale::AUTO_FORMAT_SMILIES_ENABLED,
141: XoopsBlock::CUSTOM_TEXT => SystemLocale::AUTO_FORMAT_SMILIES_DISABLED
142: ));
143: $this->addElement($ctype_select);
144: } else {
145: $this->addElement(new Xoops\Form\Hidden('c_type', XoopsBlock::CUSTOM_HTML));
146: }
147: } else {
148: if ($this->obj->getVar('template') != '') {
149: $tplfile_handler = $xoops->getHandlerTplFile();
150: $btemplate = $tplfile_handler->
151: find($xoops->getConfig('template_set'), 'block', $this->obj->getVar('bid'));
152: if (count($btemplate) > 0) {
153: $this->addElement(new Xoops\Form\Label(
154: XoopsLocale::CONTENT,
155: '<a href="' . \XoopsBaseConfig::get('url') . '/modules/system/admin.php?fct=tplsets&op=edittpl&id='
156: . $btemplate[0]->getVar('tpl_id') . '">' . SystemLocale::EDIT_TEMPLATE . '</a>'
157: ));
158: } else {
159: $btemplate2 = $tplfile_handler->find('default', 'block', $this->obj->getVar('bid'));
160: if (count($btemplate2) > 0) {
161: $this->addElement(new Xoops\Form\Label(
162: XoopsLocale::CONTENT,
163: '<a href="' . \XoopsBaseConfig::get('url') . '/modules/system/admin.php?fct=tplsets&op=edittpl&id='
164: . $btemplate2[0]->getVar('tpl_id') . '" rel="external">'
165: . SystemLocale::EDIT_TEMPLATE . '</a>'
166: ));
167: }
168: }
169: }
170: if ($this->obj->getOptions() != false) {
171: $this->addElement(new Xoops\Form\Label(XoopsLocale::OPTIONS, $this->obj->getOptions()));
172: } else {
173: $this->addElement(new Xoops\Form\Hidden('options', $this->obj->getVar('options')));
174: }
175: $this->addElement(new Xoops\Form\Hidden('c_type', XoopsBlock::CUSTOM_HTML));
176: }
177: $cache_select = new Xoops\Form\Select(
178: SystemLocale::CACHE_LIFETIME,
179: 'bcachetime',
180: $this->obj->getVar('bcachetime')
181: );
182: $cache_select->addOptionArray(array(
183: '0' => XoopsLocale::NO_CACHE,
184: '30' => sprintf(XoopsLocale::F_SECONDS, 30),
185: '60' => XoopsLocale::ONE_MINUTE,
186: '300' => sprintf(XoopsLocale::F_MINUTES, 5),
187: '1800' => sprintf(XoopsLocale::F_MINUTES, 30),
188: '3600' => XoopsLocale::ONE_HOUR,
189: '18000' => sprintf(XoopsLocale::F_HOURS, 5),
190: '86400' => XoopsLocale::ONE_DAY,
191: '259200' => sprintf(XoopsLocale::F_DAYS, 3),
192: '604800' => XoopsLocale::ONE_WEEK,
193: '2592000' => XoopsLocale::ONE_MONTH
194: ));
195: $this->addElement($cache_select);
196:
197: $this->addElement(new Xoops\Form\SelectGroup(XoopsLocale::GROUPS, 'groups', true, $groups, 5, true));
198:
199: $this->addElement(new Xoops\Form\Hidden('block_type', $this->obj->getVar('block_type')));
200: $this->addElement(new Xoops\Form\Hidden('mid', $this->obj->getVar('mid')));
201: $this->addElement(new Xoops\Form\Hidden('func_num', $this->obj->getVar('func_num')));
202: $this->addElement(new Xoops\Form\Hidden('func_file', $this->obj->getVar('func_file')));
203: $this->addElement(new Xoops\Form\Hidden('show_func', $this->obj->getVar('show_func')));
204: $this->addElement(new Xoops\Form\Hidden('edit_func', $this->obj->getVar('edit_func')));
205: $this->addElement(new Xoops\Form\Hidden('template', $this->obj->getVar('template')));
206: $this->addElement(new Xoops\Form\Hidden('dirname', $this->obj->getVar('dirname')));
207: $this->addElement(new Xoops\Form\Hidden('name', $this->obj->getVar('name')));
208: $this->addElement(new Xoops\Form\Hidden('bid', $this->obj->getVar('bid')));
209: $this->addElement(new Xoops\Form\Hidden('op', $op));
210: $this->addElement(new Xoops\Form\Hidden('fct', 'blocksadmin'));
211: $buttonTray = new Xoops\Form\ElementTray('', ' ');
212: if ($this->obj->isNew() || $this->obj->isCustom()) {
213: $preview = new Xoops\Form\Button('', 'previewblock', XoopsLocale::A_PREVIEW, 'preview');
214: $preview->setExtra("onclick=\"blocks_preview();\"");
215: $buttonTray->addElement($preview);
216: }
217: $buttonTray->addElement(new Xoops\Form\Button('', 'submitblock', XoopsLocale::A_SUBMIT, 'submit'));
218: $this->addElement($buttonTray);
219: }
220: }
221: