11 if (!defined(
'XOOPS_ROOT_PATH')) {
38 $this->db =& XoopsDatabaseFactory::getDatabaseConnection();
39 $this->_dbtable = $this->db->prefix(
"rmc_blocks");
42 $this->
setVarType(
'options', XOBJ_DTYPE_ARRAY);
43 $this->
setVarType(
'content', XOBJ_DTYPE_OTHER);
45 if (
$id==null)
return;
56 return $this->
getVar(
'bid');
65 if (empty($this->rgroups)){
66 $sql =
"SELECT gperm_groupid FROM ".$this->db->prefix(
"group_permission").
" WHERE gperm_itemid='".$this->
id().
"' AND gperm_name='rmblock_read'";
69 while ($row = $this->db->fetchArray(
$result)){
71 $this->rgroups[] = $row[
'gperm_groupid'];
83 $this->rgroups = $groups;
91 if (empty($this->wgroups)){
92 $sql =
"SELECT gperm_groupid FROM ".$this->db->prefix(
"group_permission").
" WHERE gperm_itemid='".$this->
id().
"' AND gperm_name='block_admin'";
95 while ($row = $this->db->fetchArray(
$result)){
97 $this->wgroups[] = $row[
'gperm_groupid'];
105 foreach ($this->wgroups as $k){
106 $ret[] =
new EXMGroup($row[
'gperm_groupid']);
119 $this->wgroups = $groups;
128 if (func_num_args()<=0){
131 $sql =
"SELECT mid FROM ".$this->db->prefix(
"rmc_bkmod").
" WHERE bid='".$this->
id().
"'";
134 while ($row = $this->db->fetchArray(
$result)){
144 $value = func_get_arg(0);
154 $sql =
"SELECT mid, page FROM ".$this->db->prefix(
"rmc_bkmod").
" WHERE bid='".$this->
id().
"'";
157 while ($row = $this->db->fetchArray(
$result)){
158 $ret[$row[
'mid']][] = $row[
'subpage'];
174 if ($gid<=0 && empty($xoopsUser)) $gid = XOOPS_GROUP_ANONYMOUS;
176 $pHand =& xoops_gethandler(
'groupperm');
177 return $pHand->checkRight($level ?
'block_admin' :
'rmblock_read', $this->
id(), $gid>0 ? $gid : $xoopsUser->getGroups());
190 $c_type = $this->
getVar(
'content_type');
194 if ( $c_type ==
'HTML' ) {
195 return str_replace(
'{X_SITEURL}', XOOPS_URL.
'/', $this->getVar(
'content',
'N'));
196 }
elseif ( $c_type ==
'PHP' ) {
198 echo eval($this->
getVar(
'content',
'N'));
201 return str_replace(
'{X_SITEURL}', XOOPS_URL.
'/',
$content);
202 }
elseif ( $c_type ==
'XOOPS' ) {
204 return str_replace(
'{X_SITEURL}', XOOPS_URL.
'/', $tc->to_display($this->getVar(
'content',
'N'), 1, 1));
207 return str_replace(
'{X_SITEURL}', XOOPS_URL.
'/', $tc->to_display($this->getVar(
'content',
'N'), 1, 0));
211 return $this->
getVar(
'content',
'E');
214 return $this->
getVar(
'content',
'N');
226 if ( $this->
getVar(
"type") !=
"custom" ) {
228 $show_func = $this->
getVar(
'show_func');
235 if ($this->
getVar(
'element_type')==
'plugin'){
236 $file = XOOPS_ROOT_PATH.
'/modules/'.$this->
getVar(
'element').
'/plugins/'.$this->
getVar(
'dirname').
'/blocks/'.$this->
getVar(
'file');
239 $file = XOOPS_ROOT_PATH.
"/modules/".$this->
getVar(
'dirname').
"/blocks/".$this->
getVar(
'file');
240 if ( file_exists(XOOPS_ROOT_PATH.
"/modules/".$this->getVar(
'dirname').
"/language/".$xoopsConfig[
'language'].
"/blocks.php") ) {
241 include_once XOOPS_ROOT_PATH.
"/modules/".$this->
getVar(
'dirname').
"/language/".$xoopsConfig[
'language'].
"/blocks.php";
242 }
elseif ( file_exists(XOOPS_ROOT_PATH.
"/modules/".$this->getVar(
'dirname').
"/language/english/blocks.php") ) {
243 include_once XOOPS_ROOT_PATH.
"/modules/".$this->
getVar(
'dirname').
"/language/english/blocks.php";
252 if (function_exists($show_func)){
253 $block = $show_func($option);
254 if (!$block)
return false;
262 if (empty($block[
'content'])) {
279 if ( $position == 0 ) {
280 $ret = $contentdb.$content;
281 }
elseif ( $position == 1 ) {
289 if ($newtitle !=
"") {
292 $ret = $originaltitle;
299 if ( $this->
getVar(
"block_type") ==
"C" ) {
313 $edit_func = $this->
getVar(
'edit_func');
314 if (trim($edit_func)==
'')
return;
316 switch($this->
getVar(
'element_type')){
318 $file = XOOPS_ROOT_PATH.
'/modules/'.$this->
getVar(
'element').
'/blocks/'.$this->
getVar(
'file');
319 $lang =
"load_mod_locale";
322 $file = XOOPS_ROOT_PATH.
'/modules/'.$this->
getVar(
'element').
'/plugins/'.$this->
getVar(
'dirname').
'/blocks/'.$this->
getVar(
'file');
323 $lang =
'load_plugin_locale';
328 if (!is_file(
$file)){
329 return __(
'The configuration file for this block does not exists!',
'rmcommon');
335 if (!function_exists($edit_func)){
336 return __(
'There was a problem trying to show the configuration options for this block!',
'rmcommon');
342 return $edit_func($this->
getVar(
'options'));
360 if (!$this->
isNew()){
361 $this->db->queryF(
"DELETE FROM ".$this->db->prefix(
"rmc_bkmod").
" WHERE bid='".$this->
id().
"'");
364 $sql =
"INSERT INTO ".$this->db->prefix(
"rmc_bkmod").
" (`bid`,`mid`,`page`) VALUES ";
367 if (is_array($k) && isset($k[
'subpages'])){
368 foreach ($k[
'subpages'] as $l){
369 $sql1 .= $sql1==
'' ?
"('".$this->id().
"','$id','$l')" :
", ('".$this->id().
"','$id','$l')";
372 $sql1 .= $sql1==
'' ?
"('".$this->id().
"','$id','--')" :
", ('".$this->id().
"','$id','--')";
376 if (!$this->db->queryF(
$sql . $sql1)) $this->
addError($this->db->error());
379 if (count($this->rgroups)>0 || count($this->wgroups)>0){
380 if (!$this->
isNew()){
381 $this->db->queryF(
"DELETE FROM ".$this->db->prefix(
"group_permission").
" WHERE gperm_itemid='".$this->
id().
"' AND gperm_name='rmblock_read'");
384 $sql =
"INSERT INTO ".$this->db->prefix(
"group_permission").
" (`gperm_groupid`,`gperm_itemid`,`gperm_modid`,`gperm_name`) VALUES ";
386 foreach ($this->rgroups as $k){
387 $sql1 .= $sql1==
'' ?
"('$k','".$this->id().
"','1','rmblock_read')" :
", ('$k','".$this->id().
"','1','rmblock_read')";
390 if (!$this->db->queryF(
$sql . $sql1)) $this->
addError($this->db->error());
393 if ($this->
errors()!=
''){
return false;}
else {
return true;}
402 if (!$this->db->queryF(
"DELETE FROM ".$this->db->prefix(
"rmc_bkmod").
" WHERE bid='".$this->
id().
"'")){
403 $this->
addError($this->db->error());
405 if (!$this->db->queryF(
"DELETE FROM ".$this->db->prefix(
"group_permission").
" WHERE gperm_itemid='".$this->
id().
"' AND gperm_name='rmblock_read'")){
406 $this->
addError($this->db->error());
410 if ($this->
errors()!=
''){
return false; }
else {
return true; }
416 function getAllByGroupModule($groupid, $app_id=0, $toponlyblock=
false, $visible=null, $orderby=
'b.weight,b.bid', $isactive=1, $subpage=
'')
419 $orderby = $orderby==
'' ?
'b.weight,b.bid' : $orderby;
421 $db =& XoopsDatabaseFactory::getDatabaseConnection();
423 $sql =
"SELECT DISTINCT gperm_itemid FROM ".$db->prefix(
'group_permission').
" WHERE gperm_name = 'rmblock_read' AND gperm_modid = 1";
424 if ( is_array($groupid) ) {
425 $sql .=
' AND gperm_groupid IN ('.implode(
',', $groupid).
',0)';
427 if (intval($groupid) > 0) {
428 $sql .=
' AND gperm_groupid IN (0,'.$groupid.
')';
435 $blockids[] = $myrow[
'gperm_itemid'];
437 if (!empty($blockids)) {
438 $sql =
'SELECT b.* FROM '.$db->prefix(
'rmc_blocks').
' b, '.
$db->prefix(
'rmc_bkmod').
' m WHERE m.bid=b.bid';
439 $sql .=
' AND b.isactive='.$isactive;
440 if (isset($visible)) {
441 $sql .=
' AND b.visible='.intval($visible);
443 $app_id = intval($app_id);
444 if (!empty($app_id)) {
445 $sql .=
' AND m.app_id IN (0,'.$app_id;
452 $sql .=
' AND m.app_id IN (0,1)';
457 $sql .= $subpage!=
'' ?
" AND (m.subpage='$subpage' OR m.subpage='--')" :
'';
458 $sql .=
' AND b.bid IN ('.implode(
',', $blockids).
')';
459 $sql .=
' ORDER BY '.$orderby;
464 $block->assignVars($myrow);
465 $ret[$myrow[
'bid']] =& $block;
475 $db =& XoopsDatabaseFactory::getDatabaseConnection();
477 if (!is_numeric($moduleid)){
483 if ( $asobject ==
true ) {
484 $sql =
$sql =
"SELECT * FROM ".$db->prefix(
"rmc_blocks").
" WHERE $col='".$moduleid.
"'";
486 $sql =
"SELECT bid FROM ".$db->prefix(
"rmc_blocks").
" WHERE $col=".$moduleid.
"";
494 $ret[] = $myrow[
'bid'];