/
block.php
138 lines (124 loc) · 4.7 KB
/
block.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
namespace Concrete\Controller\Backend\UserInterface;
use Concrete\Core\Error\UserMessageException;
use Page as ConcretePage;
use Permissions;
abstract class Block extends Page
{
protected $page;
protected $area;
protected $block;
protected function getEditResponse($b, $e = null)
{
$pr = new \Concrete\Core\Page\EditResponse();
$pr->setPage($this->page);
$pr->setAdditionalDataAttribute('aID', intval($this->area->getAreaID()));
$pr->setAdditionalDataAttribute('arHandle', $this->area->getAreaHandle());
$pr->setAdditionalDataAttribute('bID', intval($b->getBlockID()));
if ($e) {
$pr->setError($e);
}
return $pr;
}
public function on_start()
{
parent::on_start();
$request = $this->request;
$arHandle = $request->query->get('arHandle');
if (!$arHandle) {
$arHandle = $request->request->get('arHandle');
}
$bID = $request->query->get('bID');
if (!$bID) {
$bID = $request->request->get('bID');
}
$a = \Area::get($this->page, $arHandle);
if (!is_object($a)) {
throw new UserMessageException('Invalid Area');
}
$this->area = $a;
if (!$a->isGlobalArea()) {
$this->set('isGlobalArea', false);
$b = \Block::getByID($bID, $this->page, $a);
} else {
$this->set('isGlobalArea', true);
$stack = \Stack::getByName($arHandle);
$sc = ConcretePage::getByID($stack->getCollectionID(), 'RECENT');
$b = \Block::getByID($bID, $sc, STACKS_AREA_NAME);
if ($b) {
$b->setBlockAreaObject($a); // set the original area object
}
}
if (!$b) {
throw new UserMessageException(t('Access Denied'));
}
$this->block = $b;
$this->permissions = new \Permissions($b);
$this->set('bp', $this->permissions);
$this->set('b', $b);
}
public function getViewObject()
{
if ($this->permissions->canViewEditInterface() && $this->canAccess()) {
return \Concrete\Core\Controller\Controller::getViewObject();
}
throw new UserMessageException(t('Access Denied'));
}
protected function getBlockToEdit()
{
$ax = $this->area;
$cx = $this->page;
if ($this->area->isGlobalArea()) {
$ax = STACKS_AREA_NAME;
$cx = \Stack::getByName($_REQUEST['arHandle']);
}
$nvc = $cx->getVersionToModify();
if ($this->area->isGlobalArea()) {
$xvc = $this->page->getVersionToModify(); // we need to create a new version of THIS page as well.
$xvc->relateVersionEdits($nvc);
}
$b = \Block::getByID($_REQUEST['bID'], $nvc, $ax);
if ($b->getBlockTypeHandle() == BLOCK_HANDLE_SCRAPBOOK_PROXY) {
// if we're editing a scrapbook display block, we add a new block in this position for the real block type
// set the block to the display order
// delete the scrapbook display block, and save the data
/*
$originalDisplayOrder = $b->getBlockDisplayOrder();
$btx = BlockType::getByHandle($_b->getBlockTypeHandle());
$nb = $nvc->addBlock($btx, $ax, array());
$nb->setAbsoluteBlockDisplayOrder($originalDisplayOrder);
$b->deleteBlock();
$b = &$nb;
*/
$originalDisplayOrder = $b->getBlockDisplayOrder();
$cnt = $b->getController();
$ob = \Block::getByID($cnt->getOriginalBlockID());
$ob->loadNewCollection($nvc);
if (!is_object($ax)) {
$ax = \Area::getOrCreate($cx, $ax);
}
$ob->setBlockAreaObject($ax);
$nb = $ob->duplicate($nvc);
$nb->setAbsoluteBlockDisplayOrder($originalDisplayOrder);
$b->deleteBlock();
$b = &$nb;
} else {
if ($b->isAlias()) {
// then this means that the block we're updating is an alias. If you update an alias, you're actually going
// to duplicate the original block, and update the newly created block. If you update an original, your changes
// propagate to the aliases
$nb = $b->duplicate($nvc);
$b->deleteBlock();
$b = $nb;
}
}
return $b;
}
public function action()
{
$url = call_user_func_array('parent::action', func_get_args());
$url .= '&arHandle=' . urlencode($this->area->getAreaHandle());
$url .= '&bID=' . $this->block->getBlockID();
return $url;
}
}