XOOPS  2.6.0
block.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
15 
27 {
31  private $obj = null;
32 
38  public function __construct(XoopsBlock $obj)
39  {
40  $this->obj = $obj;
41  }
42 
50  public function getForm($mode = 'edit')
51  {
53  $xoops->loadLanguage('blocks', 'system');
54  if ($this->obj->isNew()) {
56  $modules = array(-1);
57  $groups = array(FixedGroups::USERS, FixedGroups::ANONYMOUS, FixedGroups::ADMIN);
58  $this->obj->setVar('block_type', 'C');
59  $this->obj->setVar('visible', 1);
60  $op = 'save';
61  } else {
62  $title = '';
63  $modules = array();
64  // Search modules
65  $blockmodulelink_handler = $xoops->getHandlerBlockmodulelink();
66  $criteria = new CriteriaCompo(new Criteria('block_id', $this->obj->getVar('bid')));
67  $blockmodulelink = $blockmodulelink_handler->getObjects($criteria);
68  /* @var $link XoopsBlockmodulelink */
69  foreach ($blockmodulelink as $link) {
70  $modules[] = $link->getVar('module_id');
71  }
72  // Search perms
73  $groupperm_handler = $xoops->getHandlerGroupperm();
74  $groups = $groupperm_handler->getGroupIds('block_read', $this->obj->getVar('bid'));
75  switch ($mode) {
76  case 'edit':
78  break;
79  case 'clone':
81  $this->obj->setVar('bid', 0);
82  if ($this->obj->isCustom()) {
83  $this->obj->setVar('block_type', 'C');
84  } else {
85  $this->obj->setVar('block_type', 'D');
86  }
87  break;
88  }
89  $op = 'save';
90  }
91  parent::__construct($title, 'blockform', 'admin.php', 'post', true);
92  if (!$this->obj->isNew()) {
93  $this->addElement(new Xoops\Form\Label(XoopsLocale::NAME, $this->obj->getVar('name')));
94  }
95  // Side position
96  $side_select = new Xoops\Form\Select(XoopsLocale::SIDE, 'side', $this->obj->getVar('side'));
97  $side_select->addOptionArray(array(
98  0 => XoopsLocale::LEFT,
99  1 => XoopsLocale::RIGHT,
106  ));
107  $this->addElement($side_select);
108  // Order
109  $weight = new Xoops\Form\Text(XoopsLocale::WEIGHT, 'weight', 1, 5, $this->obj->getVar('weight'), '');
111  $this->addElement($weight, true);
112  // Display
113  $this->addElement(new Xoops\Form\RadioYesNo(XoopsLocale::VISIBLE, 'visible', $this->obj->getVar('visible')));
114  // Visible In
115  $mod_select = new Xoops\Form\Select(XoopsLocale::VISIBLE_IN, 'modules', $modules, 5, true);
116  $criteria = new CriteriaCompo(new Criteria('hasmain', 1));
117  $criteria->add(new Criteria('isactive', 1));
118  $module_list = $xoops->getHandlerModule()->getNameList($criteria);
119  $module_list[-1] = XoopsLocale::TOP_PAGE;
120  $module_list[0] = XoopsLocale::ALL_PAGES;
121  ksort($module_list);
122  $mod_select->addOptionArray($module_list);
123  $this->addElement($mod_select);
124  // Title
125  $this->addElement(new Xoops\Form\Text(XoopsLocale::TITLE, 'title', 5, 255, $this->obj->getVar('title')), false);
126  if ($this->obj->isNew() || $this->obj->isCustom()) {
127  $editor_configs = array();
128  $editor_configs["name"] = "content_block";
129  $editor_configs["value"] = $this->obj->getVar('content', 'e');
130  $editor_configs["rows"] = 15;
131  $editor_configs["cols"] = 6;
132  $editor_configs["editor"] = $xoops->getModuleConfig('blocks_editor', 'system');
133  $this->addElement(new Xoops\Form\Editor(XoopsLocale::CONTENT, "content_block", $editor_configs), true);
134  if (in_array($editor_configs["editor"], array('dhtmltextarea', 'textarea'))) {
135  $ctype_select = new Xoops\Form\Select(SystemLocale::CONTENT_TYPE, 'c_type', $this->obj->getVar('c_type'));
136  $ctype_select->addOptionArray(array(
137  'H' => XoopsLocale::HTML,
141  ));
142  $this->addElement($ctype_select);
143  } else {
144  $this->addElement(new Xoops\Form\Hidden('c_type', 'H'));
145  }
146  } else {
147  if ($this->obj->getVar('template') != '') {
148  $tplfile_handler = $xoops->getHandlerTplfile();
149  $btemplate = $tplfile_handler->
150  find($xoops->getConfig('template_set'), 'block', $this->obj->getVar('bid'));
151  if (count($btemplate) > 0) {
152  $this->addElement(new Xoops\Form\Label(
154  '<a href="' . \XoopsBaseConfig::get('url') . '/modules/system/admin.php?fct=tplsets&amp;op=edittpl&amp;id='
155  . $btemplate[0]->getVar('tpl_id') . '">' . SystemLocale::EDIT_TEMPLATE . '</a>'
156  ));
157  } else {
158  $btemplate2 = $tplfile_handler->find('default', 'block', $this->obj->getVar('bid'));
159  if (count($btemplate2) > 0) {
160  $this->addElement(new Xoops\Form\Label(
162  '<a href="' . \XoopsBaseConfig::get('url') . '/modules/system/admin.php?fct=tplsets&amp;op=edittpl&amp;id='
163  . $btemplate2[0]->getVar('tpl_id') . '" rel="external">'
164  . SystemLocale::EDIT_TEMPLATE . '</a>'
165  ));
166  }
167  }
168  }
169  if ($this->obj->getOptions() != false) {
170  $this->addElement(new Xoops\Form\Label(XoopsLocale::OPTIONS, $this->obj->getOptions()));
171  } else {
172  $this->addElement(new Xoops\Form\Hidden('options', $this->obj->getVar('options')));
173  }
174  $this->addElement(new Xoops\Form\Hidden('c_type', 'H'));
175  }
176  $cache_select = new Xoops\Form\Select(
178  'bcachetime',
179  $this->obj->getVar('bcachetime')
180  );
181  $cache_select->addOptionArray(array(
182  '0' => XoopsLocale::NO_CACHE,
183  '30' => sprintf(XoopsLocale::F_SECONDS, 30),
184  '60' => XoopsLocale::ONE_MINUTE,
185  '300' => sprintf(XoopsLocale::F_MINUTES, 5),
186  '1800' => sprintf(XoopsLocale::F_MINUTES, 30),
187  '3600' => XoopsLocale::ONE_HOUR,
188  '18000' => sprintf(XoopsLocale::F_HOURS, 5),
189  '86400' => XoopsLocale::ONE_DAY,
190  '259200' => sprintf(XoopsLocale::F_DAYS, 3),
191  '604800' => XoopsLocale::ONE_WEEK,
192  '2592000' => XoopsLocale::ONE_MONTH
193  ));
194  $this->addElement($cache_select);
195  // Groups
196  $this->addElement(new Xoops\Form\SelectGroup(XoopsLocale::GROUPS, 'groups', true, $groups, 5, true));
197 
198  $this->addElement(new Xoops\Form\Hidden('block_type', $this->obj->getVar('block_type')));
199  $this->addElement(new Xoops\Form\Hidden('mid', $this->obj->getVar('mid')));
200  $this->addElement(new Xoops\Form\Hidden('func_num', $this->obj->getVar('func_num')));
201  $this->addElement(new Xoops\Form\Hidden('func_file', $this->obj->getVar('func_file')));
202  $this->addElement(new Xoops\Form\Hidden('show_func', $this->obj->getVar('show_func')));
203  $this->addElement(new Xoops\Form\Hidden('edit_func', $this->obj->getVar('edit_func')));
204  $this->addElement(new Xoops\Form\Hidden('template', $this->obj->getVar('template')));
205  $this->addElement(new Xoops\Form\Hidden('dirname', $this->obj->getVar('dirname')));
206  $this->addElement(new Xoops\Form\Hidden('name', $this->obj->getVar('name')));
207  $this->addElement(new Xoops\Form\Hidden('bid', $this->obj->getVar('bid')));
208  $this->addElement(new Xoops\Form\Hidden('op', $op));
209  $this->addElement(new Xoops\Form\Hidden('fct', 'blocksadmin'));
210  $button_tray = new Xoops\Form\ElementTray('', '&nbsp;');
211  if ($this->obj->isNew() || $this->obj->isCustom()) {
212  $preview = new Xoops\Form\Button('', 'previewblock', XoopsLocale::A_PREVIEW, 'preview');
213  $preview->setExtra("onclick=\"blocks_preview();\"");
214  $button_tray->addElement($preview);
215  }
216  $button_tray->addElement(new Xoops\Form\Button('', 'submitblock', XoopsLocale::A_SUBMIT, 'submit'));
217  $this->addElement($button_tray);
218  }
219 }
const ONE_MINUTE
Definition: en_US.php:880
const ONE_DAY
Definition: en_US.php:878
const VISIBLE_IN
Definition: en_US.php:1090
const A_SUBMIT
Definition: en_US.php:128
const E_YOU_NEED_A_POSITIVE_INTEGER
Definition: en_US.php:385
const TOP_PAGE
Definition: en_US.php:1061
__construct(XoopsBlock $obj)
Definition: block.php:38
const F_SECONDS
Definition: en_US.php:437
const OPTIONS
Definition: en_US.php:888
static getInstance()
Definition: Xoops.php:160
$weight
Definition: admin_menu.php:38
addElement(Element $formElement, $required=false)
Definition: Form.php:206
const CACHE_LIFETIME
Definition: en_US.php:67
$link
Definition: userinfo.php:84
const PHP_SCRIPT
Definition: en_US.php:358
const ONE_WEEK
Definition: en_US.php:883
const ONE_MONTH
Definition: en_US.php:881
const CONTENT
Definition: en_US.php:176
const CONTENT_TYPE
Definition: en_US.php:246
addOptionArray($options)
Definition: Select.php:129
const ALL_PAGES
Definition: en_US.php:64
$xoops
Definition: admin.php:25
const F_DAYS
Definition: en_US.php:405
const BOTTOM_LEFT
Definition: en_US.php:65
const TOP_RIGHT
Definition: en_US.php:404
const TOP_LEFT
Definition: en_US.php:403
const BOTTOM_CENTER
Definition: en_US.php:64
static get($name)
const F_MINUTES
Definition: en_US.php:426
const A_PREVIEW
Definition: en_US.php:109
const ONE_HOUR
Definition: en_US.php:879
const AUTO_FORMAT_SMILIES_DISABLED
Definition: en_US.php:38
$groups
$modules
Definition: userinfo.php:185
const AUTO_FORMAT_SMILIES_ENABLED
Definition: en_US.php:39
$button_tray
Definition: xoops_code.php:26
$criteria
const EDIT_BLOCK
Definition: en_US.php:264
const ADD_BLOCK
Definition: en_US.php:29
getForm($mode= 'edit')
Definition: block.php:50
const GROUPS
Definition: en_US.php:456
const CLONE_BLOCK
Definition: en_US.php:70
const TOP_CENTER
Definition: en_US.php:402
const EDIT_TEMPLATE
Definition: en_US.php:267
$op
const F_HOURS
Definition: en_US.php:413
const NO_CACHE
Definition: en_US.php:862
const BOTTOM_RIGHT
Definition: en_US.php:66