function &get_xoonips_unregistered_users()
{
    global $xoopsDB;
    $users_handler =& xoonips_getormhandler('xoonips', 'xoops_users');
    $xusers_handler =& xoonips_getormhandler('xoonips', 'users');
    $criteria = new CriteriaElement();
    //  $criteria = new Criteria( 'level', '0', '>' );
    $criteria->setSort('uname');
    $users_objs =& $users_handler->getObjects($criteria);
    $users = array();
    $evenodd = 'odd';
    foreach ($users_objs as $users_obj) {
        $uid = $users_obj->getVar('uid', 's');
        $criteria = new Criteria('uid', $uid);
        if ($xusers_handler->getCount($criteria) == 0) {
            $user['uid'] = $uid;
            $user['uname'] = $users_obj->getVar('uname', 's');
            $user['name'] = $users_obj->getVar('name', 's');
            $user['email'] = $users_obj->getVar('email', 's');
            $user['uname_js'] = str_replace(''', '\\\'', $user['uname']);
            $user['register'] = _AM_XOONIPS_LABEL_REGISTER;
            $user['evenodd'] = $evenodd;
            $users[] = $user;
            $evenodd = $evenodd == 'even' ? 'odd' : 'even';
        }
    }
    return $users;
}
	function execute(&$controller, &$xoopsUser)
	{
		$filename = sprintf('%s User data List.csv', $GLOBALS['xoopsConfig']['sitename']);
		$text = '';
		$field_line = '';
		
		$user_handler =& $this->_getHandler();
		$criteria = new CriteriaElement();
		$criteria->setSort('uid');
		$users = $user_handler->getObjects($criteria);
		if (!$users || count($users)==0){
			return USER_FRAME_VIEW_INDEX;
		}
		foreach ($users[0]->gets() as $key=>$var){
			$_f = '_MD_USER_LANG_'.strtoupper($key);
			$field_line .= (defined($_f) ? constant($_f) : $key).",";
		}
		$field_line .= "\n";
		
		foreach ($users as $u){
			$user_data = '';
			foreach ($u->gets() as $key=>$value){
				switch ($key){
				  case 'user_regdate':
				  case 'last_login':
					$value = $value ? formatTimestamp($value, 'Y/n/j H:i') : '';
					break;
				  default:
				}
				if (preg_match('/[,"\r\n]/', $value)) {
					$value = preg_replace('/"/', "\"\"", $value);
					$value = "\"$value\"";
				}
				$user_data .= $value . ',';
			}
			$text .= trim($user_data, ',')."\n";
		}
		$text = $field_line.$text;
		
		/// japanese 
		if (strncasecmp($GLOBALS['xoopsConfig']['language'], 'ja', 2)===0){
			mb_convert_variables('SJIS', _CHARSET, $text);
		}
		
		if( preg_match('/firefox/i' , xoops_getenv('HTTP_USER_AGENT')) ){
			header("Content-Type: application/x-csv");
		}else{
			header("Content-Type: application/vnd.ms-excel");
		}
		
		
		header("Content-Disposition: attachment ; filename=\"{$filename}\"") ;
		exit($text);
	}
 function getPositionList($fmt)
 {
     $criteria = new CriteriaElement();
     $criteria->setSort('posi_order');
     $objs =& $this->getObjects($criteria);
     $positionlist = array();
     foreach ($objs as $obj) {
         $posi_id = $obj->getVar('posi_id', 'n');
         $positionlist[$posi_id] = $obj->getVarArray($fmt);
     }
     return $positionlist;
 }
	function execute()
	{
		$filename = sprintf('%s_Profile_data_List.csv', $GLOBALS['xoopsConfig']['sitename']);
		$text = '';
		$field_line = 'uid,';
		
		$handler =& $this->_getHandler();
		$defHandler =& xoops_getmodulehandler('definitions');
		$defArr =& $defHandler->getDefinitions(false);
	
		$criteria = new CriteriaElement();
		$criteria->setSort('uid');
		$dataArr = $handler->getObjects($criteria);
		if (count($dataArr)==0){
			return PROFILE_FRAME_VIEW_INDEX;
		}
		foreach (array_keys($defArr) as $key){
			$field_line .= $var['label'].",";
		}
		$field_line .= "\n";
		
		foreach ($dataArr as $profile){
			$profile_data = '';
			foreach ($profile->gets() as $key=>$value){
				if($defArr[$key]->get('type')=='date'){
					$value = $value ? formatTimestamp($value, 'Y/n/j H:i') : '';				}
				if (preg_match('/[,"\r\n]/', $value)) {
					$value = preg_replace('/"/', "\"\"", $value);
					$value = "\"$value\"";
				}
				$profile_data .= $value . ',';
			}
			$text .= trim($profile_data, ',')."\n";
		}
		$text = $field_line.$text;
		
		/// japanese 
		if (strncasecmp($GLOBALS['xoopsConfig']['language'], 'ja', 2)===0){
			mb_convert_variables('SJIS', _CHARSET, $text);
		}
		
		if( preg_match('/firefox/i' , xoops_getenv('HTTP_USER_AGENT')) ){
			header("Content-Type: application/x-csv");
		}else{
			header("Content-Type: application/vnd.ms-excel");
		}
		
		
		header("Content-Disposition: attachment ; filename=\"{$filename}\"") ;
		exit($text);
	}
function getUserPosiList()
{
    $posi_handler =& xoonips_getormhandler('xoonips', 'positions');
    $criteria = new CriteriaElement();
    $criteria->setSort('posi_order');
    $criteria->setOrder(ASC);
    $posi_objs =& $posi_handler->getObjects($criteria, false, 'posi_id, posi_title');
    $ret = array();
    foreach ($posi_objs as $posi_obj) {
        $posi_id = $posi_obj->getVar('posi_id', 's');
        $posi_title = $posi_obj->getVar('posi_title', 'e');
        $ret[$posi_id] = $posi_title;
    }
    return $ret;
}
 public function beforeDelete()
 {
     if ($this->getOwner()->getGalleryId()) {
         $mapper = Manager::getInstance()->getMapper($this->mapper_alias);
         $aContainer = $mapper->getContainer();
         $categoryId = $this->getOwner()->getGalleryId();
         // Удаляем все записи о фотках из базы
         $oQuery = new DbUpdater(DbUpdater::TYPE_DELETE, $aContainer['TableName'], $aContainer['Object'], $this->getDbConnectionAlias());
         $oCriteria = new CriteriaElement('category_id', Criteria::EQUAL, $categoryId);
         $oQuery->addCriteria($mapper->parseUpdateCriteria($oCriteria->renderWhere()));
         $oQuery->delete();
         $this->getOwner()->getGallery()->delete();
     }
     return true;
 }
 /**
  * delete old entries for updating/rebuilding rankings
  *
  * @param int $num_rows number of new entries
  * @return bool FALSE if failed
  */
 function trim($num_rows)
 {
     $field = 'timestamp';
     $criteria = new CriteriaElement();
     $criteria->setSort('timestamp');
     $criteria->setOrder('DESC');
     $criteria->setStart($num_rows);
     $criteria->setLimit(1);
     $objs =& $this->getObjects($criteria, false, $field);
     if (empty($objs)) {
         return true;
     }
     $timestamp = $objs[0]->get('timestamp');
     $criteria = new Criteria($field, $timestamp, '<');
     // force deletion
     if (!$this->deleteAll($criteria, true)) {
         return false;
     }
     return true;
 }
function &account_get_userlist($limit, $start, $sort)
{
    global $xoopsDB;
    $users_handler =& xoonips_getormhandler('xoonips', 'xoops_users');
    $tables['users'] = $xoopsDB->prefix('users');
    $join_criteria = new XooNIpsJoinCriteria('xoonips_users', 'uid', 'uid', 'INNER');
    $criteria = new CriteriaElement();
    $sort_arr = array();
    foreach ($sort as $so) {
        $sort_arr[] = $tables['users'] . '.' . $so;
    }
    if (!empty($sort_arr)) {
        $criteria->setSort($sort_arr);
    }
    $criteria->setLimit($limit);
    $criteria->setStart($start);
    $fields = array();
    $fields[] = $tables['users'] . '.uid';
    $fields[] = $tables['users'] . '.name';
    $fields[] = $tables['users'] . '.uname';
    $fields[] = $tables['users'] . '.email';
    $users_objs =& $users_handler->getObjects($criteria, false, implode(',', $fields), false, $join_criteria);
    return $users_objs;
}
Example #9
0
 protected function update($table, $data, $pk)
 {
     $oQuery = new DbUpdater(DbUpdater::TYPE_UPDATE, $table, 't', $this->dbConnection);
     $oQuery->setElement($data);
     $oCriteria = new CriteriaElement('id', Criteria::EQUAL, $pk);
     $oQuery->addCriteria($oCriteria->renderWhere());
     $oQuery->update();
 }
Example #10
0
 protected function updateTableData($table, $data)
 {
     if (isset($data['Insert'])) {
         foreach ($data['Insert'] as $insert) {
             $oQuery = new DbUpdater(DbUpdater::TYPE_INSERT, $table, 't', $this->_dbConnection);
             $oQuery->setElement($insert);
             $oQuery->insert();
         }
     }
     if (isset($data['Update'])) {
         foreach ($data['Update'] as $insert) {
             $oQuery = new DbUpdater(DbUpdater::TYPE_UPDATE, $table, 't', $this->_dbConnection);
             $oQuery->setElement($insert);
             $oCriteria = new CriteriaElement('id', Criteria::EQUAL, $insert['id']);
             $oQuery->addCriteria($oCriteria->renderWhere());
             $oQuery->update();
         }
     }
 }
 function setRepositories(&$repositories)
 {
     // parse new repositories
     $new_repos_url = array();
     $new_repos_enabled = array();
     $new_repos_exist = array();
     foreach ($repositories as $repo) {
         $url = trim($repo);
         // remove empty line
         if (empty($url)) {
             continue;
         }
         // remove duplicated url
         if (in_array($url, $new_repos_url)) {
             continue;
         }
         // check 'enable' or 'disable'
         if (preg_match('/^(;|#)(.*)$/', $url, $matches)) {
             $enabled = 0;
             // remove empty comment line
             if (trim($matches[2]) == '') {
                 continue;
             }
         } else {
             $enabled = 1;
         }
         $new_repos_url[] = $url;
         $new_repos_enabled[] = $enabled;
         $new_repos_exist[] = false;
     }
     // get all recorded repositories
     $criteria = new CriteriaElement();
     $criteria->setSort('sort');
     $recorded_objs =& $this->getObjects($criteria, true);
     foreach ($recorded_objs as $obj) {
         // find existing repository
         $rec_url = $obj->getVar('URL', 'n');
         $found = false;
         $found_repo = null;
         foreach ($new_repos_url as $sort => $new_url) {
             // use first match entry
             if ($new_repos_exist[$sort] == false) {
                 if ($rec_url == $new_url) {
                     $found = true;
                     $new_repos_exist[$sort] = true;
                     break;
                 }
             }
         }
         if ($found) {
             // update entry
             $obj->set('sort', $sort);
             $obj->set('enabled', $new_repos_enabled[$sort]);
             $obj->set('deleted', 0);
         } else {
             // remove entry ( set deleted flag )
             $obj->set('sort', 0);
             $obj->set('enabled', 0);
             $obj->set('deleted', 1);
         }
         $this->insert($obj);
     }
     // add new repositories
     foreach ($new_repos_exist as $sort => $new_exist) {
         if (!$new_exist) {
             $obj =& $this->create();
             $obj->set('sort', $sort);
             $obj->set('URL', $new_repos_url[$sort]);
             $obj->set('enabled', $new_repos_enabled[$sort]);
             $obj->set('deleted', 0);
             $this->insert($obj);
         }
     }
 }
 function &getCriteria()
 {
     $criteria = new CriteriaElement();
     if ($this->_order) {
         $criteria->SetOrder($this->_order);
     }
     if ($this->_sort) {
         $criteria->SetSort($this->_sort);
     }
     $criteria->SetLimit($this->_limit);
     $criteria->SetStart($this->_start);
     return $criteria;
 }
Example #13
0
 protected function saveForRelationData($oObject, $before = false)
 {
     $saveForRelation = $before ? $oObject->aForSaveRelationsDataBefore : $oObject->aForSaveRelationsData;
     $objectId = $before ? 0 : (int) $oObject->getId();
     if (!empty($saveForRelation)) {
         $relations = $this->relations();
         foreach ($saveForRelation as $rel => $val) {
             $relation = $relations[$rel];
             foreach ($val as $action => $data) {
                 $oRelMapper = Manager::getInstance()->getMapper($relation['ToMapperAlias']);
                 $aRelContainer = $oRelMapper->getContainer();
                 $sRelClassName = $aRelContainer['Object'];
                 switch ($action) {
                     case 'Delete':
                         // Удаляем все что есть
                         $oQuery = new DbUpdater(DbUpdater::TYPE_DELETE, $relation['TableName'], $sRelClassName, $this->getDbConnectionAlias());
                         $oCriteria = new CriteriaElement($relation['Field2'], Criteria::EQUAL, $objectId);
                         $oQuery->addCriteria($this->parseUpdateCriteria($oCriteria->renderWhere()));
                         $oQuery->delete();
                         break;
                     case 'Add':
                         // сохраняем в базу
                         if (is_array($data)) {
                             foreach ($data as $data_val) {
                                 $oQuery = new DbUpdater(DbUpdater::TYPE_INSERT, $relation['TableName'], $sRelClassName, $this->getDbConnectionAlias());
                                 $oQuery->setElement(array($relation['Field'] => $data_val, $relation['Field2'] => $objectId));
                                 $oQuery->insert();
                             }
                         }
                         break;
                         // Has Many
                     // Has Many
                     case 'Set':
                         if (is_array($data)) {
                             $result = new SimpleCollection();
                             foreach ($data as $itm) {
                                 if (!empty($itm['Id'])) {
                                     $obj = $oRelMapper->findById($itm['Id']);
                                 } else {
                                     $obj = $oRelMapper->create();
                                 }
                                 unset($itm['Id']);
                                 $obj->import($itm);
                                 $obj->set($relation['Field'], $objectId);
                                 $obj->save();
                                 $result->add($obj);
                             }
                         }
                         break;
                         // Belongs To
                     // Belongs To
                     case 'SetOne':
                         if (is_array($data)) {
                             if (!empty($data['Id'])) {
                                 $obj = $oRelMapper->findById($data['Id']);
                             } else {
                                 $obj = $oRelMapper->create($data);
                             }
                             unset($data['Id']);
                             $obj->import($data);
                             $id = $obj->save();
                             $oObject->set($relation['Field'], $id);
                             $oObject->set($rel, $obj);
                         } else {
                             if (is_object($data)) {
                                 if (!$data->getId()) {
                                     $data->save();
                                 }
                                 $oObject->set($rel, $data);
                             }
                         }
                         break;
                 }
             }
         }
         if ($before) {
             $oObject->aForSaveRelationsDataBefore = array();
         } else {
             $oObject->aForSaveRelationsData = array();
         }
         return true;
     }
     return false;
 }
/**
 * get user objects from database
 *
 * @access public
 * @param int $start number of skip results
 * @param int $limit number of results, zero means unlimit
 * @return array object instance
 */
function &xoonips_eventlog_get_users($start, $limit)
{
    $xuhandler =& xoonips_getormhandler('xoonips', 'users');
    $join_criteria = new XooNIpsJoinCriteria('users', 'uid', 'uid', 'INNER', 'users');
    $criteria = new CriteriaElement();
    $criteria->setSort('uname');
    $criteria->setStart($start);
    if ($limit > 0) {
        $criteria->setLimit($limit);
    }
    $objs =& $xuhandler->getObjects($criteria, false, '', false, $join_criteria);
    return $objs;
}
function xoonips_ranking_show($is_arrival)
{
    global $xoopsUser;
    // load xoonips config handler
    $xconfig_handler =& xoonips_getormhandler('xoonips', 'config');
    // hide block if user is guest and public index viewing policy is 'platform'
    if (!is_object($xoopsUser)) {
        $target_user = $xconfig_handler->getValue('public_item_target_user');
        if ($target_user != 'all') {
            // 'platform'
            return false;
        }
    }
    $uid = is_object($xoopsUser) ? $xoopsUser->getVar('uid', 'n') : UID_GUEST;
    // hide block if user is invalid xoonips user
    $xsession_handler =& xoonips_getormhandler('xoonips', 'session');
    if (!$xsession_handler->validateUser($uid, false)) {
        return false;
    }
    // load utility class
    $textutil =& xoonips_getutility('text');
    $etc = '...';
    // decide maximum string length by block position
    if (defined('XOOPS_CUBE_LEGACY')) {
        // get xoonips module id
        $mydirname = basename(dirname(__DIR__));
        $module_handler =& xoops_gethandler('module');
        $module =& $module_handler->getByDirname($mydirname);
        $mid = $module->getVar('mid', 's');
        // get block array
        $block_arr =& XoopsBlock::getByModule($mid);
    } else {
        global $block_arr;
    }
    $myfunc = $is_arrival ? 'b_xoonips_ranking_new_show' : 'b_xoonips_ranking_show';
    $maxlen = 56;
    // default
    foreach ($block_arr as $b) {
        $func = $b->getVar('show_func', 'n');
        if ($func == $myfunc) {
            $side = $b->getVar('side', 'n');
            if ($side == XOOPS_SIDEBLOCK_LEFT || $side == XOOPS_SIDEBLOCK_RIGHT) {
                $maxlen = 16;
                break;
            } else {
                if ($side == XOOPS_CENTERBLOCK_LEFT || $side == XOOPS_CENTERBLOCK_RIGHT) {
                    $maxlen = 24;
                    break;
                }
            }
        }
    }
    // get configs
    $config_names = array('num_rows', 'visible', 'order');
    $new_str = $is_arrival ? 'new_' : '';
    foreach ($config_names as $name) {
        $config[$name] = $xconfig_handler->getValue('ranking_' . $new_str . $name);
    }
    $config['visible'] = explode(',', $config['visible']);
    $config['order'] = explode(',', $config['order']);
    // update rankings
    $ranking_handler =& xoonips_gethandler('xoonips', 'ranking');
    $ranking_handler->update();
    // get rankings from database
    // - set item permission criteria and join criteria
    $iperm_criteria = new CriteriaCompo();
    $iperm_criteria->add(new Criteria('title_id', 0, '=', 'tt'));
    $iperm_criteria->add(new Criteria('open_level', OL_PUBLIC, '=', 'tx'));
    $iperm_criteria->add(new Criteria('certify_state', CERTIFIED, '=', 'txil'));
    $iperm_join = new XooNIpsJoinCriteria('xoonips_item_basic', 'item_id', 'item_id', 'INNER', 'tb');
    $iperm_join->cascade(new XooNIpsJoinCriteria('xoonips_item_title', 'item_id', 'item_id', 'INNER', 'tt'));
    $iperm_join->cascade(new XooNIpsJoinCriteria('xoonips_index_item_link', 'item_id', 'item_id', 'INNER', 'txil'));
    $iperm_join->cascade(new XooNIpsJoinCriteria('xoonips_index', 'index_id', 'index_id', 'INNER', 'tx'), 'txil', true);
    // - set ranking number label
    $rank_tmp = explode(',', _MB_XOONIPS_RANKING_RANK_STR);
    $rank_str = array();
    for ($i = 0; $i < $config['num_rows']; $i++) {
        $rank_str[] = $i + 1 . $rank_tmp[min($i, count($rank_tmp) - 1)];
    }
    $block['rankings'] = array();
    if ($is_arrival) {
        // new arrival block
        // ranking new item
        if ($config['visible'][0]) {
            $table = 'ranking_new_item';
            $label = _MB_XOONIPS_RANKING_NEW_ITEM;
            $fields = 'tb.item_id, tt.title, DATE_FORMAT(timestamp,\'%m/%d\'), tb.doi';
            $criteria = $iperm_criteria;
            $criteria->setGroupby('tb.item_id');
            $criteria->setLimit($config['num_rows']);
            $criteria->setSort('timestamp');
            $criteria->setOrder('DESC');
            $join = $iperm_join;
            $handler =& xoonips_getormhandler('xoonips', $table);
            $res =& $handler->open($criteria, $fields, false, $join);
            $items = array();
            $i = 0;
            while ($obj =& $handler->getNext($res)) {
                $item_id = $obj->getVar('item_id', 'n');
                $title = $textutil->html_special_chars($obj->getExtraVar('title'));
                $title = $textutil->truncate($title, $maxlen, $etc);
                $count = $textutil->html_special_chars($obj->getExtraVar('DATE_FORMAT(timestamp,\'%m/%d\')'));
                $doi = $textutil->html_special_chars($obj->getExtraVar('doi'));
                $id = $doi == '' && XNP_CONFIG_DOI_FIELD_PARAM_NAME != '' ? 'item_id=' . $item_id : XNP_CONFIG_DOI_FIELD_PARAM_NAME . '=' . urlencode($doi);
                $url = XOOPS_URL . '/modules/xoonips/detail.php?' . $id;
                $items[] = array('title' => $title, 'url' => $url, 'num' => $count, 'rank_str' => $rank_str[$i]);
                $i++;
            }
            $handler->close($res);
            $block['rankings'][$config['order'][0]] = array('items' => $items, 'title' => $label);
            unset($items);
        }
        // ranking new group
        if ($config['visible'][1]) {
            $table = 'ranking_new_group';
            $label = _MB_XOONIPS_RANKING_NEW_GROUP;
            $fields = 'tg.gid, tg.gname, DATE_FORMAT(timestamp,\'%m/%d\')';
            $criteria = new CriteriaElement();
            $criteria->setLimit($config['num_rows']);
            $criteria->setSort('timestamp');
            $criteria->setOrder('DESC');
            $join = new XooNIpsJoinCriteria('xoonips_groups', 'gid', 'gid', 'INNER', 'tg');
            $handler =& xoonips_getormhandler('xoonips', $table);
            $res =& $handler->open($criteria, $fields, false, $join);
            $items = array();
            $i = 0;
            while ($obj =& $handler->getNext($res)) {
                $gid = $obj->getVar('gid', 'n');
                $title = $textutil->html_special_chars($obj->getExtraVar('gname'));
                $title = $textutil->truncate($title, $maxlen, $etc);
                $count = $textutil->html_special_chars($obj->getExtraVar('DATE_FORMAT(timestamp,\'%m/%d\')'));
                $url = XOOPS_URL . '/modules/xoonips/groups.php';
                $items[] = array('title' => $title, 'url' => $url, 'num' => $count, 'rank_str' => $rank_str[$i]);
                $i++;
            }
            $handler->close($res);
            $block['rankings'][$config['order'][1]] = array('items' => $items, 'title' => $label);
            unset($items);
        }
    } else {
        // ranking block
        // ranking viewed item
        if ($config['visible'][0]) {
            $table = 'ranking_viewed_item';
            $label = _MB_XOONIPS_RANKING_VIEWED_ITEM;
            $fields = 'tb.item_id, tt.title, count';
            $criteria = $iperm_criteria;
            $criteria->add(new Criteria('count', 0, '<>'));
            $criteria->setLimit($config['num_rows']);
            $criteria->setSort('count');
            $criteria->setOrder('DESC');
            $join = $iperm_join;
            $handler =& xoonips_getormhandler('xoonips', $table);
            $res =& $handler->open($criteria, $fields, true, $join);
            $items = array();
            $i = 0;
            while ($obj =& $handler->getNext($res)) {
                $item_id = $obj->getVar('item_id', 'n');
                $title = $textutil->html_special_chars($obj->getExtraVar('title'));
                $title = $textutil->truncate($title, $maxlen, $etc);
                $count = $obj->getVar('count', 'n');
                $doi = $textutil->html_special_chars($obj->getExtraVar('doi'));
                $id = $doi == '' && XNP_CONFIG_DOI_FIELD_PARAM_NAME != '' ? 'item_id=' . $item_id : XNP_CONFIG_DOI_FIELD_PARAM_NAME . '=' . urlencode($doi);
                $url = XOOPS_URL . '/modules/xoonips/detail.php?' . $id;
                $items[] = array('title' => $title, 'url' => $url, 'num' => $count, 'rank_str' => $rank_str[$i]);
                $i++;
            }
            $handler->close($res);
            $block['rankings'][$config['order'][0]] = array('items' => $items, 'title' => $label);
            unset($items);
        }
        // ranking downloaded item
        if ($config['visible'][1]) {
            $table = 'ranking_downloaded_item';
            $label = _MB_XOONIPS_RANKING_DOWNLOADED_ITEM;
            $fields = 'tb.item_id, tt.title, count';
            $criteria = $iperm_criteria;
            $criteria->add(new Criteria('count', 0, '<>'));
            $criteria->setLimit($config['num_rows']);
            $criteria->setSort('count');
            $criteria->setOrder('DESC');
            $join = $iperm_join;
            $handler =& xoonips_getormhandler('xoonips', $table);
            $res =& $handler->open($criteria, $fields, true, $join);
            $items = array();
            $i = 0;
            while ($obj =& $handler->getNext($res)) {
                $item_id = $obj->getVar('item_id', 'n');
                $title = $textutil->html_special_chars($obj->getExtraVar('title'));
                $title = $textutil->truncate($title, $maxlen, $etc);
                $count = $obj->getVar('count', 'n');
                $doi = $textutil->html_special_chars($obj->getExtraVar('doi'));
                $id = $doi == '' && XNP_CONFIG_DOI_FIELD_PARAM_NAME != '' ? 'item_id=' . $item_id : XNP_CONFIG_DOI_FIELD_PARAM_NAME . '=' . urlencode($doi);
                $url = XOOPS_URL . '/modules/xoonips/detail.php?' . $id;
                $items[] = array('title' => $title, 'url' => $url, 'num' => $count, 'rank_str' => $rank_str[$i]);
                $i++;
            }
            $handler->close($res);
            $block['rankings'][$config['order'][1]] = array('items' => $items, 'title' => $label);
            unset($items);
        }
        // ranking contiributing user
        if ($config['visible'][2]) {
            $table = 'ranking_contributing_user';
            $label = _MB_XOONIPS_RANKING_CONTRIBUTING_USER;
            $fields = 'tu.uid, tu.uname, COUNT(*) AS count';
            $criteria = new CriteriaElement();
            $criteria->setLimit($config['num_rows']);
            $criteria->setSort('count');
            $criteria->setOrder('DESC');
            $criteria->setGroupby('tu.uid');
            $join = new XooNIpsJoinCriteria('users', 'uid', 'uid', 'INNER', 'tu');
            $handler =& xoonips_getormhandler('xoonips', $table);
            $res =& $handler->open($criteria, $fields, true, $join);
            $items = array();
            $i = 0;
            while ($obj =& $handler->getNext($res)) {
                $uid = $obj->getVar('uid', 'n');
                $title = $textutil->html_special_chars($obj->getExtraVar('uname'));
                $title = $textutil->truncate($title, $maxlen, $etc);
                $count = intval($obj->getExtraVar('count'));
                $url = XOOPS_URL . '/modules/xoonips/showusers.php?uid=' . $uid;
                $items[] = array('title' => $title, 'url' => $url, 'num' => $count, 'rank_str' => $rank_str[$i]);
                $i++;
            }
            $handler->close($res);
            $block['rankings'][$config['order'][2]] = array('items' => $items, 'title' => $label);
            unset($items);
        }
        // ranking searched keyword
        if ($config['visible'][3]) {
            $table = 'ranking_searched_keyword';
            $label = _MB_XOONIPS_RANKING_SEARCHED_KEYWORD;
            $fields = 'keyword, count';
            $criteria = new CriteriaCompo(new Criteria('count', 0, '<>'));
            $criteria->add(new Criteria('keyword', '', '!='));
            // ignore empty
            $criteria->setLimit($config['num_rows']);
            $criteria->setSort('count');
            $criteria->setOrder('DESC');
            $handler =& xoonips_getormhandler('xoonips', $table);
            $res =& $handler->open($criteria, $fields, true);
            $items = array();
            $i = 0;
            while ($obj =& $handler->getNext($res)) {
                $keyword = $obj->getVar('keyword', 'n');
                $title = $textutil->html_special_chars($keyword);
                $title = preg_replace('/[\\x00-\\x20]/se', 'urlencode("\\0")', $title);
                $title = $textutil->truncate($title, $maxlen, $etc);
                $count = $obj->getVar('count', 'n');
                $url = XOOPS_URL . '/modules/xoonips/itemselect.php?op=quicksearch&amp;search_itemtype=all&amp;keyword=' . urlencode($keyword);
                $items[] = array('title' => $title, 'url' => $url, 'num' => $count, 'rank_str' => $rank_str[$i]);
                $i++;
            }
            $handler->close($res);
            $block['rankings'][$config['order'][3]] = array('items' => $items, 'title' => $label);
            unset($items);
        }
        if ($config['visible'][4]) {
            // ranking active group
            $table = 'ranking_active_group';
            $label = _MB_XOONIPS_RANKING_CONTRIBUTED_GROUP;
            $fields = 'tg.gid, tg.gname, count';
            $criteria = new Criteria('count', 0, '<>');
            $criteria->setLimit($config['num_rows']);
            $criteria->setSort('count');
            $criteria->setOrder('DESC');
            $join = new XooNIpsJoinCriteria('xoonips_groups', 'gid', 'gid', 'INNER', 'tg');
            $handler =& xoonips_getormhandler('xoonips', $table);
            $res =& $handler->open($criteria, $fields, false, $join);
            $items = array();
            $i = 0;
            while ($obj =& $handler->getNext($res)) {
                $gid = $obj->getVar('gid', 'n');
                $title = $textutil->html_special_chars($obj->getExtraVar('gname'));
                $title = $textutil->truncate($title, $maxlen, $etc);
                $count = $obj->getVar('count', 'n');
                $url = XOOPS_URL . '/modules/xoonips/groups.php';
                $items[] = array('title' => $title, 'url' => $url, 'num' => $count, 'rank_str' => $rank_str[$i]);
                $i++;
            }
            $handler->close($res);
            $block['rankings'][$config['order'][4]] = array('items' => $items, 'title' => $label);
            unset($items);
        }
    }
    ksort($block['rankings']);
    return $block;
}