本文整理汇总了PHP中IP::hexToQuad方法的典型用法代码示例。如果您正苦于以下问题:PHP IP::hexToQuad方法的具体用法?PHP IP::hexToQuad怎么用?PHP IP::hexToQuad使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IP
的用法示例。
在下文中一共展示了IP::hexToQuad方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testHexToQuad
/**
* @covers IP::hexToQuad
*/
public function testHexToQuad()
{
$this->assertEquals('0.0.0.1', IP::hexToQuad('00000001'));
$this->assertEquals('255.0.0.0', IP::hexToQuad('FF000000'));
$this->assertEquals('255.255.255.255', IP::hexToQuad('FFFFFFFF'));
$this->assertEquals('10.188.222.255', IP::hexToQuad('0ABCDEFF'));
// hex not left-padded...
$this->assertEquals('0.0.0.0', IP::hexToQuad('0'));
$this->assertEquals('0.0.0.1', IP::hexToQuad('1'));
$this->assertEquals('0.0.0.255', IP::hexToQuad('FF'));
$this->assertEquals('0.0.255.0', IP::hexToQuad('FF00'));
}
示例2: execute
//.........这里部分代码省略.........
$lower = $upper = IP::toHex($params['ip']);
}
$prefix = substr($lower, 0, 4);
# Fairly hard to make a malicious SQL statement out of hex characters,
# but it is good practice to add quotes
$lower = $db->addQuotes($lower);
$upper = $db->addQuotes($upper);
$this->addWhere(array('ipb_range_start' . $db->buildLike($prefix, $db->anyString()), 'ipb_range_start <= ' . $lower, 'ipb_range_end >= ' . $upper, 'ipb_auto' => 0));
}
if (!is_null($params['show'])) {
$show = array_flip($params['show']);
/* Check for conflicting parameters. */
if (isset($show['account']) && isset($show['!account']) || isset($show['ip']) && isset($show['!ip']) || isset($show['range']) && isset($show['!range']) || isset($show['temp']) && isset($show['!temp'])) {
$this->dieUsageMsg('show');
}
$this->addWhereIf('ipb_user = 0', isset($show['!account']));
$this->addWhereIf('ipb_user != 0', isset($show['account']));
$this->addWhereIf('ipb_user != 0 OR ipb_range_end > ipb_range_start', isset($show['!ip']));
$this->addWhereIf('ipb_user = 0 AND ipb_range_end = ipb_range_start', isset($show['ip']));
$this->addWhereIf('ipb_expiry = ' . $db->addQuotes($db->getInfinity()), isset($show['!temp']));
$this->addWhereIf('ipb_expiry != ' . $db->addQuotes($db->getInfinity()), isset($show['temp']));
$this->addWhereIf("ipb_range_end = ipb_range_start", isset($show['!range']));
$this->addWhereIf("ipb_range_end > ipb_range_start", isset($show['range']));
}
if (!$this->getUser()->isAllowed('hideuser')) {
$this->addWhereFld('ipb_deleted', 0);
}
// Purge expired entries on one in every 10 queries
if (!mt_rand(0, 10)) {
Block::purgeExpired();
}
$res = $this->select(__METHOD__);
$count = 0;
foreach ($res as $row) {
if (++$count > $params['limit']) {
// We've had enough
$this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->ipb_timestamp));
break;
}
$block = array();
if ($fld_id) {
$block['id'] = $row->ipb_id;
}
if ($fld_user && !$row->ipb_auto) {
$block['user'] = $row->ipb_address;
}
if ($fld_userid && !$row->ipb_auto) {
$block['userid'] = $row->ipb_user;
}
if ($fld_by) {
$block['by'] = $row->ipb_by_text;
}
if ($fld_byid) {
$block['byid'] = $row->ipb_by;
}
if ($fld_timestamp) {
$block['timestamp'] = wfTimestamp(TS_ISO_8601, $row->ipb_timestamp);
}
if ($fld_expiry) {
$block['expiry'] = $wgContLang->formatExpiry($row->ipb_expiry, TS_ISO_8601);
}
if ($fld_reason) {
$block['reason'] = $row->ipb_reason;
}
if ($fld_range && !$row->ipb_auto) {
$block['rangestart'] = IP::hexToQuad($row->ipb_range_start);
$block['rangeend'] = IP::hexToQuad($row->ipb_range_end);
}
if ($fld_flags) {
// For clarity, these flags use the same names as their action=block counterparts
if ($row->ipb_auto) {
$block['automatic'] = '';
}
if ($row->ipb_anon_only) {
$block['anononly'] = '';
}
if ($row->ipb_create_account) {
$block['nocreate'] = '';
}
if ($row->ipb_enable_autoblock) {
$block['autoblock'] = '';
}
if ($row->ipb_block_email) {
$block['noemail'] = '';
}
if ($row->ipb_deleted) {
$block['hidden'] = '';
}
if ($row->ipb_allow_usertalk) {
$block['allowusertalk'] = '';
}
}
$fit = $result->addValue(array('query', $this->getModuleName()), null, $block);
if (!$fit) {
$this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->ipb_timestamp));
break;
}
}
$result->setIndexedTagName_internal(array('query', $this->getModuleName()), 'block');
}
示例3: testHexToQuad
/**
* @covers IP::hexToQuad
* @dataProvider provideIPsAndHexes
*/
public function testHexToQuad($ip, $hex)
{
$this->assertEquals($ip, IP::hexToQuad($hex));
}
示例4: execute
public function execute()
{
$params = $this->extractRequestParams();
$prop = array_flip($params['prop']);
$fld_id = isset($prop['id']);
$fld_address = isset($prop['address']);
$fld_by = isset($prop['by']);
$fld_timestamp = isset($prop['timestamp']);
$fld_expiry = isset($prop['expiry']);
$fld_reason = isset($prop['reason']);
$fld_range = isset($prop['range']);
$result = $this->getResult();
$data = array();
$this->addTables('globalblocks');
if ($fld_id) {
$this->addFields('gb_id');
}
if ($fld_address) {
$this->addFields(array('gb_address', 'gb_anon_only'));
}
if ($fld_by) {
$this->addFields(array('gb_by', 'gb_by_wiki'));
}
if ($fld_timestamp) {
$this->addFields('gb_timestamp');
}
if ($fld_expiry) {
$this->addFields('gb_expiry');
}
if ($fld_reason) {
$this->addFields('gb_reason');
}
if ($fld_range) {
$this->addFields(array('gb_range_start', 'gb_range_end'));
}
$this->addOption('LIMIT', $params['limit'] + 1);
$this->addWhereRange('gb_timestamp', $params['dir'], $params['start'], $params['end']);
if (isset($params['ids'])) {
$this->addWhereFld('gb_id', $params['ids']);
}
if (isset($params['addresses'])) {
$this->addWhereFld('gb_address', $params['addresses']);
}
if (isset($params['ip'])) {
list($ip, $range) = IP::parseCIDR($params['ip']);
if ($ip && $range) {
# We got a CIDR range
if ($range < 16) {
$this->dieUsage('CIDR ranges broader than /16 are not accepted', 'cidrtoobroad');
}
$lower = wfBaseConvert($ip, 10, 16, 8, false);
$upper = wfBaseConvert($ip + pow(2, 32 - $range) - 1, 10, 16, 8, false);
} else {
$lower = $upper = IP::toHex($params['ip']);
}
$prefix = substr($lower, 0, 4);
$this->addWhere(array("gb_range_start LIKE '{$prefix}%'", "gb_range_start <= '{$lower}'", "gb_range_end >= '{$upper}'"));
}
$res = $this->select(__METHOD__);
$count = 0;
foreach ($res as $row) {
if (++$count > $params['limit']) {
// We've had enough
$this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->gb_timestamp));
break;
}
$block = array();
if ($fld_id) {
$block['id'] = $row->gb_id;
}
if ($fld_address) {
$block['address'] = $row->gb_address;
if ($row->gb_anon_only) {
$block['anononly'] = '';
}
}
if ($fld_by) {
$block['by'] = $row->gb_by;
$block['bywiki'] = $row->gb_by_wiki;
}
if ($fld_timestamp) {
$block['timestamp'] = wfTimestamp(TS_ISO_8601, $row->gb_timestamp);
}
if ($fld_expiry) {
$block['expiry'] = Block::decodeExpiry($row->gb_expiry, TS_ISO_8601);
}
if ($fld_reason) {
$block['reason'] = $row->gb_reason;
}
if ($fld_range) {
$block['rangestart'] = IP::hexToQuad($row->gb_range_start);
$block['rangeend'] = IP::hexToQuad($row->gb_range_end);
}
$data[] = $block;
}
$result->setIndexedTagName($data, 'block');
$result->addValue('query', $this->getModuleName(), $data);
}
示例5: execute
//.........这里部分代码省略.........
}
if ($fld_range) {
$this->addFields(array('ipb_range_start', 'ipb_range_end'));
}
if ($fld_flags) {
$this->addFields(array('ipb_auto', 'ipb_anon_only', 'ipb_create_account', 'ipb_enable_autoblock', 'ipb_block_email', 'ipb_deleted', 'ipb_allow_usertalk'));
}
$this->addOption('LIMIT', $params['limit'] + 1);
$this->addWhereRange('ipb_timestamp', $params['dir'], $params['start'], $params['end']);
if (isset($params['ids'])) {
$this->addWhereFld('ipb_id', $params['ids']);
}
if (isset($params['users'])) {
foreach ((array) $params['users'] as $u) {
$this->prepareUsername($u);
}
$this->addWhereFld('ipb_address', $this->usernames);
}
if (isset($params['ip'])) {
list($ip, $range) = IP::parseCIDR($params['ip']);
if ($ip && $range) {
# We got a CIDR range
if ($range < 16) {
$this->dieUsage('CIDR ranges broader than /16 are not accepted', 'cidrtoobroad');
}
$lower = wfBaseConvert($ip, 10, 16, 8, false);
$upper = wfBaseConvert($ip + pow(2, 32 - $range) - 1, 10, 16, 8, false);
} else {
$lower = $upper = IP::toHex($params['ip']);
}
$prefix = substr($lower, 0, 4);
$this->addWhere(array("ipb_range_start LIKE '{$prefix}%'", "ipb_range_start <= '{$lower}'", "ipb_range_end >= '{$upper}'"));
}
if (!$wgUser->isAllowed('suppress')) {
$this->addWhereFld('ipb_deleted', 0);
}
// Purge expired entries on one in every 10 queries
if (!mt_rand(0, 10)) {
Block::purgeExpired();
}
$res = $this->select(__METHOD__);
$count = 0;
while ($row = $res->fetchObject()) {
if (++$count > $params['limit']) {
// We've had enough
$this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->ipb_timestamp));
break;
}
$block = array();
if ($fld_id) {
$block['id'] = $row->ipb_id;
}
if ($fld_user && !$row->ipb_auto) {
$block['user'] = $row->ipb_address;
}
if ($fld_by) {
$block['by'] = $row->user_name;
}
if ($fld_timestamp) {
$block['timestamp'] = wfTimestamp(TS_ISO_8601, $row->ipb_timestamp);
}
if ($fld_expiry) {
$block['expiry'] = Block::decodeExpiry($row->ipb_expiry, TS_ISO_8601);
}
if ($fld_reason) {
$block['reason'] = $row->ipb_reason;
}
if ($fld_range) {
$block['rangestart'] = IP::hexToQuad($row->ipb_range_start);
$block['rangeend'] = IP::hexToQuad($row->ipb_range_end);
}
if ($fld_flags) {
// For clarity, these flags use the same names as their action=block counterparts
if ($row->ipb_auto) {
$block['automatic'] = '';
}
if ($row->ipb_anon_only) {
$block['anononly'] = '';
}
if ($row->ipb_create_account) {
$block['nocreate'] = '';
}
if ($row->ipb_enable_autoblock) {
$block['autoblock'] = '';
}
if ($row->ipb_block_email) {
$block['noemail'] = '';
}
if ($row->ipb_deleted) {
$block['hidden'] = '';
}
if ($row->ipb_allow_usertalk) {
$block['allowusertalk'] = '';
}
}
$data[] = $block;
}
$result->setIndexedTagName($data, 'block');
$result->addValue('query', $this->getModuleName(), $data);
}