17 defined(
'XOOPS_ROOT_PATH') or die('Restricted access');
19 require_once XOOPS_ROOT_PATH . '/kernel/block.php';
29 function __construct()
31 parent::__construct();
34 function getForm($mode=
'edit')
39 $groups = array( XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS, XOOPS_GROUP_ADMIN );
40 $this->setVar(
'block_type',
'C');
41 $this->setVar(
'visible',1);
47 $blocklinkmodule = $blocklinkmodule_handler->getObjects(
$criteria);
48 foreach ($blocklinkmodule as $link) {
49 $modules[] = $link->getVar(
'module_id');
53 $groups =& $groupperm_handler->getGroupIds(
'block_read', $this->getVar(
'bid'));
60 $this->setVar(
'bid', 0);
61 if ( $this->isCustom() ) {
62 $this->setVar(
'block_type',
'C');
64 $this->setVar(
'block_type',
'D');
71 if (!$this->isNew()) {
76 $side_select->addOptionArray(array(
85 $form->addElement($side_select);
99 $mod_select->addOptionArray($module_list);
100 $form->addElement($mod_select);
103 if ($this->isNew() || $this->isCustom()) {
104 $editor_configs=array();
105 $editor_configs[
"name"] =
"content_block";
106 $editor_configs[
"value"] = $this->getVar(
'content',
'e');
107 $editor_configs[
"rows"] = 20;
108 $editor_configs[
"cols"] = 100;
109 $editor_configs[
"width"] =
"100%";
110 $editor_configs[
"height"] =
"400px";
113 if ( in_array( $editor_configs[
"editor"], array(
'dhtmltextarea',
'textarea' ) ) ) {
115 $ctype_select->addOptionArray(array(
120 $form->addElement($ctype_select);
125 if ($this->getVar(
'template') !=
'') {
127 $btemplate = $tplfile_handler->find(
$GLOBALS[
'xoopsConfig'][
'template_set'],
'block', $this->getVar(
'bid') );
128 if (count($btemplate) > 0) {
131 $btemplate2 = $tplfile_handler->find(
'default',
'block', $this->getVar(
'bid'));
132 if (count($btemplate2) > 0) {
137 if ( $this->getOptions() !=
false ) {
145 $cache_select->addOptionArray(array(
152 '18000' => sprintf(
_HOURS, 5),
154 '259200' => sprintf(
_DAYS, 3),
157 $form->addElement($cache_select);
174 if ($this->isNew() || $this->isCustom()) {
176 $preview->setExtra(
"onclick=\"blocks_preview();\"");
190 function getOptions()
193 if (!$this->isCustom()) {
194 $edit_func = $this->getVar(
'edit_func');
198 if (file_exists(
$GLOBALS[
'xoops']->path(
'modules/' . $this->getVar(
'dirname') .
'/blocks/' . $this->getVar(
'func_file')))) {
199 if (file_exists(
$file =
$GLOBALS[
'xoops']->path(
'modules/' . $this->getVar(
'dirname') .
'/language/' . $xoopsConfig[
'language'] .
'/blocks.php'))) {
201 } elseif (file_exists(
$file =
$GLOBALS[
'xoops']->path(
'modules/' . $this->getVar(
'dirname') .
'/language/english/blocks.php'))) {
204 include_once
$GLOBALS[
'xoops']->path(
'modules/' . $this->getVar(
'dirname') .
'/blocks/' . $this->getVar(
'func_file'));
205 $options = explode(
"|", $this->getVar(
"options"));
221 if ($this->getVar(
'block_type') ==
'C')
return true;
232 function getContent($format =
's', $c_type =
'T')
234 $format = strtolower($format);
235 $c_type = strtoupper($c_type);
243 if ($c_type ==
'H') {
244 return str_replace(
'{X_SITEURL}', XOOPS_URL .
'/', $this->getVar(
'content',
'n'));
245 }
else if ($c_type ==
'P') {
247 echo eval($this->getVar(
'content',
'n'));
250 return str_replace(
'{X_SITEURL}', XOOPS_URL .
'/',
$content);
251 }
else if ($c_type ==
'S') {
253 $content = str_replace(
'{X_SITEURL}', XOOPS_URL .
'/', $this->getVar(
'content',
'n'));
257 $content = str_replace(
'{X_SITEURL}', XOOPS_URL .
'/', $this->getVar(
'content',
'n'));
262 return $this->getVar(
'content',
'e');
265 return $this->getVar(
'content',
'n');
285 parent::__construct(
$db,
'newblocks',
'SystemBlock',
'bid',
'title');
290 $obj->setVar(
'last_modified', time());
291 return parent::insert($obj);
305 $sql =
'SELECT DISTINCT(b.bid), b.* FROM ' . $this->db->prefix(
'newblocks') .
' b LEFT JOIN ' . $this->db->prefix(
'block_module_link') .
' l ON b.bid=l.block_id';
316 while ($myrow = $this->db->fetchArray(
$result)) {
318 $block->assignVars($myrow);
322 $ret[$myrow[
'bid']] = & $block;
345 function getAllBlocksByGroup($groupid, $asobject =
true, $side = null, $visible = null, $orderby =
"b.weight,b.bid", $isactive = 1)
350 $sql =
'SELECT b.bid ';
352 $sql =
'SELECT b.* ';
354 $sql .=
"FROM " .
$db->prefix(
"newblocks") .
" b LEFT JOIN " .
$db->prefix(
"group_permission") .
" l ON l.gperm_itemid=b.bid WHERE gperm_name = 'block_read' AND gperm_modid = 1";
355 if (is_array($groupid)) {
356 $sql .=
" AND (l.gperm_groupid=" . $groupid[0] .
"";
357 $size = count($groupid);
359 for(
$i = 1;
$i < $size;
$i ++) {
360 $sql .=
" OR l.gperm_groupid=" . $groupid[
$i] .
"";
365 $sql .=
" AND l.gperm_groupid=" . $groupid .
"";
367 $sql .=
" AND b.isactive=" . $isactive;
371 $side =
"(b.side=0 OR b.side=1)";
373 $side =
"(b.side=3 OR b.side=4 OR b.side=5 OR b.side=7 OR b.side=8 OR b.side=9 )";
375 $side =
"b.side=" . $side;
377 $sql .=
" AND " . $side;
379 if (isset($visible)) {
380 $sql .=
" AND b.visible=$visible";
382 $sql .=
" ORDER BY $orderby";
386 if (!in_array($myrow[
'bid'], $added)) {
388 $ret[] = $myrow[
'bid'];
392 array_push($added, $myrow[
'bid']);
401 if (isset($groupid)) {
402 $sql =
"SELECT DISTINCT gperm_itemid FROM " . $this->db->prefix(
'group_permission') .
" WHERE gperm_name = 'block_read' AND gperm_modid = 1";
403 if ( is_array($groupid) ) {
404 $sql .=
' AND gperm_groupid IN (' . implode(
',', $groupid) .
')';
406 if (intval($groupid) > 0) {
407 $sql .=
' AND gperm_groupid=' . intval($groupid);
412 while ( $myrow = $this->db->fetchArray(
$result ) ) {
413 $blockids[] = $myrow[
'gperm_itemid'];
415 if (empty($blockids)) {
424 $isactive = intval($isactive);
427 if (isset($groupid)) {
428 $sql =
"SELECT DISTINCT gperm_itemid FROM ".$db->prefix(
'group_permission').
" WHERE gperm_name = 'block_read' AND gperm_modid = 1";
429 if ( is_array($groupid) ) {
430 $sql .=
' AND gperm_groupid IN ('.implode(
',', $groupid).
')';
432 if (intval($groupid) > 0) {
433 $sql .=
' AND gperm_groupid='.intval($groupid);
439 $blockids[] = $myrow[
'gperm_itemid'];
441 if (empty($blockids)) {
445 $sql =
'SELECT b.* FROM '.$db->prefix(
'newblocks').
' b, '.
$db->prefix(
'block_module_link').
' m WHERE m.block_id=b.bid';
446 $sql .=
' AND b.isactive='.$isactive;
447 if (isset($visible)) {
448 $sql .=
' AND b.visible='.intval($visible);
459 $sql .=
' AND m.module_id IN (0,-1)';
461 $sql .=
' AND m.module_id=0';
464 if (!empty($blockids)) {
465 $sql .=
' AND b.bid IN ('.implode(
',', $blockids).
')';
467 $sql .=
' ORDER BY '.$orderby;
471 $ret[$myrow[
'bid']] =& $block;
482 $sql =
"SELECT DISTINCT(bid) from ".$db->prefix(
'newblocks');
485 $bids[] = $myrow[
'bid'];
488 $sql =
"SELECT DISTINCT(p.gperm_itemid) from ".$db->prefix(
'group_permission').
" p, ".
$db->prefix(
'groups').
" g WHERE g.groupid=p.gperm_groupid AND p.gperm_name='block_read'";
492 $grouped[] = $myrow[
'gperm_itemid'];
495 $non_grouped = array_diff($bids, $grouped);
496 if (!empty($non_grouped)) {
497 $sql =
'SELECT b.* FROM '.$db->prefix(
'newblocks').
' b, '.
$db->prefix(
'block_module_link').
' m WHERE m.block_id=b.bid';
498 $sql .=
' AND b.isactive='.intval($isactive);
499 if (isset($visible)) {
500 $sql .=
' AND b.visible='.intval($visible);
511 $sql .=
' AND m.module_id IN (0,-1)';
513 $sql .=
' AND m.module_id=0';
516 $sql .=
' AND b.bid IN ('.implode(
',', $non_grouped).
')';
517 $sql .=
' ORDER BY '.$orderby;
521 $ret[$myrow[
'bid']] =& $block;
538 $funcNum = intval($funcNum);
539 $moduleId = intval($moduleId);
540 if ($funcNum < 1 || $moduleId < 1) {
545 if (isset($showFunc)) {
547 $sql = sprintf(
"SELECT COUNT(*) FROM %s WHERE mid = %d AND func_num = %d AND show_func = %s",
$db->prefix(
'newblocks'), $moduleId, $funcNum,
$db->quoteString(trim($showFunc)));
549 $sql = sprintf(
"SELECT COUNT(*) FROM %s WHERE mid = %d AND func_num = %d",
$db->prefix(
'newblocks'), $moduleId, $funcNum);