function clone_block($bid) { global $xoopsConfig; xoops_cp_header(); $myblock = new XoopsBlock($bid); $db =& Database::getInstance(); $sql = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . intval($bid); $result = $db->query($sql); $modules = array(); while ($row = $db->fetchArray($result)) { $modules[] = intval($row['module_id']); } $is_custom = $myblock->isCustom(); $groupperm_handler =& xoops_gethandler('groupperm'); $groups =& $groupperm_handler->getGroupIds("block_read", $bid); $block = array('form_title' => _AM_CLONEBLOCK, 'name' => $myblock->getVar('name'), 'title' => $myblock->getVar('title'), 'side' => $myblock->getVar('side'), 'weight' => $myblock->getVar('weight'), 'visible' => $myblock->getVar('visible'), 'content' => $myblock->getVar('content', 'N'), 'modules' => $modules, 'is_custom' => $is_custom, 'ctype' => $myblock->getVar('c_type'), 'cachetime' => $myblock->getVar('bcachetime'), 'op' => 'clone_ok', 'bid' => $myblock->getVar('bid'), 'edit_form' => $myblock->getOptions(), 'template' => $myblock->getVar('template'), 'options' => $myblock->getVar('options'), 'groups' => $groups); echo '<a href="admin.php?fct=blocksadmin">' . _AM_BADMIN . '</a> <span style="font-weight:bold;">»»</span> ' . _AM_CLONEBLOCK . '<br /><br />'; include XOOPS_ROOT_PATH . '/modules/system/admin/blocksadmin/blockform.php'; $form->display(); xoops_cp_footer(); exit; }
function myblocksadmin_update_block($bid, $bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bcachetime, $bmodule, $options = array()) { global $xoopsConfig; if (empty($bmodule)) { xoops_cp_header(); xoops_error(sprintf(_AM_NOTSELNG, _AM_VISIBLEIN)); xoops_cp_footer(); exit; } $myblock = new XoopsBlock($bid); // $myblock->setVar('side', $bside); GIJ - if ($bside >= 0) { $myblock->setVar('side', $bside); } // GIJ + $myblock->setVar('weight', $bweight); $myblock->setVar('visible', $bvisible); $myblock->setVar('title', $btitle); $myblock->setVar('content', $bcontent); $myblock->setVar('bcachetime', $bcachetime); if (isset($options) && count($options) > 0) { $options = implode('|', $options); $myblock->setVar('options', $options); } if ($myblock->getVar('block_type') == 'C') { switch ($bctype) { case 'H': $name = _AM_CUSTOMHTML; break; case 'P': $name = _AM_CUSTOMPHP; break; case 'S': $name = _AM_CUSTOMSMILE; break; default: $name = _AM_CUSTOMNOSMILE; break; } $myblock->setVar('name', $name); $myblock->setVar('c_type', $bctype); } else { $myblock->setVar('c_type', 'H'); } $msg = _AM_DBUPDATED; if ($myblock->store() != false) { $db =& Database::getInstance(); $sql = sprintf("DELETE FROM %s WHERE block_id = %u", $db->prefix('block_module_link'), $bid); $db->query($sql); foreach ($bmodule as $bmid) { $sql = sprintf("INSERT INTO %s (block_id, module_id) VALUES (%u, %d)", $db->prefix('block_module_link'), $bid, intval($bmid)); $db->query($sql); } include_once XOOPS_ROOT_PATH . '/class/template.php'; $xoopsTpl = new XoopsTpl(); $xoopsTpl->xoops_setCaching(2); if ($myblock->getVar('template') != '') { if ($xoopsTpl->is_cached('db:' . $myblock->getVar('template'))) { if (!$xoopsTpl->clear_cache('db:' . $myblock->getVar('template'))) { $msg = 'Unable to clear cache for block ID' . $bid; } } } else { if ($xoopsTpl->is_cached('db:system_dummy.html', 'block' . $bid)) { if (!$xoopsTpl->clear_cache('db:system_dummy.html', 'block' . $bid)) { $msg = 'Unable to clear cache for block ID' . $bid; } } } } else { $msg = 'Failed update of block. ID:' . $bid; } // redirect_header('admin.php?fct=blocksadmin&t='.time(),1,$msg); // exit(); GIJ - return $msg; // GIJ + }
function previewContent($block_data) { $bid = intval($block_data['bid']); if (!$block_data['is_custom']) { return ''; } if (empty($this->preview_request)) { return ''; } //HACK by domifara //TODO : need no hook block at this $block = new XoopsBlock($bid); if ($block->getVar('mid')) { return ''; } $block->setVar('title', $block_data['title']); $block->setVar('content', $block_data['content']); restore_error_handler(); $original_level = error_reporting(E_ALL); // $ret = $block->getContent( 'S' , $block_data['ctype'] ) ; $c_type = $block_data['ctype']; if ($c_type == 'H') { $ret = str_replace('{X_SITEURL}', XOOPS_URL . '/', $block->getVar('content', 'N')); } else { if ($c_type == 'P') { ob_start(); echo eval($block->getVar('content', 'N')); $content = ob_get_contents(); ob_end_clean(); $ret = str_replace('{X_SITEURL}', XOOPS_URL . '/', $content); } else { if ($c_type == 'S') { $myts =& MyTextSanitizer::getInstance(); $content = str_replace('{X_SITEURL}', XOOPS_URL . '/', $block->getVar('content', 'N')); $ret = $myts->displayTarea($content, 1, 1); } else { $myts =& MyTextSanitizer::getInstance(); $content = str_replace('{X_SITEURL}', XOOPS_URL . '/', $block->getVar('content', 'N')); $ret = $myts->displayTarea($content, 1, 0); } } } error_reporting($original_level); return $ret; }
function plugin_xoopsblock_convert() { if ($this->root->module['platform'] !== "xoops") { return ''; } static $css_show = FALSE; list($tgt, $option1, $option2) = array_pad(func_get_args(), 3, ""); $tgt_bids = array(); if (!$tgt || $tgt === "?") { $tgt = "?"; } else { foreach (explode(",", $tgt) as $_bid) { if (preg_match("/^\\d+\$/", $_bid) && $_bid > 0) { $tgt_bids[] = $_bid; } } } $align = "left"; $around = false; $width = ""; $arg = array(); if (preg_match("/^(left|center|right)\$/i", $option2, $arg)) { $align = $arg[1]; } if (preg_match("/^(left|center|right)\$/i", $option1, $arg)) { $align = $arg[1]; } if (preg_match("/^(around|float|width)(:?w?([\\d]+%?)(?:px)?)?\$/i", $option2, $arg)) { if ($arg[1]) { $around = true; } $width = !strstr($arg[3], "%") ? $arg[3] . "px" : $arg[3]; $width = "width:" . $width . ";"; } if (preg_match("/^(around|float|width)(:?w?([\\d]+%?)(?:px)?)?\$/i", $option1, $arg)) { if ($arg[1]) { $around = true; } $width = !strstr($arg[3], "%") ? $arg[3] . "px" : $arg[3]; $width = "width:" . $width . ";"; } if ($align === 'center') { if (!$width) { $width = 'width:auto;'; } $style = ' style="margin-left:auto;margin-right:auto;' . $width . '"'; $around = false; } else { $style = ' style="float:' . $align . ';' . $width . '"'; } $clear = $around ? '' : '<div style="clear:both;"></div>'; global $xoopsUser; $xoopsblock = new XoopsBlock(); $xoopsgroup = new XoopsGroup(); $arr = array(); $side = null; if ($this->root->userinfo['admin']) { $arr = $xoopsblock->getAllBlocks(); } else { if ($xoopsUser) { $arr = $xoopsblock->getAllBlocksByGroup($xoopsUser->groups()); } else { $arr = $xoopsblock->getAllBlocksByGroup($this->plugin_xoopsblock_getByType("Anonymous")); } } $ret = ""; if ($tgt == "?") { foreach ($arr as $myblock) { $block = array(); $block_type = @$myblock->getVar("type") ? $myblock->getVar("type") : $myblock->getVar("block_type"); $name = @$myblock->getVar("title") ? $myblock->getVar("title") : $myblock->getVar("name"); $bid = $myblock->getVar('bid'); $ret .= "<li>(" . $bid . ")" . $name . "</li>"; } } else { global $xoopsTpl; require_once XOOPS_ROOT_PATH . '/class/template.php'; $xoopsTpl = new XoopsTpl(); if (is_object($xoopsUser)) { $xoopsTpl->assign(array('xoops_isuser' => true, 'xoops_userid' => $xoopsUser->getVar('uid'), 'xoops_uname' => $xoopsUser->getVar('uname'), 'xoops_isadmin' => $xoopsUser->isAdmin())); } $xoopsTpl->assign('xoops_requesturi', htmlspecialchars($GLOBALS['xoopsRequestUri'], ENT_QUOTES)); foreach ($tgt_bids as $bid) { $myblock = new XoopsBlock($bid); $_bid = $myblock->getVar('bid'); if (!empty($_bid)) { $bcachetime = $myblock->getVar('bcachetime'); // Only a guest enable cache. by nao-pon //if (empty($bcachetime)) { if ($bcachetime % 10 == 1) { $bcachetime_guest = TRUE; $bcachetime = $bcachetime - 1; } else { $bcachetime_guest = FALSE; } if (empty($bcachetime) || is_object($xoopsUser) && $bcachetime_guest) { //if (empty($bcachetime)) { $xoopsTpl->xoops_setCaching(0); } else { $xoopsTpl->xoops_setCaching(2); $xoopsTpl->xoops_setCacheTime($bcachetime); } $btpl = $myblock->getVar('template'); if ($btpl != '') { if (empty($bcachetime) || !$xoopsTpl->is_cached('db:' . $btpl, 'blk_' . $myblock->getVar('bid'))) { //$xoopsLogger->addBlock($myblock->getVar('name')); $bresult = $myblock->buildBlock(); if (!$bresult) { continue; } $xoopsTpl->assign_by_ref('block', $bresult); $bcontent = $xoopsTpl->fetch('db:' . $btpl, 'blk_' . $myblock->getVar('bid')); $xoopsTpl->clear_assign('block'); } else { //$xoopsLogger->addBlock($myblock->getVar('name'), true, $bcachetime); $bcontent = $xoopsTpl->fetch('db:' . $btpl, 'blk_' . $myblock->getVar('bid')); } } else { //$bid = $myblock->getVar('bid'); if (empty($bcachetime) || !$xoopsTpl->is_cached('db:system_dummy.html', 'blk_' . $bid)) { //$xoopsLogger->addBlock($myblock->getVar('name')); $bresult = $myblock->buildBlock(); if (!$bresult) { continue; } $xoopsTpl->assign_by_ref('dummy_content', $bresult['content']); $bcontent = $xoopsTpl->fetch('db:system_dummy.html', 'blk_' . $bid); $xoopsTpl->clear_assign('block'); } else { //$xoopsLogger->addBlock($myblock->getVar('name'), true, $bcachetime); $bcontent = $xoopsTpl->fetch('db:system_dummy.html', 'blk_' . $bid); } } $btitle = $myblock->getVar('title'); } else { $btitle = "Block({$bid})"; $bcontent = "Block({$bid}) is not found."; } if ($bcontent) { $ret .= "<h5>" . $btitle . "</h5>\n"; $ret .= $bcontent; foreach (explode("\n", $xoopsTpl->get_template_vars('xoops_block_header')) as $str) { $this->root->head_tags[] = rtrim($str); } foreach (explode("\n", $xoopsTpl->get_template_vars('xoops_module_header')) as $str) { $this->root->head_tags[] = rtrim($str); } $this->root->head_tags = array_unique($this->root->head_tags); } } unset($myblock); } if (!$css_show) { $css_show = true; $this->root->head_pre_tags[] = "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"" . XOOPS_URL . "/xoops.css\" />"; } if ($tgt == "?") { $ret = "<ul>{$ret}</ul>"; } unset($xoopsblock, $xoopsgroup); return "<div{$style}>{$ret}</div>{$clear}"; }
function getEntryIndex() { return $this->_mBlock->getVar('side'); }
/** * XoopsThemeBlocksPlugin::buildBlock() * * @param XoopsBlock $xobject * @param XoopsTpl $template * @return array|bool */ public function buildBlock($xobject, &$template) { $xoops = Xoops::getInstance(); // The lame type workaround will change // bid is added temporarily as workaround for specific block manipulation $dirname = $xobject->getVar('dirname'); $block = array('id' => $xobject->getVar('bid'), 'module' => $dirname, 'title' => $xobject->getVar('title'), 'weight' => $xobject->getVar('weight'), 'lastmod' => $xobject->getVar('last_modified')); $bcachetime = (int) $xobject->getVar('bcachetime'); if (empty($bcachetime)) { $template->caching = 0; } else { $template->caching = 2; $template->cache_lifetime = $bcachetime; } $template->setCompileId($dirname); $tplName = ($tplName = $xobject->getVar('template')) ? "block:{$dirname}/{$tplName}" : "module:system/system_block_dummy.tpl"; //$tplName = str_replace('.html', '.tpl', $tplName); $cacheid = $this->generateCacheId('blk_' . $xobject->getVar('bid')); $xoops->preload()->triggerEvent('core.themeblocks.buildblock.start', array($xobject, $template->isCached($tplName, $cacheid))); if (!$bcachetime || !$template->isCached($tplName, $cacheid)) { //Get theme metas $old = array(); if ($this->theme && $bcachetime) { foreach ($this->theme->metas as $type => $value) { $old[$type] = $this->theme->metas[$type]; } } //build block if ($bresult = $xobject->buildBlock()) { $template->assign('block', $bresult); $block['content'] = $template->fetch($tplName, $cacheid); } else { $block = false; } //check if theme added new metas if ($this->theme && $bcachetime) { $metas = array(); foreach ($this->theme->metas as $type => $value) { $dif = Xoops_Utils::arrayRecursiveDiff($this->theme->metas[$type], $old[$type]); if (count($dif)) { $metas[$type] = $dif; } } if (count($metas)) { Xoops_Cache::write($cacheid, $metas); } } } else { $block['content'] = $template->fetch($tplName, $cacheid); } //add block cached metas if ($this->theme && $bcachetime) { if ($metas = Xoops_Cache::read($cacheid)) { foreach ($metas as $type => $value) { $this->theme->metas[$type] = array_merge($this->theme->metas[$type], $metas[$type]); } } } $template->setCompileId(); return $block; }
} else { if ($op == 'save') { $block['form_title'] = _AM_ADDBLOCK; } else { $block['form_title'] = _AM_CLONEBLOCK; } $myblock = new XoopsBlock(); $myblock->setVar('block_type', 'C'); } $myts =& MyTextSanitizer::getInstance(); $myblock->setVar('title', $myts->stripSlashesGPC($btitle)); $myblock->setVar('content', $myts->stripSlashesGPC($bcontent)); $dummyhtml = '<html><head><meta http-equiv="content-type" content="text/html; charset=' . _CHARSET . '" />'; $dummyhtml .= '<meta http-equiv="content-language" content="' . _LANGCODE . '" /><title>' . $xoopsConfig['sitename'] . '</title>'; $dummyhtml .= '<link rel="stylesheet" type="text/css" media="all" href="' . xoops_getcss($xoopsConfig['theme_set']) . '" />'; $dummyhtml .= '</head><body><table><tr><th>' . $myblock->getVar('title') . '</th></tr><tr><td>'; $dummyhtml .= $myblock->getContent('S', $bctype) . '</td></tr></table></body></html>'; $block['groups'] = $bgroups; $block['edit_form'] = false; $block['template'] = ''; $block['op'] = $op; $block['side'] = $bside; $block['weight'] = $bweight; $block['visible'] = $bvisible; $block['title'] = $myblock->getVar('title', 'E'); $block['content'] = $myblock->getVar('content', 'E'); $block['modules'] =& $bmodule; $block['ctype'] = isset($bctype) ? $bctype : $myblock->getVar('c_type'); $block['is_custom'] = true; $block['cachetime'] = intval($bcachetime); echo '<a href="admin.php?fct=blocksadmin">' . _AM_BADMIN . '</a> <span style="font-weight:bold;">»»</span> ' . $block['form_title'] . '<br /><br />';
$block['form_title'] = _AM_EDITBLOCK; $myblock = new XoopsBlock($bid); $block['name'] = $myblock->getVar('name'); } else { if ($op == 'save') { $block['form_title'] = _AM_ADDBLOCK; } else { $block['form_title'] = _AM_CLONEBLOCK; } $myblock = new XoopsBlock(); $myblock->setVar('block_type', 'C'); } $myts =& MyTextSanitizer::getInstance(); $myblock->setVar('title', $myts->stripSlashesGPC($btitle)); $myblock->setVar('content', $myts->stripSlashesGPC($bcontent)); $dummyhtml = '<html><head><meta http-equiv="content-type" content="text/html; charset=' . _CHARSET . '" /><meta http-equiv="content-language" content="' . _LANGCODE . '" /><title>' . $xoopsConfig['sitename'] . '</title><link rel="stylesheet" type="text/css" media="all" href="' . xoops_getcss($xoopsConfig['theme_set']) . '" /></head><body><table><tr><th>' . $myblock->getVar('title') . '</th></tr><tr><td>' . $myblock->getContent('S', $bctype) . '</td></tr></table></body></html>'; $block['edit_form'] = false; $block['template'] = ''; $block['op'] = $op; $block['side'] = $bside; $block['weight'] = $bweight; $block['visible'] = $bvisible; $block['title'] = $myblock->getVar('title', 'E'); $block['content'] = $myblock->getVar('content', 'E'); $block['modules'] =& $bmodule; $block['ctype'] = isset($bctype) ? $bctype : $myblock->getVar('c_type'); $block['is_custom'] = true; $block['cachetime'] = intval($bcachetime); echo '<a href="admin.php?fct=blocksadmin">' . _AM_BADMIN . '</a> <span style="font-weight:bold;">»»</span> ' . $block['form_title'] . '<br /><br />'; include XOOPS_ROOT_PATH . '/modules/system/admin/blocksadmin/blockform.php'; $form->display();
function previewContent($block_data) { $bid = intval($block_data['bid']); if (!$block_data['is_custom']) { return ''; } if (empty($this->preview_request)) { return ''; } $block = new XoopsBlock($bid); if ($block->getVar('mid')) { return ''; } $block->setVar('title', $block_data['title']); $block->setVar('content', $block_data['content']); restore_error_handler(); $original_level = error_reporting(E_ALL); $ret = $block->getContent('S', $block_data['ctype']); error_reporting($original_level); return $ret; }
/** * @param string $rettype * @param boolean $side * @param null $visible * @param string $orderby * @param int $isactive * @return array */ public function getAllBlocks($rettype = "object", $side = null, $visible = null, $orderby = "side,weight,bid", $isactive = 1) { $ret = array(); $qb = $this->db2->createXoopsQueryBuilder(); $eb = $qb->expr(); $qb->fromPrefix('newblocks', null)->where($eb->eq('isactive', $qb->createNamedParameter($isactive, \PDO::PARAM_INT))); if (isset($side)) { // get both sides in sidebox? (some themes need this) if ($side == XOOPS_SIDEBLOCK_BOTH) { $qb->andWhere($eb->in('side', array(0, 1))); } elseif ($side == XOOPS_CENTERBLOCK_ALL) { $qb->andWhere($eb->in('side', array(3, 4, 5, 7, 8, 9))); } else { $qb->andWhere($eb->eq('side', $qb->createNamedParameter($side, \PDO::PARAM_INT))); } } if (isset($visible)) { $qb->andWhere($eb->eq('visible', $qb->createNamedParameter($visible, \PDO::PARAM_INT))); } $qb->orderBy($orderby); switch ($rettype) { case "object": $qb->select('*'); $result = $qb->execute(); while ($myrow = $result->fetch(\PDO::FETCH_ASSOC)) { $ret[] = new XoopsBlock($myrow); } break; case "list": $qb->select('*'); $result = $qb->execute(); while ($myrow = $result->fetch(\PDO::FETCH_ASSOC)) { $block = new XoopsBlock($myrow); $title = $block->getVar("title"); $title = empty($title) ? $block->getVar("name") : $title; $ret[$block->getVar("bid")] = $title; } break; case "id": $qb->select('bid'); $result = $qb->execute(); while ($myrow = $result->fetch(\PDO::FETCH_ASSOC)) { $ret[] = $myrow['bid']; } break; } return $ret; }
/** * XoopsBlock::getAllBlocks() * * @param string $rettype * @param mixed $side * @param mixed $visible * @param string $orderby * @param integer $isactive * @return array */ public function getAllBlocks($rettype = 'object', $side = null, $visible = null, $orderby = 'side,weight,bid', $isactive = 1) { $db = XoopsDatabaseFactory::getDatabaseConnection(); $ret = array(); $where_query = ' WHERE isactive=' . $isactive; if (isset($side)) { // get both sides in sidebox? (some themes need this) if ($side == XOOPS_SIDEBLOCK_BOTH) { $side = '(side=0 OR side=1)'; } elseif ($side == XOOPS_CENTERBLOCK_ALL) { $side = '(side=3 OR side=4 OR side=5 OR side=7 OR side=8 OR side=9)'; } elseif ($side == XOOPS_FOOTERBLOCK_ALL) { $side = '(side=10 OR side=11 OR side=12)'; } else { $side = 'side=' . $side; } $where_query .= ' AND ' . $side; } if (isset($visible)) { $where_query .= ' AND visible=.' . $visible; } $where_query .= ' ORDER BY ' . $orderby; switch ($rettype) { case 'object': $sql = 'SELECT * FROM ' . $db->prefix('newblocks') . '' . $where_query; $result = $db->query($sql); while ($myrow = $db->fetchArray($result)) { $ret[] = new XoopsBlock($myrow); } break; case 'list': $sql = 'SELECT * FROM ' . $db->prefix('newblocks') . '' . $where_query; $result = $db->query($sql); while ($myrow = $db->fetchArray($result)) { $block = new XoopsBlock($myrow); $title = $block->getVar('title'); $title = empty($title) ? $block->getVar('name') : $title; $ret[$block->getVar('bid')] = $title; } break; case 'id': $sql = 'SELECT bid FROM ' . $db->prefix('newblocks') . '' . $where_query; $result = $db->query($sql); while ($myrow = $db->fetchArray($result)) { $ret[] = $myrow['bid']; } break; } //echo $sql; return $ret; }
$myblock->setVar('visible', $_POST['bvisible']); $myblock->setVar('title', $_POST['btitle']); $myblock->setVar('content', $bcontent); $myblock->setVar('bcachetime', $bcachetime); $options_count = count($options); if ($options_count > 0) { //Convert array values to comma-separated for ($i = 0; $i < $options_count; $i++) { if (is_array($options[$i])) { $options[$i] = implode(',', $options[$i]); } } $options = implode('|', $options); $myblock->setVar('options', $options); } if ($myblock->getVar('block_type') == 'C') { switch ($bctype) { case 'H': $name = _AM_CUSTOMHTML; break; case 'P': $name = _AM_CUSTOMPHP; break; case 'S': $name = _AM_CUSTOMSMILE; break; default: $name = _AM_CUSTOMNOSMILE; break; } $myblock->setVar('name', $name);
function previewContent($block_data) { $bid = intval($block_data['bid']); if (!$block_data['is_custom']) { return ''; } if (empty($this->preview_request)) { return ''; } //HACK by domifara //TODO : need no hook block at this $block = new XoopsBlock($bid); /* $handler =& xoops_gethandler('block'); $block =& $handler->create(false) ; $block->load($bid) ; */ if ($block->getVar('mid')) { return ''; } $block->setVar('title', $block_data['title']); $block->setVar('content', $block_data['content']); restore_error_handler(); $original_level = error_reporting(E_ALL); $ret = $block->getContent('S', $block_data['ctype']); error_reporting($original_level); return $ret; }
function clone_block_ok($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options) { global $xoopsUser; $block = new XoopsBlock($bid); $clone =& $block->xoopsClone(); if (empty($bmodule)) { xoops_cp_header(); xoops_error(sprintf(_AM_NOTSELNG, _AM_VISIBLEIN)); xoops_cp_footer(); exit; } $clone->setVar('side', $bside); $clone->setVar('weight', $bweight); $clone->setVar('visible', $bvisible); $clone->setVar('content', $bcontent); //$clone->setVar('title', $btitle); $clone->setVar('bcachetime', $bcachetime); if (isset($options) && count($options) > 0) { $options = implode('|', $options); $clone->setVar('options', $options); } $clone->setVar('bid', 0); if ($block->getVar('block_type') == 'C' || $block->getVar('block_type') == 'E') { $clone->setVar('block_type', 'E'); } else { $clone->setVar('block_type', 'D'); } $newid = $clone->store(); if (!$newid) { xoops_cp_header(); $clone->getHtmlErrors(); xoops_cp_footer(); exit; } if ($clone->getVar('template') != '') { $tplfile_handler =& xoops_gethandler('tplfile'); $btemplate =& $tplfile_handler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid); if (count($btemplate) > 0) { $tplclone =& $btemplate[0]->xoopsClone(); $tplclone->setVar('tpl_id', 0); $tplclone->setVar('tpl_refid', $newid); $tplman->insert($tplclone); } } $db =& Database::getInstance(); foreach ($bmodule as $bmid) { $sql = 'INSERT INTO ' . $db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newid . ', ' . $bmid . ')'; $db->query($sql); } $groups =& $xoopsUser->getGroups(); $count = count($groups); for ($i = 0; $i < $count; $i++) { $sql = "INSERT INTO " . $db->prefix('group_permission') . " (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (" . $groups[$i] . ", " . $newid . ", 1, 'block_read')"; $db->query($sql); } redirect_header('admin.php?fct=blocksadmin&t=' . time(), 1, _AM_DBUPDATED); }
/** * getForm - get block edit form * * @param string $mode mode for form, edit or clone * * @return void */ public function getForm($mode = 'edit') { $xoops = Xoops::getInstance(); $xoops->loadLanguage('blocks', 'system'); if ($this->obj->isNew()) { $title = SystemLocale::ADD_BLOCK; $modules = array(-1); $groups = array(FixedGroups::USERS, FixedGroups::ANONYMOUS, FixedGroups::ADMIN); $this->obj->setVar('block_type', 'C'); $this->obj->setVar('visible', 1); $op = 'save'; } else { $title = ''; $modules = array(); // Search modules $blockmodulelink_handler = $xoops->getHandlerBlockmodulelink(); $criteria = new CriteriaCompo(new Criteria('block_id', $this->obj->getVar('bid'))); $blockmodulelink = $blockmodulelink_handler->getObjects($criteria); /* @var $link XoopsBlockmodulelink */ foreach ($blockmodulelink as $link) { $modules[] = $link->getVar('module_id'); } // Search perms $groupperm_handler = $xoops->getHandlerGroupperm(); $groups = $groupperm_handler->getGroupIds('block_read', $this->obj->getVar('bid')); switch ($mode) { case 'edit': $title = SystemLocale::EDIT_BLOCK; break; case 'clone': $title = SystemLocale::CLONE_BLOCK; $this->obj->setVar('bid', 0); if ($this->obj->isCustom()) { $this->obj->setVar('block_type', 'C'); } else { $this->obj->setVar('block_type', 'D'); } break; } $op = 'save'; } parent::__construct($title, 'blockform', 'admin.php', 'post', true); if (!$this->obj->isNew()) { $this->addElement(new Xoops\Form\Label(XoopsLocale::NAME, $this->obj->getVar('name'))); } // Side position $side_select = new Xoops\Form\Select(XoopsLocale::SIDE, 'side', $this->obj->getVar('side')); $side_select->addOptionArray(array(0 => XoopsLocale::LEFT, 1 => XoopsLocale::RIGHT, 3 => SystemLocale::TOP_LEFT, 4 => SystemLocale::TOP_RIGHT, 5 => SystemLocale::TOP_CENTER, 7 => SystemLocale::BOTTOM_LEFT, 8 => SystemLocale::BOTTOM_RIGHT, 9 => SystemLocale::BOTTOM_CENTER)); $this->addElement($side_select); // Order $weight = new Xoops\Form\Text(XoopsLocale::WEIGHT, 'weight', 1, 5, $this->obj->getVar('weight'), ''); $weight->setPattern('^\\d+$', XoopsLocale::E_YOU_NEED_A_POSITIVE_INTEGER); $this->addElement($weight, true); // Display $this->addElement(new Xoops\Form\RadioYesNo(XoopsLocale::VISIBLE, 'visible', $this->obj->getVar('visible'))); // Visible In $mod_select = new Xoops\Form\Select(XoopsLocale::VISIBLE_IN, 'modules', $modules, 5, true); $criteria = new CriteriaCompo(new Criteria('hasmain', 1)); $criteria->add(new Criteria('isactive', 1)); $module_list = $xoops->getHandlerModule()->getNameList($criteria); $module_list[-1] = XoopsLocale::TOP_PAGE; $module_list[0] = XoopsLocale::ALL_PAGES; ksort($module_list); $mod_select->addOptionArray($module_list); $this->addElement($mod_select); // Title $this->addElement(new Xoops\Form\Text(XoopsLocale::TITLE, 'title', 5, 255, $this->obj->getVar('title')), false); if ($this->obj->isNew() || $this->obj->isCustom()) { $editor_configs = array(); $editor_configs["name"] = "content_block"; $editor_configs["value"] = $this->obj->getVar('content', 'e'); $editor_configs["rows"] = 15; $editor_configs["cols"] = 6; $editor_configs["editor"] = $xoops->getModuleConfig('blocks_editor', 'system'); $this->addElement(new Xoops\Form\Editor(XoopsLocale::CONTENT, "content_block", $editor_configs), true); if (in_array($editor_configs["editor"], array('dhtmltextarea', 'textarea'))) { $ctype_select = new Xoops\Form\Select(SystemLocale::CONTENT_TYPE, 'c_type', $this->obj->getVar('c_type')); $ctype_select->addOptionArray(array('H' => XoopsLocale::HTML, 'P' => SystemLocale::PHP_SCRIPT, 'S' => SystemLocale::AUTO_FORMAT_SMILIES_ENABLED, 'T' => SystemLocale::AUTO_FORMAT_SMILIES_DISABLED)); $this->addElement($ctype_select); } else { $this->addElement(new Xoops\Form\Hidden('c_type', 'H')); } } else { if ($this->obj->getVar('template') != '') { $tplfile_handler = $xoops->getHandlerTplfile(); $btemplate = $tplfile_handler->find($xoops->getConfig('template_set'), 'block', $this->obj->getVar('bid')); if (count($btemplate) > 0) { $this->addElement(new Xoops\Form\Label(XoopsLocale::CONTENT, '<a href="' . \XoopsBaseConfig::get('url') . '/modules/system/admin.php?fct=tplsets&op=edittpl&id=' . $btemplate[0]->getVar('tpl_id') . '">' . SystemLocale::EDIT_TEMPLATE . '</a>')); } else { $btemplate2 = $tplfile_handler->find('default', 'block', $this->obj->getVar('bid')); if (count($btemplate2) > 0) { $this->addElement(new Xoops\Form\Label(XoopsLocale::CONTENT, '<a href="' . \XoopsBaseConfig::get('url') . '/modules/system/admin.php?fct=tplsets&op=edittpl&id=' . $btemplate2[0]->getVar('tpl_id') . '" rel="external">' . SystemLocale::EDIT_TEMPLATE . '</a>')); } } } if ($this->obj->getOptions() != false) { $this->addElement(new Xoops\Form\Label(XoopsLocale::OPTIONS, $this->obj->getOptions())); } else { $this->addElement(new Xoops\Form\Hidden('options', $this->obj->getVar('options'))); } $this->addElement(new Xoops\Form\Hidden('c_type', 'H')); } $cache_select = new Xoops\Form\Select(SystemLocale::CACHE_LIFETIME, 'bcachetime', $this->obj->getVar('bcachetime')); $cache_select->addOptionArray(array('0' => XoopsLocale::NO_CACHE, '30' => sprintf(XoopsLocale::F_SECONDS, 30), '60' => XoopsLocale::ONE_MINUTE, '300' => sprintf(XoopsLocale::F_MINUTES, 5), '1800' => sprintf(XoopsLocale::F_MINUTES, 30), '3600' => XoopsLocale::ONE_HOUR, '18000' => sprintf(XoopsLocale::F_HOURS, 5), '86400' => XoopsLocale::ONE_DAY, '259200' => sprintf(XoopsLocale::F_DAYS, 3), '604800' => XoopsLocale::ONE_WEEK, '2592000' => XoopsLocale::ONE_MONTH)); $this->addElement($cache_select); // Groups $this->addElement(new Xoops\Form\SelectGroup(XoopsLocale::GROUPS, 'groups', true, $groups, 5, true)); $this->addElement(new Xoops\Form\Hidden('block_type', $this->obj->getVar('block_type'))); $this->addElement(new Xoops\Form\Hidden('mid', $this->obj->getVar('mid'))); $this->addElement(new Xoops\Form\Hidden('func_num', $this->obj->getVar('func_num'))); $this->addElement(new Xoops\Form\Hidden('func_file', $this->obj->getVar('func_file'))); $this->addElement(new Xoops\Form\Hidden('show_func', $this->obj->getVar('show_func'))); $this->addElement(new Xoops\Form\Hidden('edit_func', $this->obj->getVar('edit_func'))); $this->addElement(new Xoops\Form\Hidden('template', $this->obj->getVar('template'))); $this->addElement(new Xoops\Form\Hidden('dirname', $this->obj->getVar('dirname'))); $this->addElement(new Xoops\Form\Hidden('name', $this->obj->getVar('name'))); $this->addElement(new Xoops\Form\Hidden('bid', $this->obj->getVar('bid'))); $this->addElement(new Xoops\Form\Hidden('op', $op)); $this->addElement(new Xoops\Form\Hidden('fct', 'blocksadmin')); $button_tray = new Xoops\Form\ElementTray('', ' '); if ($this->obj->isNew() || $this->obj->isCustom()) { $preview = new Xoops\Form\Button('', 'previewblock', XoopsLocale::A_PREVIEW, 'preview'); $preview->setExtra("onclick=\"blocks_preview();\""); $button_tray->addElement($preview); } $button_tray->addElement(new Xoops\Form\Button('', 'submitblock', XoopsLocale::A_SUBMIT, 'submit')); $this->addElement($button_tray); }
function getAllBlocks($rettype = "object", $side = null, $visible = null, $orderby = "side,weight,bid", $isactive = 1) { $db = $GLOBALS['xoopsDB']; $ret = array(); $where_query = " WHERE isactive=" . $isactive; if (isset($side)) { // get both sides in sidebox? (some themes need this) if ($side == 2) { $side = "(side=0 OR side=1)"; } elseif ($side == 6) { $side = "(side=3 OR side=4 OR side=5 OR side=7 OR side=8 OR side=9)"; } else { $side = "side=" . $side; } $where_query .= " AND " . $side; } if (isset($visible)) { $where_query .= " AND visible={$visible}"; } $where_query .= " ORDER BY {$orderby}"; switch ($rettype) { case "object": $sql = "SELECT * FROM " . $db->prefix("newblocks") . "" . $where_query; $result = $db->query($sql); while ($myrow = $db->fetchArray($result)) { $ret[] = new XoopsBlock($myrow); } break; case "list": $sql = "SELECT * FROM " . $db->prefix("newblocks") . "" . $where_query; $result = $db->query($sql); while ($myrow = $db->fetchArray($result)) { $block = new XoopsBlock($myrow); //$title = ($block->getVar("block_type") != "C") ? $block->getVar("name") : $block->getVar("title"); $title = $block->getVar("title"); $title = empty($title) ? $block->getVar("name") : $title; $ret[$block->getVar("bid")] = $title; } break; case "id": $sql = "SELECT bid FROM " . $db->prefix("newblocks") . "" . $where_query; $result = $db->query($sql); while ($myrow = $db->fetchArray($result)) { $ret[] = $myrow['bid']; } break; } //echo $sql; return $ret; }
} if ($op == 'clone') { xoops_cp_header(); $myblock = new XoopsBlock($bid); // check if this is TinyD's content block // if( $myblock->getVar('show_func') != 'b_tinycontent_content_show' ) { // redirect_header( 'myblocksadmin.php' , 1 , 'invalid block' ) ; // } $db =& Database::getInstance(); $sql = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . intval($bid); $result = $db->query($sql); $modules = array(); while ($row = $db->fetchArray($result)) { $modules[] = intval($row['module_id']); } $is_custom = $myblock->getVar('block_type') == 'C' || $myblock->getVar('block_type') == 'E' ? true : false; $block = array('form_title' => _AM_CLONEBLOCK, 'name' => $myblock->getVar('name'), 'side' => $myblock->getVar('side'), 'weight' => $myblock->getVar('weight'), 'visible' => $myblock->getVar('visible'), 'content' => $myblock->getVar('content', 'N'), 'title' => $myblock->getVar('title', 'E'), 'modules' => $modules, 'is_custom' => $is_custom, 'ctype' => $myblock->getVar('c_type'), 'cachetime' => $myblock->getVar('bcachetime'), 'op' => 'clone_ok', 'bid' => $myblock->getVar('bid'), 'edit_form' => $myblock->getOptions(), 'template' => $myblock->getVar('template'), 'options' => $myblock->getVar('options')); echo '<a href="admin.php?fct=blocksadmin">' . _AM_BADMIN . '</a> <span style="font-weight:bold;">»»</span> ' . _AM_CLONEBLOCK . '<br /><br />'; include 'blockform.php'; $form->display(); xoops_cp_footer(); exit; } if ($op == 'clone_ok') { $block = new XoopsBlock($bid); // check if this is TinyD's content block // if( $block->getVar('show_func') != 'b_tinycontent_content_show' ) { // redirect_header( 'myblocksadmin.php' , 1 , 'invalid block' ) ; // } if (empty($options)) { $options = array();