[xoops-cvslog 1563] CVS update: xoops2jp/html/class

Back to archive index

Minahito minah****@users*****
2006年 1月 3日 (火) 00:04:59 JST


Index: xoops2jp/html/class/xoopsblock.php
diff -u xoops2jp/html/class/xoopsblock.php:1.2.8.4 xoops2jp/html/class/xoopsblock.php:1.2.8.5
--- xoops2jp/html/class/xoopsblock.php:1.2.8.4	Fri Dec 30 17:20:30 2005
+++ xoops2jp/html/class/xoopsblock.php	Tue Jan  3 00:04:59 2006
@@ -1,5 +1,5 @@
 <?php
-// $Id: xoopsblock.php,v 1.2.8.4 2005/12/30 08:20:30 minahito Exp $
+// $Id: xoopsblock.php,v 1.2.8.5 2006/01/02 15:04:59 minahito Exp $
 //  ------------------------------------------------------------------------ //
 //                XOOPS - PHP Content Management System                      //
 //                    Copyright (c) 2000 XOOPS.org                           //
@@ -32,11 +32,21 @@
 if (!defined('XOOPS_ROOT_PATH')) {
     exit();
 }
+
 require_once XOOPS_ROOT_PATH."/kernel/object.php";
 
+define ("SHOW_SIDEBLOCK_LEFT",     1);
+define ("SHOW_SIDEBLOCK_RIGHT",    2);
+define ("SHOW_CENTERBLOCK_LEFT",   4);
+define ("SHOW_CENTERBLOCK_RIGHT",  8);
+define ("SHOW_CENTERBLOCK_CENTER", 16);
+define ("SHOW_BLOCK_ALL",          31);
+
 class XoopsBlock extends XoopsObject
 {
     var $db;
+	
+	var $mBlockFlagMapping = array();
 
     function XoopsBlock($id = null)
     {
@@ -72,6 +82,16 @@
                 $this->load(intval($id));
             }
         }
+
+		
+		$this->mBlockFlagMapping = array(
+			0 => false,
+			SHOW_SIDEBLOCK_LEFT => 0,
+			SHOW_SIDEBLOCK_RIGHT => 1,
+			SHOW_CENTERBLOCK_LEFT => 3,
+			SHOW_CENTERBLOCK_RIGHT => 4,
+			SHOW_CENTERBLOCK_CENTER => 5
+		);
     }
 
     function load($id)
@@ -167,14 +187,15 @@
     function &buildBlock()
     {
         global $xoopsConfig, $xoopsOption;
-        
+        $ret = false;
+
         $block = array();
         // M for module block, S for system block C for Custom
         if ( $this->getVar("block_type") != "C" ) {
             // get block display function
             $show_func = $this->getVar('show_func');
             if ( !$show_func ) {
-                return false;
+                return $ret;
             }
             // must get lang files b4 execution of the function
             if ( file_exists(XOOPS_ROOT_PATH."/modules/".$this->getVar('dirname')."/blocks/".$this->getVar('func_file')) ) {
@@ -188,19 +209,19 @@
                     // execute the function
                     $block = $show_func($options);
                     if ( !$block ) {
-                        return false;
+                        return $ret;
                     }
                 } else {
-                    return false;
+                    return $ret;
                 }
             } else {
-                return false;
+                return $ret;
             }
         } else {
             // it is a custom block, so just return the contents
             $block['content'] = $this->getContent("S",$this->getVar("c_type"));
             if (empty($block['content'])) {
-                return false;
+                return $ret;
             }
         }
         return $block;
@@ -459,6 +480,75 @@
         return $ret;
     }
 
+	/**
+	 * Return block instance array by $groupid, $mid and $blockFlag.
+	 * This function is new function of Cube and used from controller.
+	 * @author minahito
+	 */
+	function &getBlocks($groupid, $mid=false, $blockFlag=SHOW_BLOCK_ALL, $orderby='b.weight,b.bid')
+    {
+        $root =& XCube_Root::getSingleton();
+        $db =& $root->mController->getDB();
+
+        $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=1 AND b.visible=1 ';
+            if ($mid !== false && $mid !== 0) {
+                $sql .= ' AND m.module_id IN (0,'.intval($mid).')';
+            } else {
+                $sql .= ' AND m.module_id=0';
+            }
+
+            //
+            // SIDE
+            //
+            if ($blockFlag != SHOW_BLOCK_ALL) {
+				$arr = array();
+				if ($blockFlag & SHOW_SIDEBLOCK_LEFT) {
+					$arr[] = "b.side=" . $this->mBlockFlagMapping[SHOW_SIDEBLOCK_LEFT];
+				}
+				if ($blockFlag & SHOW_SIDEBLOCK_RIGHT) {
+					$arr[] = "b.side=" . $this->mBlockFlagMapping[SHOW_SIDEBLOCK_RIGHT];
+				}
+				if ($blockFlag & SHOW_CENTERBLOCK_LEFT) {
+					$arr[] = "b.side=" . $this->mBlockFlagMapping[SHOW_CENTERBLOCK_LEFT];
+				}
+				if ($blockFlag & SHOW_CENTERBLOCK_CENTER) {
+					$arr[] = "b.side=" . $this->mBlockFlagMapping[SHOW_CENTERBLOCK_CENTER];
+				}
+				if ($blockFlag & SHOW_CENTERBLOCK_RIGHT) {
+					$arr[] = "b.side=" . $this->mBlockFlagMapping[SHOW_CENTERBLOCK_RIGHT];
+				}
+				
+				$sql .= " AND (" . implode(" OR ", $arr) . ")";
+			}
+
+			$sql .= ' AND b.bid IN ('.implode(',', $blockids).')';
+            $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;
+    }
+
     function &getNonGroupedBlocks($module_id=0, $toponlyblock=false, $visible=null, $orderby='b.weight,b.bid', $isactive=1)
     {
         $db =& Database::getInstance();


xoops-cvslog メーリングリストの案内
Back to archive index