public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz) { if ($this->meta === AIR) { if ($target instanceof LiquidBlock) { $level->setBlock($target, new AirBlock(), true, false, true); if (($player->gamemode & 0x1) === 0) { $this->meta = $target instanceof WaterBlock ? WATER : LAVA; } return true; } } elseif ($this->meta === WATER) { //Support Make Non-Support Water to Support Water if ($block->getID() === AIR || $block instanceof WaterBlock && ($block->getMetadata() & 0x7) != 0x0) { $water = new WaterBlock(); $level->setBlock($block, $water, true, false, true); $water->place(clone $this, $player, $block, $target, $face, $fx, $fy, $fz); if (($player->gamemode & 0x1) === 0) { $this->meta = 0; } return true; } } elseif ($this->meta === LAVA) { if ($block->getID() === AIR) { $level->setBlock($block, new LavaBlock(), true, false, true); if (($player->gamemode & 0x1) === 0) { $this->meta = 0; } return true; } } return false; }
public function setPermissionObject(Block $b) { $this->permissionObject = $b; // if the area overrides the collection permissions explicitly (with a one on the override column) we check if ($b->overrideAreaPermissions()) { $this->permissionObjectToCheck = $b; } else { $a = $b->getBlockAreaObject(); if (is_object($a)) { if ($a->overrideCollectionPermissions()) { $this->permissionObjectToCheck = $a; } elseif ($a->getAreaCollectionInheritID()) { $mcID = $a->getAreaCollectionInheritID(); $mc = Page::getByID($mcID, 'RECENT'); $ma = Area::get($mc, $a->getAreaHandle()); if ($ma->overrideCollectionPermissions()) { $this->permissionObjectToCheck = $ma; } else { $this->permissionObjectToCheck = $ma->getAreaCollectionObject(); } } else { $this->permissionObjectToCheck = $a->getAreaCollectionObject(); } } else { $this->permissionObjectToCheck = Page::getCurrentPage(); } } }
function test_hidden() { // Reads from test/templates/block-test.php $block = new Block('test'); $block->hidden = TRUE; $this->assertEqual('', $block->render()); }
protected function parseBlock($lines, $current = 0) { //printf("parseBlock: line %s\n", $current); $rootBlock = new Block('[root]'); for ($i = $current, $count = count($lines); $i < $count; $i++) { $line = trim($lines[$i]); $line = $this->stripComment($line); if ($line === '' || $line[0] === '#') { //printf("parseBlock: skip line %s\n", $i); continue; } if ($line[strlen($line) - 1] === '{') { list($block, $i) = $this->parseBlock($lines, ++$i); if ($block !== false) { list($name, $value) = $this->parseLine($line); $block->name = $name; $block->value = $value; $rootBlock->addBlock($block); } continue; } if ($line === '}') { return [$rootBlock, $i]; } list($property, $i) = $this->parseProperty($lines, $i); if ($property !== false) { $rootBlock->addProperty($property); } } return $rootBlock; }
function headerNav() { include "config/site.php"; require_once 'model/Block.php'; $block = new Block(); $blocks = $block->getBlocks(); require "{$tpl_root}/_header_nav.php"; }
/** * Remove block from composition * * @param Block $blockToRemove */ public function removeBlock(Block $blockToRemove) { foreach ($this->blocks as $key => $block) { if ($block->getName() === $blockToRemove->getName()) { unset($this->blocks[$key]); } } }
private function renderBlocks() { $this->aRenderedBlocks = array(); foreach ($this->aBlocks as $sBlock) { // New block object $oBlock = new Block($sBlock, $this->aPageConfig, $this->sConfigFile); $this->aRenderedBlocks[$oBlock->getName()] = $oBlock->render(); } }
public function append(Block $block) { if ($this->numBlocks > 0) { $last = $this->numBlocks - 1; $this->blocks[$last]->setNextHash($block->getHash()); } $this->numBlocks++; $this->blocks[] = $block; }
/** * On theme activation, activate some default blocks */ public function action_theme_activated() { $blocks = $this->get_blocks('primary', '', $this); if (count($blocks) == 0) { $block = new Block(array('title' => _t('Posts'), 'type' => 'grayposts')); $block->add_to_area('primary'); Session::notice(_t('Added default blocks to theme areas.')); } }
public function test_delete_block() { $params = array('title' => $this->title, 'type' => $this->type); $block = new Block($params); $block->insert(); $count = DB::get_value('SELECT count(*) FROM {blocks}'); $block->delete(); $this->assert_equal($count - 1, DB::get_value('SELECT count(*) FROM {blocks}'), 'Count of blocks should decrease by one'); }
/** * Add the K2 menu block to the nav area upon theme activation if there's nothing already there */ public function action_theme_activated() { $blocks = $this->get_blocks('nav', 0, $this); if (count($blocks) == 0) { $block = new Block(array('title' => _t('K2 Menu'), 'type' => 'k2_menu')); $block->add_to_area('nav'); Session::notice(_t('Added K2 Menu block to Nav area.')); } }
/** * Return string representation * * @return string */ public function __toString() { if (is_string($this->content)) { $content = $this->content; } else { $content = $this->content->__toString(); } $result = sprintf('@%s %s', $this->keyword, $content); return $result; }
public function addDBData() { for ($i = 1; $i <= 4; $i++) { $this->localUsers[] = $this->getMutableTestUser()->getUser(); } $sysop = static::getTestSysop()->getUser(); $block = new Block(['address' => $this->localUsers[2]->getName(), 'by' => $sysop->getId(), 'reason' => __METHOD__, 'expiry' => '1 day', 'hideName' => false]); $block->insert(); $block = new Block(['address' => $this->localUsers[3]->getName(), 'by' => $sysop->getId(), 'reason' => __METHOD__, 'expiry' => '1 day', 'hideName' => true]); $block->insert(); }
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz) { if (($target->isTransparent === false or $target->getID() === SLAB) and $face !== 0 and $face !== 1) { $faces = array(2 => 0, 3 => 1, 4 => 2, 5 => 3); $this->meta = $faces[$face] & 0x3; if ($fy > 0.5) { $this->meta |= 0x8; } $this->level->setBlock($block, $this, true, false, true); return true; } }
public function indexAction() { $collection = $this->getModel()->getCollection(); $params = $this->getParams(); $list = new Block('templates/' . $params['controller'] . '/index.php'); $list->setVar('collection', $collection); $labels = $this->getEntityLabels(); $layout = $this->layout; $layout->setVar('title', $labels[1]); $layout->setChild('body', $list); $layout->render(); }
/** * Get basic info about a given block * @param Block $block * @return array Array containing several keys: * - blockid - ID of the block * - blockedby - username of the blocker * - blockedbyid - user ID of the blocker * - blockreason - reason provided for the block * - blockedtimestamp - timestamp for when the block was placed/modified * - blockexpiry - expiry time of the block */ public static function getBlockInfo(Block $block) { global $wgContLang; $vals = array(); $vals['blockid'] = $block->getId(); $vals['blockedby'] = $block->getByName(); $vals['blockedbyid'] = $block->getBy(); $vals['blockreason'] = $block->mReason; $vals['blockedtimestamp'] = wfTimestamp(TS_ISO_8601, $block->mTimestamp); $vals['blockexpiry'] = $wgContLang->formatExpiry($block->getExpiry(), TS_ISO_8601, 'infinite'); return $vals; }
/** * On theme activation, set the default options and activate a default menu */ public function action_theme_activated() { $opts = Options::get_group(__CLASS__); if (empty($opts)) { Options::set_group(__CLASS__, $this->defaults); } $blocks = $this->get_blocks('nav', 0, $this); if (count($blocks) == 0) { $block = new Block(array('title' => _t('Charcoal Menu'), 'type' => 'charcoal_menu')); $block->add_to_area('nav'); Session::notice(_t('Added Charcoal Menu block to Nav area.')); } }
function smarty_function_create_block($params, &$smarty) { global $smarty_blocks; $block = new Block($params['name']); $block->set_content($params['content']); $block->output(false); $smarty_blocks[$params['name']] = $block; if (isset($params['parent'])) { $smarty_blocks[$params['parent']]->add_block($block); } return ""; //return "qweqwe"; }
public function testInterpretReferenceBlockDirective() { $pageXml = new \Magento\Framework\View\Layout\Element(__DIR__ . '/_files/_layout_update_reference.xml', 0, true); $parentElement = new \Magento\Framework\View\Layout\Element('<page></page>'); foreach ($pageXml->xpath('body/*') as $element) { $this->assertTrue(in_array($element->getName(), $this->block->getSupportedNodes())); $this->block->interpret($this->readerContext, $element, $parentElement); } $structure = $this->readerContext->getScheduledStructure(); $this->assertArrayHasKey($this->blockName, $structure->getStructure()); $this->assertEquals('block', $structure->getStructure()[$this->blockName][self::IDX_TYPE]); $resultElementData = $structure->getStructureElementData($this->blockName); $this->assertEquals(['test_arg' => 'test-argument-value'], $resultElementData['arguments']); }
public static function addBlock($blocker, $to_block) { if ($blocker == $to_block) { // Blocking yourself would be stupid, don't do it. return; } $block = new Block(); $block->blocking_user_id = $blocker; $block->blocked_user_id = $to_block; $block->save(); # Take the blocker of the blocked autoread $q = Doctrine_Query::create()->update("Autofinger")->set("updated", 0)->where("interest = ?", $blocker)->andWhere("owner = ?", $to_block); $q->execute(); }
/** * @param Block $block * @param $user * @return bool */ function efPowersMakeUnblockable($block, $user) { $blockedUser = User::newFromName($block->getRedactedName()); if (empty($blockedUser) || !$blockedUser->isAllowed('unblockable')) { return true; } /* $wgMessageCache was removed in ME 1.18 global $wgMessageCache; // hack to get IpBlock to display the message we want -- hardcoded in core code $replacement = wfMsgExt( 'staffpowers-ipblock-abort', array('parseinline') ); $wgMessageCache->addMessages( array( 'hookaborted' => $replacement ) ); */ wfRunHooks('BlockIpStaffPowersCancel', array($block, $user)); return false; }
public function executeCreate(sfWebRequest $request) { $this->forward404Unless($request->isMethod(sfRequest::POST)); $bPost = $request->getParameter('block'); $bData = new BlockData(); $bData->fromArray($bPost['block_data']); $bPosition = new BlockPosition(); $bPosition->fromArray($bPost['block_position']); $block = new Block(); $block->set('BlockData', $bData); $block->set('BlockPosition', $bPosition); $block->save(); $this->block = $block; $this->setTemplate('show'); }
public function addDBData() { for ($i = 1; $i <= 4; $i++) { $user = User::newFromName("UTLocalIdLookup{$i}"); if ($user->getId() == 0) { $user->addToDatabase(); } $this->localUsers["UTLocalIdLookup{$i}"] = $user->getId(); } User::newFromName('UTLocalIdLookup1')->addGroup('local-id-lookup-test'); $block = new Block(array('address' => 'UTLocalIdLookup3', 'by' => User::idFromName('UTSysop'), 'reason' => __METHOD__, 'expiry' => '1 day', 'hideName' => false)); $block->insert(); $block = new Block(array('address' => 'UTLocalIdLookup4', 'by' => User::idFromName('UTSysop'), 'reason' => __METHOD__, 'expiry' => '1 day', 'hideName' => true)); $block->insert(); }
/** * @static * @param $user User * @param $editToken * @param $hookError * @return bool */ public static function onEmailUserPermissionsErrors( $user, $editToken, &$hookError ) { wfDebug( "Checking Tor status\n" ); // Just in case we're checking another user global $wgUser; if ( $user->getName() != $wgUser->getName() ) { return true; } if (self::isExitNode()) { wfDebug( "-User detected as editing through tor.\n" ); global $wgTorBypassPermissions; foreach( $wgTorBypassPermissions as $perm) { if ($user->isAllowed( $perm )) { wfDebug( "-User has $perm permission. Exempting from Tor Blocks\n" ); return true; } } if (Block::isWhitelistedFromAutoblocks( wfGetIp() )) { wfDebug( "-IP is in autoblock whitelist. Exempting from Tor blocks.\n" ); return true; } $ip = wfGetIp(); wfDebug( "-User detected as editing from Tor node. Denying email.\n" ); $hookError = array( 'permissionserrors', 'torblock-blocked', array( $ip ) ); return false; } return true; }
/** * Unblocks the specified user or provides the reason the unblock failed. */ public function execute() { $user = $this->getUser(); $params = $this->extractRequestParams(); if (is_null($params['id']) && is_null($params['user'])) { $this->dieUsageMsg('unblock-notarget'); } if (!is_null($params['id']) && !is_null($params['user'])) { $this->dieUsageMsg('unblock-idanduser'); } if (!$user->isAllowed('block')) { $this->dieUsageMsg('cantunblock'); } # bug 15810: blocked admins should have limited access here if ($user->isBlocked()) { $status = SpecialBlock::checkUnblockSelf($params['user'], $user); if ($status !== true) { $this->dieUsageMsg($status); } } $data = array('Target' => is_null($params['id']) ? $params['user'] : "******", 'Reason' => $params['reason']); $block = Block::newFromTarget($data['Target']); $retval = SpecialUnblock::processUnblock($data, $this->getContext()); if ($retval !== true) { $this->dieUsageMsg($retval[0]); } $res['id'] = $block->getId(); $target = $block->getType() == Block::TYPE_AUTO ? '' : $block->getTarget(); $res['user'] = $target instanceof User ? $target->getName() : $target; $res['userid'] = $target instanceof User ? $target->getId() : 0; $res['reason'] = $params['reason']; $this->getResult()->addValue(null, $this->getModuleName(), $res); }
/** * Add the GridFieldAddExistingSearchButton component to this grid config. * * @return $this **/ public function addExisting() { $classes = $this->blockManager->getBlockClasses(); $this->addComponent($add = new GridFieldAddExistingSearchButton()); $add->setSearchList(Block::get()->filter(array('ClassName' => array_keys($classes)))); return $this; }
public function drawBlock() { //echo 'drawBlock'; if ($this->templateHolder != null) { parent::draw(); } }
/** * Get CMS fields * * @return FieldList */ public function getCMSFields() { $fields = parent::getCMSFields(); $fields->removeByName('TeamMembers'); $fields->addFieldToTab('Root.Main', GridField::create('TeamMembers', 'Team Members', $this->TeamMembers(), GridFieldConfig_RecordEditor::create()->addComponent(new GridFieldSortableRows('SortOrder')))); return $fields; }
public function run($request) { // update block/set titles // Name field has been reverted back to Title // DB::query("update Block set Name = Title"); // DB::query("update BlockSet set Name = Title"); // update block areas DB::query("\n\t\t\tupdate SiteTree_Blocks\n\t\t\tleft join Block on SiteTree_Blocks.BlockID = Block.ID\n\t\t\tset BlockArea = Block.Area\n\t\t\twhere BlockID = Block.ID\n\t\t"); // update block sort DB::query("\n\t\t\tupdate SiteTree_Blocks\n\t\t\tleft join Block on SiteTree_Blocks.BlockID = Block.ID\n\t\t\tset Sort = Block.Weight\n\t\t\twhere BlockID = Block.ID\n\t\t"); echo "BlockAreas, Sort updated<br />"; // migrate global blocks $sc = SiteConfig::current_site_config(); if ($sc->Blocks()->Count()) { $set = BlockSet::get()->filter('Title', 'Global')->first(); if (!$set) { $set = BlockSet::create(array('Title' => 'Global')); $set->write(); } foreach ($sc->Blocks() as $block) { if (!$set->Blocks()->find('ID', $block->ID)) { $set->Blocks()->add($block, array('Sort' => $block->Weight, 'BlockArea' => $block->Area)); echo "Block #{$block->ID} added to Global block set<br />"; } } } // publish blocks $blocks = Block::get()->filter('Published', 1); foreach ($blocks as $block) { $block->publish('Stage', 'Live'); echo "Published Block #{$block->ID}<br />"; } }
/** * Returns true it overlaps another block * * @param Block $block * @return bool */ public function overlaps(Block $block) { if ($this->room == 'Online' || $block->room == 'Online') { return FALSE; } return parent::overlaps($block); }