PEAK XOOPS - Re: How to display blocks in appoint page in englishin japanese

Re: How to display blocks in appoint page

List posts in the topic

none Re: How to display blocks in appoint page

msg# 1.1.1
depth:
2
Previous post - Next post | Parent - Children.1 | Posted on 2007/10/24 12:58 | Last modified
sugar  二等兵 From: Taiwan  Posts: 6
I will hack xoops cube be SNS
so I wish some blocks only display in "userinfo.php" page, like "friends list" or " monthly calendar"

I already succeed this hack

STEP1.
Edit modules/system/admin/blocksadmin/blockform.php & blocksadmin.php
add $module_list[-2] = "User Page"; before $module_list[-1] = _AM_TOPPAGE;

STEP2.
Edit class/xoopsblock.php find function getAllByGroupModule and getNonGroupedBlocks change to
    function &getAllByGroupModule($groupid, $module_id=0, $special_page=0, $visible=null, $orderby='b.weight,b.bid', $isactive=1)
    {
        $db =& Database::getInstance();
        $ret = array();
        $sql = "SELECT DISTINCT gperm_itemid FROM ".$db->prefix('group_permission')." WHERE gperm_name = 'block_read' AND gperm_modid = 1";
        if ( is_array($groupid) ) {
            $sql .= ' AND gperm_groupid IN ('.implode(',', $groupid).')';
        } else {
            if (intval($groupid) > 0) {
                $sql .= ' AND gperm_groupid='.$groupid;
            }
        }
        $result = $db->query($sql);
        $blockids = array();
        while ( $myrow = $db->fetchArray($result) ) {
            $blockids[] = $myrow['gperm_itemid'];
        }
        if (!empty($blockids)) {
            $sql = 'SELECT b.* FROM '.$db->prefix('newblocks').' b, '.$db->prefix('block_module_link').' m WHERE m.block_id=b.bid';
            $sql .= ' AND b.isactive='.$isactive;
            if (isset($visible)) {
                $sql .= ' AND b.visible='.intval($visible);
            }
            $module_id = intval($module_id);
            if (!empty($module_id)) {
                $sql .= ' AND m.module_id IN (0,'.$module_id;
                if ($special_page == '1') {
                    $sql .= ',-1';
				}
                $sql .= ')';
            } else {
                if ($special_page == 1) {
                    $sql .= ' AND m.module_id IN (0,-1)';
		} elseif ($special_page == 2) {
		    $sql .= ' AND m.module_id IN (0,-2)';
                } else {
                    $sql .= ' AND m.module_id=0';
                }
            }
            $sql .= ' AND b.bid IN ('.implode(',', $blockids).')';
            $sql .= ' ORDER BY '.$orderby;
			//echo $sql;
            $result = $db->query($sql);
            while ( $myrow = $db->fetchArray($result) ) {
                $block =& new XoopsBlock($myrow);
                $ret[$myrow['bid']] =& $block;
                unset($block);
            }
        }
        return $ret;
    }
	
    function &getNonGroupedBlocks($module_id=0, $special_page=0,, $visible=null, $orderby='b.weight,b.bid', $isactive=1)
    {
        $db =& Database::getInstance();
        $ret = array();
        $bids = array();
        $sql = "SELECT DISTINCT(bid) from ".$db->prefix('newblocks');
        if ($result = $db->query($sql)) {
            while ( $myrow = $db->fetchArray($result) ) {
                $bids[] = $myrow['bid'];
            }
        }
        $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'";
        $grouped = array();
        if ($result = $db->query($sql)) {
            while ( $myrow = $db->fetchArray($result) ) {
                $grouped[] = $myrow['gperm_itemid'];
            }
        }
        $non_grouped = array_diff($bids, $grouped);
        if (!empty($non_grouped)) {
            $sql = 'SELECT b.* FROM '.$db->prefix('newblocks').' b, '.$db->prefix('block_module_link').' m WHERE m.block_id=b.bid';
            $sql .= ' AND b.isactive='.$isactive;
            if (isset($visible)) {
                $sql .= ' AND b.visible='.intval($visible);
            }
            $module_id = intval($module_id);
            if (!empty($module_id)) {
                $sql .= ' AND m.module_id IN (0,'.$module_id;
                if ($special_page == 1) {
                    $sql .= ',-1';
				}
                $sql .= ')';
            } else {
                if ($special_page == 1) {
                    $sql .= ' AND m.module_id IN (0,-1)';
		} elseif ($special_page == 2) {
		    $sql .= ' AND m.module_id IN (0,-2)';
                } else {
                    $sql .= ' AND m.module_id=0';
                }
            }
            $sql .= ' AND b.bid IN ('.implode(',', $non_grouped).')';
            $sql .= ' ORDER BY '.$orderby;
            $result = $db->query($sql);
            while ( $myrow = $db->fetchArray($result) ) {
                $block =& new XoopsBlock($myrow);
                $ret[$myrow['bid']] =& $block;
                unset($block);
            }
        }
        return $ret;
    }

STEP3.
Edit header.php find and change red color
    $xoopsblock = new XoopsBlock();
    $block_arr = array();
    if (is_object($xoopsUser)) {
        $xoopsTpl->assign(array('xoops_isuser' => true, 'xoops_userid' => $xoopsUser->getVar('uid'), 'xoops_uname' => $xoopsUser->getVar('uname'), 'xoops_isadmin' => $xoopsUserIsAdmin));
        if (!empty($xoopsModule)) {
            // set page title
            $xoopsTpl->assign(array('xoops_pagetitle' => $xoopsModule->getVar('name'), 'xoops_modulename' => $xoopsModule->getVar('name'), 'xoops_dirname' => $xoopsModule->getVar('dirname')));
            if (preg_match("/index\.php$/i", xoops_getenv('PHP_SELF')) && $xoopsConfig['startpage'] == $xoopsModule->getVar('dirname')) {
                $block_arr =& $xoopsblock->getAllByGroupModule($xoopsUser->getGroups(), $xoopsModule->getVar('mid'), 1, XOOPS_BLOCK_VISIBLE);
            } else {
                $block_arr =& $xoopsblock->getAllByGroupModule($xoopsUser->getGroups(), $xoopsModule->getVar('mid'), 0, XOOPS_BLOCK_VISIBLE);
            }
        } else {
            $xoopsTpl->assign('xoops_pagetitle', htmlspecialchars($xoopsConfig['slogan'], ENT_QUOTES));
            if (!empty($xoopsOption['show_cblock'])) {
                $block_arr =& $xoopsblock->getAllByGroupModule($xoopsUser->getGroups(), 0, 1, XOOPS_BLOCK_VISIBLE);
            } else {
                //$block_arr =& $xoopsblock->getAllByGroupModule($xoopsUser->getGroups(), 0, 0, XOOPS_BLOCK_VISIBLE);
		if (preg_match("/userinfo\.php$/i", xoops_getenv('PHP_SELF'))) {
			$block_arr =& $xoopsblock->getAllByGroupModule($xoopsUser->getGroups(), 0, 2, XOOPS_BLOCK_VISIBLE);
		} else {
			$block_arr =& $xoopsblock->getAllByGroupModule(XOOPS_GROUP_ANONYMOUS, 0, 0, XOOPS_BLOCK_VISIBLE);
		}
            }
        }
    } else {
        $xoopsTpl->assign(array('xoops_isuser' => false, 'xoops_isadmin' => false));
        if (!empty($xoopsModule)) {
            // set page title
            $xoopsTpl->assign(array('xoops_pagetitle' => $xoopsModule->getVar('name'), 'xoops_modulename' => $xoopsModule->getVar('name'), 'xoops_dirname' => $xoopsModule->getVar('dirname')));
            if (preg_match("/index\.php$/i", xoops_getenv('PHP_SELF')) && $xoopsConfig['startpage'] == $xoopsModule->getVar('dirname')) {
                $block_arr =& $xoopsblock->getAllByGroupModule(XOOPS_GROUP_ANONYMOUS, $xoopsModule->getVar('mid'), 1, XOOPS_BLOCK_VISIBLE);
            } else {
                $block_arr =& $xoopsblock->getAllByGroupModule(XOOPS_GROUP_ANONYMOUS, $xoopsModule->getVar('mid'), 0, XOOPS_BLOCK_VISIBLE);
            }
        } else {
            $xoopsTpl->assign('xoops_pagetitle', htmlspecialchars($xoopsConfig['slogan'], ENT_QUOTES));
            if (!empty($xoopsOption['show_cblock'])) {
                $block_arr =& $xoopsblock->getAllByGroupModule(XOOPS_GROUP_ANONYMOUS, 0, 1, XOOPS_BLOCK_VISIBLE);
            } else {
                //$block_arr =& $xoopsblock->getAllByGroupModule(XOOPS_GROUP_ANONYMOUS, 0, 0, XOOPS_BLOCK_VISIBLE);
		if (preg_match("/userinfo\.php$/i", xoops_getenv('PHP_SELF'))) {
			$block_arr =& $xoopsblock->getAllByGroupModule($xoopsUser->getGroups(), 0, 2, XOOPS_BLOCK_VISIBLE);
		} else {
			$block_arr =& $xoopsblock->getAllByGroupModule(XOOPS_GROUP_ANONYMOUS, 0, 0, XOOPS_BLOCK_VISIBLE);
		}
            }
        }
    }

all done, now can setting block only display in userinfo.php
Votes:15 Average:2.00

Posts tree

  Advanced search


Login
Username or e-mail:

Password:

Remember Me

Lost Password?

Register now!