public function testSave() { $bt = BlockType::installBlockType($this->btHandle); $btx = BlockType::getByID(1); $class = $btx->getBlockTypeClass(); $btc = new $class(); $bID = 1; foreach ($this->requestData as $type => $requestData) { $nb = $bt->add($requestData); $data = $this->expectedRecordData[$type]; $db = Loader::db(); $r = $db->GetRow('select * from `' . $btc->getBlockTypeDatabaseTable() . '` where bID = ?', array($bID)); foreach ($data as $key => $value) { $this->assertTrue($r[$key] == $value, 'Key `' . $key . '` did not equal expected value `' . $value . '` instead equalled `' . $r[$key] . '` (type `' . $type . '`)'); } $bID++; ob_start(); $bv = new BlockView($nb); $bv->render('view'); $contents = ob_get_contents(); ob_end_clean(); $contents = trim($contents); if (isset($this->expectedOutput[$type])) { $this->assertTrue($this->expectedOutput[$type] == $contents, 'Output `' . $contents . '` did not equal expected output `' . $this->expectedOutput[$type] . '` (type `' . $type . '`)'); } } }
function getRssUrl($b) { $uh = Loader::helper('concrete/urls'); if (!$b) { return ''; } $btID = $b->getBlockTypeID(); $bt = BlockType::getByID($btID); $c = $b->getBlockCollectionObject(); $a = $b->getBlockAreaObject(); $rssUrl = $uh->getToolsURL('rss', 'page_list_teasers') . "?bID=" . $b->getBlockID() . "&cID=" . $c->getCollectionID() . "&arHandle=" . $a->getAreaHandle(); return $rssUrl; }
public function add($cID, $arHandle, $btID, $action) { $c = \Page::getByID($cID); if (is_object($c) && !$c->isError()) { $a = \Area::getOrCreate($c, $arHandle); if (is_object($a)) { $ap = new \Permissions($a); $bt = \BlockType::getByID($btID); if (is_object($bt) && $ap->canAddBlock($bt)) { $controller = $bt->getController(); return $this->deliverResponse($controller, $action); } } } $response = new Response(t('Access Denied')); return $response; }
<div class="ccm-dashboard-inner"> <a style="float: right" href="<?=View::url($cPath) ?>"><?= t("« Return to Scrapbook List") ?></a> <div class="sillyIE7"><?= $ih->button_js( t('Add Block to Scrapbook'), 'GlobalScrapbook.addBlock(event)','left'); ?></div> <div class="ccm-spacer"></div> <div id="ccm-scrapbook-list" class="ui-sortable"> <? if( !count($globalScrapbookBlocks) ){ echo t('You have no items in this scrapbook.'); }else foreach($globalScrapbookBlocks as $b) { $b->setBlockAreaObject($globalScrapbookArea); $bv = new BlockView(); $bt = BlockType::getByID( $b->getBlockTypeID() ); $bp = new Permissions($b); $btIcon = $ci->getBlockTypeIconURL($bt); //give this block a name if it doesn't have one if( !strlen($b->getBlockName()) ){ $b->updateBlockName( $scrapbookName.' '.intval($b->bID) ); } ?> <div class="ccm-scrapbook-list-item" id="ccm-scrapbook-list-item-<?=intval($b->bID)?>"> <div class="ccm-block-type"> <div class="options"> <? if ($bp->canWrite()) { ?> <a href="javascript:void(0)" onclick="GlobalScrapbook.toggleRename(<?=intval($b->bID) ?>)"><?=t('Rename')?></a> | <a href="javascript:void(0)" onclick="GlobalScrapbook.editBlockTemplate(<?=intval($b->bID) ?>)" ><?=t('Custom Template')?></a>
} else { $b->alias($c); } } } } $obj = new stdClass(); $obj->aID = $a->getAreaID(); $obj->arHandle = $a->getAreaHandle(); $obj->cID = $c->getCollectionID(); $obj->bID = $b->getBlockID(); $obj->error = false; print Loader::helper('json')->encode($obj); exit; } else { $bt = BlockType::getByID($_REQUEST['btID']); if ($ap->canAddBlock($bt)) { $data = $_POST; $data['uID'] = $u->getUserID(); $class = $bt->getBlockTypeClass(); $bi = new $class($bt); $e = $bi->validate($data); $obj = new stdClass(); $obj->aID = $a->getAreaID(); $obj->arHandle = $a->getAreaHandle(); $obj->cID = $c->getCollectionID(); if (!is_object($e) || $e instanceof ValidationErrorHelper && !$e->has()) { if (!$bt->includeAll()) { $nvc = $c->getVersionToModify(); $nb = $nvc->addBlock($bt, $a, $data); } else {
function deleteBlock($forceDelete = false) { $db = Loader::db(); if ($this->bID < 1) { return false; } $this->refreshCache(); $cID = $this->cID; $c = $this->getBlockCollectionObject(); $cvID = $c->getVersionID(); $bID = $this->bID; $arHandle = $this->arHandle; // if this block is located in a master collection, we're going to delete all the instances of the block, // regardless if ($c instanceof Page && $c->isMasterCollection() && !$this->isAlias() || $forceDelete) { // forceDelete is used by the administration console $r = $db->Execute('select cID, cvID from CollectionVersionBlocks where bID = ?', array($bID)); while ($row = $r->FetchRow()) { Cache::delete('collection_blocks', $row['cID'] . ':' . $row['cvID']); } // this is an original. We're deleting it, and everything else having to do with it $q = "delete from CollectionVersionBlocks where bID = '{$bID}'"; $r = $db->query($q); $q = "delete from CollectionVersionBlockPermissions where bID = '{$bID}'"; $r = $db->query($q); $q = "delete from CollectionVersionBlockStyles where bID = " . intval($bID); $r = $db->query($q); } else { $q = "delete from CollectionVersionBlocks where cID = '{$cID}' and (cvID = '{$cvID}' or cbIncludeAll=1) and bID = '{$bID}' and arHandle = '{$arHandle}'"; $r = $db->query($q); // next, we delete the groups instance of this block $q = "delete from CollectionVersionBlockPermissions where bID = '{$bID}' and cvID = '{$cvID}' and cID = '{$cID}'"; $r = $db->query($q); $q = "delete from CollectionVersionBlockStyles where cID = '{$cID}' and cvID = '{$cvID}' and bID = '{$bID}' and arHandle = '{$arHandle}'"; $r = $db->query($q); } //then, we see whether or not this block is aliased to anything else $q = "select count(*) as total from CollectionVersionBlocks where bID = '{$bID}'"; $totalBlocks = $db->getOne($q); if ($totalBlocks < 1) { $q = "delete from BlockRelations where originalBID = ? or bID = ?"; $r = $db->query($q, array($this->bID, $this->bID)); // this block is not referenced in the system any longer, so we delete the entry in the blocks table, as well as the entries in the corresponding // sub-blocks table $v = array($this->bID); // so, first we delete the block's sub content $bt = BlockType::getByID($this->getBlockTypeID()); if ($bt && method_exists($bt, 'getBlockTypeClass')) { $class = $bt->getBlockTypeClass(); $bc = new $class($this); $bc->delete(); } // now that the block's subcontent delete() method has been run, we delete the block from the Blocks table $q = "delete from Blocks where bID = ?"; $r = $db->query($q, $v); } }
echo $link; ?> ">Read full post »</a> </div> </div> <hr class="blog-entry-divider"/> <?php } ?> </div> <div id="blog-index-foot"> <?php if (!$previewMode && $controller->rss) { $btID = $b->getBlockTypeID(); $bt = BlockType::getByID($btID); $uh = Loader::helper('concrete/urls'); $rssUrl = $controller->getRssUrl($b, 'blog_rss'); $rssIcon = $uh->getBlockTypeAssetsURL($bt, 'rss.png'); $rssTitle = $controller->rssTitle; ?> <div id="rss"> <a href="<?php echo $rssUrl; ?> " target="_blank"><?php echo t('Subscribe to RSS Feed'); ?> </a> <a href="<?php echo $rssUrl;
/** * Renders a view in the block's folder. * <code> * public function view() { // The view() method is automatically run when a block is viewed * $this->render("other_special_view"); // don't use .php * } * </code> * @param string $view * @return void */ function render($view) { $bv = new BlockView(); $bv->setController($this); // sometimes we need the block type available in here if (is_object($this->getBlockObject())) { $bt = BlockType::getByID($this->getBlockObject()->getBlockTypeID()); $a = $this->getBlockObject()->getBlockAreaObject(); } $this->renderOverride = $view; }
public function inspect($btID = 0) { if ($btID > 0) { $bt = BlockType::getByID($btID); } if (isset($bt) && ($bt instanceof BlockType)) { $this->set('bt', $bt); $this->set('num', $bt->getCount()); } else { $this->redirect('/dashboard/blocks/types'); } }
function deleteBlock($forceDelete = false) { $db = Loader::db(); if ($this->bID < 1) { return false; } $cID = $this->cID; $c = $this->getBlockCollectionObject(); $cvID = $c->getVersionID(); $bID = $this->bID; $arHandle = $this->arHandle; // if this block is located in a master collection, we're going to delete all the instances of the block, // regardless if ($c instanceof Page && $c->isMasterCollection() && !$this->isAlias() || $forceDelete) { // forceDelete is used by the administration console // this is an original. We're deleting it, and everything else having to do with it $q = "delete from CollectionVersionBlocks where bID = ?"; $r = $db->query($q, array($bID)); $q = "delete from ComposerContentLayout where bID = ?"; $r = $db->query($q, array($bID)); $q = "delete from BlockPermissionAssignments where bID = ?"; $r = $db->query($q, array($bID)); $q = "delete from CollectionVersionBlockStyles where bID = ?"; $r = $db->query($q, array($bID)); } else { $q = "delete from CollectionVersionBlocks where cID = ? and (cvID = ? or cbIncludeAll=1) and bID = ? and arHandle = ?"; $r = $db->query($q, array($cID, $cvID, $bID, $arHandle)); // next, we delete the groups instance of this block $q = "delete from BlockPermissionAssignments where bID = ? and cvID = ? and cID = ?"; $r = $db->query($q, array($bID, $cvID, $cID)); $q = "delete from CollectionVersionBlockStyles where cID = ? and cvID = ? and bID = ? and arHandle = ?"; $r = $db->query($q, array($cID, $cvID, $bID, $arHandle)); } //then, we see whether or not this block is aliased to anything else $totalBlocks = $db->GetOne('select count(*) from CollectionVersionBlocks where bID = ?', array($bID)); $totalBlocks += $db->GetOne('select count(*) from btCoreScrapbookDisplay where bOriginalID = ?', array($bID)); if ($totalBlocks < 1) { $q = "delete from BlockRelations where originalBID = ? or bID = ?"; $r = $db->query($q, array($this->bID, $this->bID)); // this block is not referenced in the system any longer, so we delete the entry in the blocks table, as well as the entries in the corresponding // sub-blocks table $v = array($this->bID); // so, first we delete the block's sub content $bt = BlockType::getByID($this->getBlockTypeID()); if ($bt && method_exists($bt, 'getBlockTypeClass')) { $class = $bt->getBlockTypeClass(); $bc = new $class($this); $bc->delete(); } // now that the block's subcontent delete() method has been run, we delete the block from the Blocks table $q = "delete from Blocks where bID = ?"; $r = $db->query($q, $v); // Aaaand then we delete all scrapbooked blocks to this entry $r = $db->Execute('select cID, cvID, CollectionVersionBlocks.bID, arHandle from CollectionVersionBlocks inner join btCoreScrapbookDisplay on CollectionVersionBlocks.bID = btCoreScrapbookDisplay.bID where bOriginalID = ?', array($bID)); while ($row = $r->FetchRow()) { $c = Page::getByID($row['cID'], $row['cvID']); $b = Block::getByID($row['bID'], $c, $row['arHandle']); $b->delete(); } } }
<?php defined('C5_EXECUTE') or die("Access Denied."); use Concrete\Block\Form\MiniSurvey; $miniSurvey = new MiniSurvey(); $bID = $_GET['bID']; //Permissions Check $bID = $_REQUEST['bID']; if ($_GET['cID'] && $_GET['arHandle']) { $c = Page::getByID($_GET['cID'], 'RECENT'); $a = Area::get($c, $_GET['arHandle']); if (intval($_GET['bID']) == 0) { //add survey mode $ap = new Permissions($a); $bt = BlockType::getByID($_GET['btID']); if (!$ap->canAddBlock($bt)) { $badPermissions = true; } } else { //edit survey mode // this really ought to be refactored if (!$a->isGlobalArea()) { $b = Block::getByID($_REQUEST['bID'], $c, $a); if ($b->getBlockTypeHandle() == BLOCK_HANDLE_SCRAPBOOK_PROXY) { $b = Block::getByID($b->getController()->getOriginalBlockID()); $b->setBlockAreaObject($a); $b->loadNewCollection($c); $bID = $b->getBlockID(); } } else { $b = Block::getByID($_REQUEST['bID'], Stack::getByName($a->getAreaHandle()), STACKS_AREA_NAME);
<strong><?php echo $pk->getPermissionKeyDisplayName(); ?> </strong> <?php echo t('Permission on '); if ($pk instanceof AreaPermissionKey) { ?> <strong><?php echo $pk->getPermissionObject()->getAreaHandle(); ?> </strong>. <?php } else { if ($pk instanceof BlockPermissionKey) { $bt = BlockType::getByID($pk->getPermissionObject()->getBlockTypeID()); $obj = $pk->getPermissionObject(); if ($obj->getBlockName() != '') { ?> <?php echo t('the %s block named <strong>%s</strong> in <strong>%s</strong> Area. ', t($bt->getBlockTypeName()), $obj->getBlockName(), $pk->getPermissionObject()->getAreaHandle()); ?> <?php } else { ?> <?php echo t('<strong>%s Block</strong> in <strong>%s</strong> Area. ', t($bt->getBlockTypeName()), $pk->getPermissionObject()->getAreaHandle()); ?>
public function view() { $btc = $this->block->getInstance(); $btc->outputAutoHeaderItems(); $bv = new BlockView($this->block); $bv->addScopeItems(array('c' => $this->page, 'a' => $this->area, 'dialogController' => $this)); $this->set('bv', $bv); $canEditCustomTemplate = false; if ($this->permissions->canEditBlockCustomTemplate()) { $canEditCustomTemplate = true; switch ($this->block->getBlockTypeHandle()) { case BLOCK_HANDLE_SCRAPBOOK_PROXY: $bi = $this->block->getInstance(); $bx = \Block::getByID($bi->getOriginalBlockID()); $bt = \BlockType::getByID($bx->getBlockTypeID()); $bFilename = $bx->getBlockFilename(); break; case BLOCK_HANDLE_PAGE_TYPE_OUTPUT_PROXY: $bi = $this->block->getInstance(); $output = $bi->getComposerOutputControlObject(); $control = FormLayoutSetControl::getByID($output->getPageTypeComposerFormLayoutSetControlID()); $object = $control->getPageTypeComposerControlObject(); if ($object instanceof BlockControl) { $bt = $object->getBlockTypeObject(); } $bFilename = $this->block->getBlockFilename(); break; default: $bt = \BlockType::getByID($this->block->getBlockTypeID()); $bFilename = $this->block->getBlockFilename(); break; } $templates = array(); if (is_object($bt)) { $templates = $bt->getBlockTypeCustomTemplates(); } $this->set('bFilename', $bFilename); $this->set('templates', $templates); } $this->set('canEditCustomTemplate', $canEditCustomTemplate); }
/** * Gets a list of installed BlockTypes * - could be defined as static * @todo we have three duplicate functions getBlockTypeArray, getInstalledList, getBlockTypeList * @return BlockType[] */ public function getBlockTypeArray() { $db = Loader::db(); $q = "select btID from BlockTypes order by btDisplayOrder asc, btName asc, btID asc"; $r = $db->query($q); $btArray = array(); if ($r) { while ($row = $r->fetchRow()) { $bt = BlockType::getByID($row['btID']); if (is_object($bt)) { $btArray[] = $bt; } } $r->free(); } return $btArray; }
public function view() { $btc = $this->block->getInstance(); $btc->outputAutoHeaderItems(); $bv = new BlockView($this->block); $bv->addScopeItems(array('c' => $this->page, 'a' => $this->area, 'dialogController' => $this)); $this->set('bv', $bv); $canEditCustomTemplate = false; if ($this->permissions->canEditBlockCustomTemplate()) { $canEditCustomTemplate = true; if ($this->block->getBlockTypeHandle() == BLOCK_HANDLE_SCRAPBOOK_PROXY) { $bi = $this->block->getInstance(); $bx = \Block::getByID($bi->getOriginalBlockID()); $bt = \BlockType::getByID($bx->getBlockTypeID()); } else { $bt = \BlockType::getByID($this->block->getBlockTypeID()); } $templates = $bt->getBlockTypeCustomTemplates(); $this->set('templates', $templates); } $this->set('canEditCustomTemplate', $canEditCustomTemplate); }
public function getRssUrl($b, $tool = 'rss'){ $uh = Loader::helper('concrete/urls'); if(!$b) return ''; $btID = $b->getBlockTypeID(); $bt = BlockType::getByID($btID); $c = $b->getBlockCollectionObject(); $a = $b->getBlockAreaObject(); $rssUrl = $uh->getBlockTypeToolsURL($bt)."/" . $tool . "?bID=".$b->getBlockID()."&cID=".$c->getCollectionID()."&arHandle=" . $a->getAreaHandle(); return $rssUrl; }