Minahito
minah****@users*****
2006年 5月 9日 (火) 19:21:10 JST
Index: xoops2jp/html/modules/base/class/image.php diff -u /dev/null xoops2jp/html/modules/base/class/image.php:1.1.2.1 --- /dev/null Tue May 9 19:21:10 2006 +++ xoops2jp/html/modules/base/class/image.php Tue May 9 19:21:10 2006 @@ -0,0 +1,39 @@ +<?php + +if (!defined('XOOPS_ROOT_PATH')) exit(); + +class BaseImageObject extends XoopsSimpleObject +{ + var $mImageCategory = null; + var $_mImageCategoryLoadedFlag = false; + + function BaseImageObject() + { + $this->initVar('image_id', XOBJ_DTYPE_INT, '', false); + $this->initVar('image_name', XOBJ_DTYPE_STRING, '', true, 30); + $this->initVar('image_nicename', XOBJ_DTYPE_STRING, '', true, 255); + $this->initVar('image_mimetype', XOBJ_DTYPE_STRING, '', true, 30); + $this->initVar('image_created', XOBJ_DTYPE_INT, time(), true); + $this->initVar('image_display', XOBJ_DTYPE_BOOL, '1', true); + $this->initVar('image_weight', XOBJ_DTYPE_INT, '0', true); + $this->initVar('imgcat_id', XOBJ_DTYPE_INT, '0', true); + } + + function loadImagecategory() + { + if ($this->_mImageCategoryLoadedFlag == false) { + $handler =& xoops_getmodulehandler('imagecategory'); + $this->mImageCategory =& $handler->get($this->get('imgcat_id')); + $this->_mImageCategoryLoadedFlag = true; + } + } +} + +class BaseImageHandler extends XoopsObjectGenericHandler +{ + var $mTable = "image"; + var $mPrimary = "image_id"; + var $mClass = "BaseImageObject"; +} + +?> Index: xoops2jp/html/modules/base/class/imagecategory.php diff -u /dev/null xoops2jp/html/modules/base/class/imagecategory.php:1.1.2.1 --- /dev/null Tue May 9 19:21:10 2006 +++ xoops2jp/html/modules/base/class/imagecategory.php Tue May 9 19:21:10 2006 @@ -0,0 +1,190 @@ +<?php + +if (!defined('XOOPS_ROOT_PATH')) exit(); + +class BaseImagecategoryObject extends XoopsSimpleObject +{ + var $mImage = array(); + var $_mImageLoadedFlag = false; + + /** + * Array of group objects which are allowed to read files of this category. + */ + var $mReadGroups = array(); + var $_mReadGroupsLoadedFlag = false; + + /** + * Array of group objects which are allowed to upload a file to this category. + */ + var $mUploadGroups = array(); + var $_mUploadGroupsLoadedFlag = false; + + + function BaseImagecategoryObject() + { + $this->initVar('imgcat_id', XOBJ_DTYPE_INT, '', false); + $this->initVar('imgcat_name', XOBJ_DTYPE_STRING, '', true, 100); + $this->initVar('imgcat_maxsize', XOBJ_DTYPE_INT, '50000', true); + $this->initVar('imgcat_maxwidth', XOBJ_DTYPE_INT, '120', true); + $this->initVar('imgcat_maxheight', XOBJ_DTYPE_INT, '120', true); + $this->initVar('imgcat_display', XOBJ_DTYPE_BOOL, '1', true); + $this->initVar('imgcat_weight', XOBJ_DTYPE_INT, '0', true); + $this->initVar('imgcat_type', XOBJ_DTYPE_STRING, 'C', true, 1); + $this->initVar('imgcat_storetype', XOBJ_DTYPE_STRING, 'file', true, 5); + } + + function loadImage() + { + if ($this->_mImageLoadedFlag == false) { + $handler =& xoops_getmodulehandler('image'); + $this->mImage =& $handler->getObjects(new Criteria('imagecat_id', $this->get('imagecat_id'))); + $this->_mImageLoadedFlag = true; + } + } + + function &createImage() + { + $handler =& xoops_getmodulehandler('image'); + $obj =& $handler->create(); + $obj->set('imagecat_id', $this->get('imagecat_id')); + return $obj; + } + + function loadReadGroups() + { + if ($this->_mReadGroupsLoadedFlag) { + return; + } + + $handler =& xoops_gethandler('groupperm'); + $gidArr = $handler->getGroupIds('imgcat_read', $this->get('imgcat_id')); + + $handler =& xoops_gethandler('group'); + foreach ($gidArr as $gid) { + $object =& $handler->get($gid); + + if (is_object($object)) { + $this->mReadGroups[] =& $object; + } + + unset($object); + } + + $this->_mReadGroupsLoadedFlag = true; + } + + function isLoadedReadGroups() + { + return $this->_mReadGroupsLoadedFlag; + } + + function loadUploadGroups() + { + if ($this->_mUploadGroupsLoadedFlag) { + return; + } + + $handler =& xoops_gethandler('groupperm'); + $gidArr = $handler->getGroupIds('imgcat_write', $this->get('imgcat_id')); + + $handler =& xoops_gethandler('group'); + foreach ($gidArr as $gid) { + $object =& $handler->get($gid); + + if (is_object($object)) { + $this->mUploadGroups[] =& $object; + } + + unset($object); + } + + $this->_mUploadGroupsLoadedFlag = true; + } + + function isLoadedUploadGroups() + { + return $this->_mUploadGroupsLoadedFlag; + } +} + +class BaseImagecategoryHandler extends XoopsObjectGenericHandler +{ + var $mTable = "imagecategory"; + var $mPrimary = "imgcat_id"; + var $mClass = "BaseImagecategoryObject"; + + function insert(&$obj, $force = false) + { + $returnFlag = parent::insert($obj, $force); + + $handler =& xoops_gethandler('groupperm'); + + // + // If the object has groups which are allowed to read. + // + if ($obj->isLoadedReadGroups()) { + $criteria =& new CriteriaCompo(); + $criteria->add(new Criteria('gperm_itemid', $obj->get('imgcat_id'))); + $criteria->add(new Criteria('gperm_modid', 1)); + $criteria->add(new Criteria('gperm_name', 'imgcat_read')); + $handler->deleteAll($criteria); + + foreach ($obj->mReadGroups as $group) { + $perm =& $handler->create(); + $perm->set('gperm_groupid', $group->get('groupid')); + $perm->set('gperm_itemid', $obj->get('imgcat_id')); + $perm->set('gperm_modid', 1); + $perm->set('gperm_name', 'imgcat_read'); + + $returnFlag &= $handler->insert($perm, $force); + } + } + + // + // If the object has groups which are allowed to upload. + // + if ($obj->isLoadedUploadGroups()) { + $criteria =& new CriteriaCompo(); + $criteria->add(new Criteria('gperm_itemid', $obj->get('imgcat_id'))); + $criteria->add(new Criteria('gperm_modid', 1)); + $criteria->add(new Criteria('gperm_name', 'imgcat_write')); + $handler->deleteAll($criteria); + + foreach ($obj->mUploadGroups as $group) { + $perm =& $handler->create(); + $perm->set('gperm_groupid', $group->get('groupid')); + $perm->set('gperm_itemid', $obj->get('imgcat_id')); + $perm->set('gperm_modid', 1); + $perm->set('gperm_name', 'imgcat_write'); + + $returnFlag &= $handler->insert($perm, $force); + } + } + + return $returnFlag; + } + + function delete(&$obj, $force = false) + { + $handler =& xoops_getmodulehandler('image'); + $handler->deleteAll(new Criteria('imagecat_id', $obj->get('imagecat_id'))); + unset($handler); + + $handler =& xoops_gethandler('groupperm'); + $criteria =& new CriteriaCompo(); + $criteria->add(new Criteria('gperm_itemid', $obj->get('imgcat_id'))); + $criteria->add(new Criteria('gperm_modid', 1)); + + $nameCriteria =& new CriteriaCompo(); + $nameCriteria->add(new Criteria('gperm_name', 'imgcat_read')); + $nameCriteria->add(new Criteria('gperm_name', 'imgcat_write'), 'OR'); + + $criteria->add($nameCriteria); + + $handler->deleteAll($criteria); + + return parent::delete($obj, $force); + } +} + +?>