22 defined(
'XOOPS_ROOT_PATH') or die('Restricted access');
24 include_once
$GLOBALS['xoops']->path( 'kernel/
object.php' );
65 $this->assignVars($id);
67 $this->load(intval($id));
80 $sql =
'SELECT * FROM ' . $this->db->prefix(
'newblocks') .
' WHERE bid = ' . $id;
81 $arr = $this->db->fetchArray($this->db->query(
$sql));
82 $this->assignVars($arr);
92 if (!$this->cleanVars()) {
95 foreach ($this->cleanVars as $k => $v) {
99 $bid = $this->db->genId($this->db->prefix(
"newblocks") .
"_bid_seq");
100 $sql = sprintf(
"INSERT INTO %s (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type, c_type, isactive, dirname, func_file, show_func, edit_func, template, bcachetime, last_modified) VALUES (%u, %u, %u, %s, %s, %s, %s, %u, %u, %u, %s, %s, %u, %s, %s, %s, %s, %s, %u, %u)", $this->db->prefix(
'newblocks'), $bid,
$mid, $func_num, $this->db->quoteString(
$options), $this->db->quoteString($name), $this->db->quoteString(
$title), $this->db->quoteString(
$content), $side, $weight, $visible, $this->db->quoteString($block_type), $this->db->quoteString($c_type), 1, $this->db->quoteString(
$dirname), $this->db->quoteString($func_file), $this->db->quoteString($show_func), $this->db->quoteString($edit_func), $this->db->quoteString($template), $bcachetime, time());
102 $sql =
"UPDATE " . $this->db->prefix(
"newblocks") .
" SET options=" . $this->db->quoteString(
$options);
104 if ($this->isCustom() ) {
105 $sql .=
", name=" . $this->db->quoteString($name);
107 $sql .=
", isactive=" . $isactive .
", title=" . $this->db->quoteString(
$title) .
", content=" . $this->db->quoteString(
$content) .
", side=" . $side .
", weight=" . $weight .
", visible=" . $visible .
", c_type=" . $this->db->quoteString($c_type) .
", template=" . $this->db->quoteString($template) .
", bcachetime=" . $bcachetime .
", last_modified=" . time() .
" WHERE bid=" . $bid;
109 if (!$this->db->query(
$sql)) {
110 $this->setErrors(
"Could not save block data into database");
114 $bid = $this->db->getInsertId();
126 $sql = sprintf(
"DELETE FROM %s WHERE bid = %u", $this->db->prefix(
'newblocks'), $this->getVar(
'bid'));
127 if (! $this->db->query(
$sql)) {
130 $sql = sprintf(
"DELETE FROM %s WHERE gperm_name = 'block_read' AND gperm_itemid = %u AND gperm_modid = 1", $this->db->prefix(
'group_permission'), $this->getVar(
'bid'));
131 $this->db->query(
$sql);
132 $sql = sprintf(
"DELETE FROM %s WHERE block_id = %u", $this->db->prefix(
'block_module_link'), $this->getVar(
'bid'));
133 $this->db->query(
$sql);
144 function getContent($format =
's', $c_type =
't')
153 if ($c_type ==
'H') {
154 return str_replace(
'{X_SITEURL}', XOOPS_URL .
'/', $this->getVar(
'content',
'n'));
155 }
else if ($c_type ==
'P') {
157 echo eval($this->getVar(
'content',
'n'));
160 return str_replace(
'{X_SITEURL}', XOOPS_URL .
'/',
$content);
161 }
else if ($c_type ==
'S') {
163 $content = str_replace(
'{X_SITEURL}', XOOPS_URL .
'/', $this->getVar(
'content',
'n'));
167 $content = str_replace(
'{X_SITEURL}', XOOPS_URL .
'/', $this->getVar(
'content',
'n'));
172 return $this->getVar(
'content',
'e');
175 return $this->getVar(
'content',
'n');
185 function buildBlock()
189 if (!$this->isCustom()) {
191 $show_func = $this->getVar(
'show_func');
195 if (!file_exists($func_file =
$GLOBALS[
'xoops']->path(
'modules/' . $this->getVar(
'dirname') .
'/blocks/' . $this->getVar(
'func_file')))) {
201 include_once $func_file;
203 if (function_exists($show_func)) {
205 $options = explode(
'|', $this->getVar(
'options'));
215 $block[
'content'] = $this->getContent(
's', $this->getVar(
'c_type'));
216 if (empty($block[
'content'])) {
230 function buildContent($position,
$content =
"", $contentdb =
"")
232 if ($position == 0) {
234 }
else if ($position == 1) {
247 function buildTitle($originaltitle, $newtitle =
'')
249 if ($newtitle !=
'') {
252 $ret = $originaltitle;
264 return in_array($this->getVar(
'block_type'), array(
274 function getOptions()
277 if (!$this->isCustom()) {
278 $edit_func = $this->getVar(
'edit_func');
282 if (file_exists(
$GLOBALS[
'xoops']->path(
'modules/' . $this->getVar(
'dirname') .
'/blocks/' . $this->getVar(
'func_file')))) {
283 if (file_exists(
$file =
$GLOBALS[
'xoops']->path(
'modules/' . $this->getVar(
'dirname') .
'/language/' . $xoopsConfig[
'language'] .
'/blocks.php'))) {
285 } elseif (file_exists(
$file =
$GLOBALS[
'xoops']->path(
'modules/' . $this->getVar(
'dirname') .
'/language/english/blocks.php'))) {
288 include_once
$GLOBALS[
'xoops']->path(
'modules/' . $this->getVar(
'dirname') .
'/blocks/' . $this->getVar(
'func_file'));
289 $options = explode(
"|", $this->getVar(
"options"));
317 function getAllBlocksByGroup($groupid, $asobject =
true, $side = null, $visible = null, $orderby =
"b.weight,b.bid", $isactive = 1)
322 $sql =
'SELECT b.bid ';
324 $sql =
'SELECT b.* ';
326 $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";
327 if (is_array($groupid)) {
328 $sql .=
" AND (l.gperm_groupid=" . $groupid[0] .
"";
329 $size = count($groupid);
331 for(
$i = 1;
$i < $size;
$i ++) {
332 $sql .=
" OR l.gperm_groupid=" . $groupid[
$i] .
"";
337 $sql .=
" AND l.gperm_groupid=" . $groupid .
"";
339 $sql .=
" AND b.isactive=" . $isactive;
343 $side =
"(b.side=0 OR b.side=1)";
345 $side =
"(b.side=3 OR b.side=4 OR b.side=5 OR b.side=7 OR b.side=8 OR b.side=9 )";
347 $side =
"b.side=" . $side;
349 $sql .=
" AND " . $side;
351 if (isset($visible)) {
352 $sql .=
" AND b.visible=$visible";
354 $sql .=
" ORDER BY $orderby";
357 while ($myrow = $db->fetchArray(
$result)) {
358 if (!in_array($myrow[
'bid'], $added)) {
360 $ret[] = $myrow[
'bid'];
364 array_push($added, $myrow[
'bid']);
380 function getAllBlocks($rettype =
"object", $side = null, $visible = null, $orderby =
"side,weight,bid", $isactive = 1)
384 $where_query =
" WHERE isactive=" . $isactive;
388 $side =
"(side=0 OR side=1)";
389 } elseif ($side == 6) {
390 $side =
"(side=3 OR side=4 OR side=5 OR side=7 OR side=8 OR side=9)";
392 $side =
"side=" . $side;
394 $where_query .=
" AND " . $side;
396 if (isset($visible)) {
397 $where_query .=
" AND visible=.". $visible;
399 $where_query .=
" ORDER BY ".$orderby;
402 $sql =
"SELECT * FROM " . $db->prefix(
"newblocks") .
"" . $where_query;
404 while ($myrow = $db->fetchArray(
$result)) {
409 $sql =
"SELECT * FROM " . $db->prefix(
"newblocks") .
"" . $where_query;
411 while ($myrow = $db->fetchArray(
$result)) {
413 $title = $block->getVar(
"title");
419 $sql =
"SELECT bid FROM " . $db->prefix(
"newblocks") .
"" . $where_query;
421 while ($myrow = $db->fetchArray(
$result)) {
422 $ret[] = $myrow[
'bid'];
437 function getByModule($moduleid, $asobject =
true)
439 $moduleid = intval($moduleid);
441 if ($asobject ==
true) {
442 $sql =
$sql =
"SELECT * FROM " . $db->prefix(
"newblocks") .
" WHERE mid=" . $moduleid;
444 $sql =
"SELECT bid FROM " . $db->prefix(
"newblocks") .
" WHERE mid=" . $moduleid;
448 while ($myrow = $db->fetchArray(
$result)) {
452 $ret[] = $myrow[
'bid'];
469 function getAllByGroupModule($groupid,
$module_id = 0, $toponlyblock =
false, $visible = null, $orderby =
'b.weight, m.block_id', $isactive = 1)
471 $isactive = intval($isactive);
474 if (isset($groupid)) {
475 $sql =
"SELECT DISTINCT gperm_itemid FROM " . $db->prefix(
'group_permission') .
" WHERE gperm_name = 'block_read' AND gperm_modid = 1";
476 if (is_array($groupid)) {
477 $sql .=
' AND gperm_groupid IN (' . implode(
',', $groupid) .
')';
479 if (intval($groupid) > 0) {
480 $sql .=
' AND gperm_groupid=' . intval($groupid);
485 while ($myrow = $db->fetchArray(
$result)) {
486 $blockids[] = $myrow[
'gperm_itemid'];
488 if (empty($blockids)) {
492 $sql =
'SELECT b.* FROM ' . $db->prefix(
'newblocks') .
' b, ' . $db->prefix(
'block_module_link') .
' m WHERE m.block_id=b.bid';
493 $sql .=
' AND b.isactive=' . $isactive;
494 if (isset($visible)) {
495 $sql .=
' AND b.visible=' . intval($visible);
506 $sql .=
' AND m.module_id IN (0,-1)';
508 $sql .=
' AND m.module_id=0';
511 if (!empty($blockids)) {
512 $sql .=
' AND b.bid IN (' . implode(
',', $blockids) .
')';
514 $sql .=
' ORDER BY ' . $orderby;
516 while ($myrow = $db->fetchArray(
$result)) {
518 $ret[$myrow[
'bid']] = & $block;
534 function getNonGroupedBlocks(
$module_id = 0, $toponlyblock =
false, $visible = null, $orderby =
'b.weight, m.block_id', $isactive = 1)
539 $sql =
"SELECT DISTINCT(bid) from " . $db->prefix(
'newblocks');
541 while ($myrow = $db->fetchArray(
$result)) {
542 $bids[] = $myrow[
'bid'];
545 $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'";
548 while ($myrow = $db->fetchArray(
$result)) {
549 $grouped[] = $myrow[
'gperm_itemid'];
552 $non_grouped = array_diff($bids, $grouped);
553 if (!empty($non_grouped)) {
554 $sql =
'SELECT b.* FROM ' . $db->prefix(
'newblocks') .
' b, ' . $db->prefix(
'block_module_link') .
' m WHERE m.block_id=b.bid';
555 $sql .=
' AND b.isactive=' . intval($isactive);
556 if (isset($visible)) {
557 $sql .=
' AND b.visible=' . intval($visible);
568 $sql .=
' AND m.module_id IN (0,-1)';
570 $sql .=
' AND m.module_id=0';
573 $sql .=
' AND b.bid IN (' . implode(
',', $non_grouped) .
')';
574 $sql .=
' ORDER BY ' . $orderby;
576 while ($myrow = $db->fetchArray(
$result)) {
578 $ret[$myrow[
'bid']] =& $block;
593 function countSimilarBlocks($moduleId, $funcNum, $showFunc = null)
595 $funcNum = intval($funcNum);
596 $moduleId = intval($moduleId);
597 if ($funcNum < 1 || $moduleId < 1) {
602 if (isset($showFunc)) {
604 $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)));
606 $sql = sprintf(
"SELECT COUNT(*) FROM %s WHERE mid = %d AND func_num = %d", $db->prefix(
'newblocks'), $moduleId, $funcNum);
611 list ($count) = $db->fetchRow(
$result);