</dd>
</dl>
+ <dl>
+ <dt><label for="pageIDs">{lang}wcf.acp.box.pageIDs{/lang}</label></dt>
+ <dd>
+ <select name="pageIDs[]" id="pageIDs" multiple="multiple" size="20">
+ {foreach from=$pageNodeList item=pageNode}
+ <option value="{@$pageNode->getPage()->pageID}"{if $pageNode->getPage()->pageID|in_array:$pageIDs} selected="selected"{/if}>{if $pageNode->getDepth() > 1}{@" "|str_repeat:($pageNode->getDepth() - 1)}{/if}{$pageNode->getPage()->name}</option>
+ {/foreach}
+ </select>
+ </dd>
+ </dl>
+
{event name='dataFields'}
</section>
<label><input type="checkbox" id="visibleEverywhere" name="visibleEverywhere" value="1" {if $visibleEverywhere}checked="checked" {/if}/> {lang}wcf.acp.box.visibleEverywhere{/lang}</label>
</dd>
</dl>
+
+ <dl>
+ <dt><label for="pageIDs">{lang}wcf.acp.box.pageIDs{/lang}</label></dt>
+ <dd>
+ <select name="pageIDs[]" id="pageIDs" multiple="multiple" size="20">
+ {foreach from=$pageNodeList item=pageNode}
+ <option value="{@$pageNode->getPage()->pageID}"{if $pageNode->getPage()->pageID|in_array:$pageIDs} selected="selected"{/if}>{if $pageNode->getDepth() > 1}{@" "|str_repeat:($pageNode->getDepth() - 1)}{/if}{$pageNode->getPage()->name}</option>
+ {/foreach}
+ </select>
+ </dd>
+ </dl>
{/if}
{event name='dataFields'}
use wcf\data\box\BoxEditor;
use wcf\data\media\Media;
use wcf\data\media\ViewableMediaList;
+use wcf\data\page\PageNodeTree;
use wcf\form\AbstractForm;
+use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\exception\UserInputException;
use wcf\system\language\LanguageFactory;
use wcf\system\WCF;
*/
public $images = [];
+ /**
+ * page ids
+ * @var integer[]
+ */
+ public $pageIDs = [];
+
/**
* @inheritDoc
*/
if (isset($_POST['cssClassName'])) $this->cssClassName = StringUtil::trim($_POST['cssClassName']);
if (isset($_POST['showHeader'])) $this->showHeader = intval($_POST['showHeader']);
if (isset($_POST['className'])) $this->className = StringUtil::trim($_POST['className']);
+ if (isset($_POST['pageIDs']) && is_array($_POST['pageIDs'])) $this->pageIDs = ArrayUtil::toIntegerArray($_POST['pageIDs']);
if (isset($_POST['title']) && is_array($_POST['title'])) $this->title = ArrayUtil::trim($_POST['title']);
if (isset($_POST['content']) && is_array($_POST['content'])) $this->content = ArrayUtil::trim($_POST['content']);
// @todo check class
}
+ // validate page ids
+ if (!empty($this->pageIDs)) {
+ $conditionBuilder = new PreparedStatementConditionBuilder();
+ $conditionBuilder->add('pageID IN (?)', [$this->pageIDs]);
+ $sql = "SELECT pageID
+ FROM wcf".WCF_N."_page
+ " . $conditionBuilder;
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute($conditionBuilder->getParameters());
+ $this->pageIDs = [];
+ while ($row = $statement->fetchArray()) {
+ $this->pageIDs[] = $row['pageID'];
+ }
+ }
+
// validate images
if (WCF::getSession()->getPermission('admin.content.cms.canUseMedia')) {
foreach ($this->imageID as $languageID => $imageID) {
'showHeader' => $this->showHeader,
'className' => $this->className,
'identifier' => ''
- ]), 'content' => $content]);
+ ]), 'content' => $content, 'pageIDs' => $this->pageIDs ]);
$returnValues = $this->objectAction->executeAction();
// set generic box identifier
'content' => $this->content,
'imageID' => $this->imageID,
'images' => $this->images,
+ 'pageIDs' => $this->pageIDs,
'availableLanguages' => LanguageFactory::getInstance()->getLanguages(),
'availableBoxTypes' => Box::$availableBoxTypes,
- 'availablePositions' => Box::$availablePositions
+ 'availablePositions' => Box::$availablePositions,
+ 'pageNodeList' => (new PageNodeTree())->getNodeList()
]);
}
}
'cssClassName' => $this->cssClassName,
'showHeader' => $this->showHeader,
'className' => $this->className
- ]), 'content' => $content]);
+ ]), 'content' => $content, 'pageIDs' => $this->pageIDs]);
$this->objectAction->executeAction();
// call saved event
$this->className = $this->box->className;
if ($this->box->showHeader) $this->showHeader = 1;
if ($this->box->visibleEverywhere) $this->visibleEverywhere = 1;
+ else $this->visibleEverywhere = 0;
+ $this->pageIDs = $this->box->getPageIDs();
foreach ($this->box->getBoxContent() as $languageID => $content) {
$this->title[$languageID] = $content['title'];
use wcf\data\box\Box;
use wcf\data\menu\MenuAction;
use wcf\data\menu\MenuEditor;
+use wcf\data\page\PageNodeTree;
use wcf\form\AbstractForm;
+use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\exception\UserInputException;
use wcf\system\language\I18nHandler;
use wcf\system\WCF;
+use wcf\util\ArrayUtil;
use wcf\util\StringUtil;
/**
*/
public $showHeader = 1;
+ /**
+ * page ids
+ * @var integer[]
+ */
+ public $pageIDs = [];
+
/**
* @inheritDoc
*/
if (isset($_POST['visibleEverywhere'])) $this->visibleEverywhere = intval($_POST['visibleEverywhere']);
if (isset($_POST['cssClassName'])) $this->cssClassName = StringUtil::trim($_POST['cssClassName']);
if (isset($_POST['showHeader'])) $this->showHeader = intval($_POST['showHeader']);
+ if (isset($_POST['pageIDs']) && is_array($_POST['pageIDs'])) $this->pageIDs = ArrayUtil::toIntegerArray($_POST['pageIDs']);
}
/**
// validate box position
$this->validatePosition();
+
+ // validate page ids
+ if (!empty($this->pageIDs)) {
+ $conditionBuilder = new PreparedStatementConditionBuilder();
+ $conditionBuilder->add('pageID IN (?)', [$this->pageIDs]);
+ $sql = "SELECT pageID
+ FROM wcf".WCF_N."_page
+ " . $conditionBuilder;
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute($conditionBuilder->getParameters());
+ $this->pageIDs = [];
+ while ($row = $statement->fetchArray()) {
+ $this->pageIDs[] = $row['pageID'];
+ }
+ }
}
/**
'showOrder' => $this->showOrder,
'cssClassName' => $this->cssClassName,
'packageID' => 1
- )));
+ ), 'pageIDs' => $this->pageIDs));
$returnValues = $this->objectAction->executeAction();
// set generic identifier
$menuEditor = new MenuEditor($returnValues['returnValues']);
'showOrder' => $this->showOrder,
'visibleEverywhere' => $this->visibleEverywhere,
'showHeader' => $this->showHeader,
- 'availablePositions' => Box::$availableMenuPositions
+ 'pageIDs' => $this->pageIDs,
+ 'availablePositions' => Box::$availableMenuPositions,
+ 'pageNodeList' => (new PageNodeTree())->getNodeList()
));
}
}
'showHeader' => ($this->showHeader) ? 1 : 0,
'showOrder' => $this->showOrder,
'cssClassName' => $this->cssClassName
- ))));
+ )), 'pageIDs' => $this->pageIDs));
$boxAction->executeAction();
}
$this->cssClassName = $this->menu->getBox()->cssClassName;
$this->showOrder = $this->menu->getBox()->showOrder;
$this->visibleEverywhere = $this->menu->getBox()->visibleEverywhere;
+ $this->pageIDs = $this->menu->getBox()->getPageIDs();
$this->showHeader = $this->menu->getBox()->showHeader;
}
}
* box content grouped by language id
* @var string[][]
*/
- protected $boxContent = null;
+ protected $boxContent;
/**
* image media object
* @var ViewableMedia
*/
- protected $image = null;
+ protected $image;
/**
* @inheritDoc
* available box types
* @var string[]
*/
- public static $availableBoxTypes = ['text', 'html', 'system'];
+ public static $availableBoxTypes = ['text', 'html', 'tpl', 'system'];
/**
* available box positions
*/
protected $menu;
+ /**
+ * box to page assignments
+ * @var integer[]
+ */
+ protected $pageIDs;
+
/**
* Returns true if the active user can delete this box.
*
return false;
}
+ /**
+ * Returns box to page assignments.
+ *
+ * @return integer[]
+ */
+ public function getPageIDs() {
+ if ($this->pageIDs === null) {
+ $this->pageIDs = [];
+ $sql = "SELECT pageID
+ FROM wcf" . WCF_N . "_box_to_page
+ WHERE boxID = ?";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute([$this->boxID]);
+ while ($row = $statement->fetchArray()) {
+ $this->pageIDs[] = $row['pageID'];
+ }
+ }
+
+ return $this->pageIDs;
+ }
+
/**
* Returns the box with the given name.
*
}
}
+ // save box to page
+ if (!empty($this->parameters['pageIDs'])) {
+ $sql = "INSERT INTO wcf".WCF_N."_box_to_page
+ (boxID, pageID, visible)
+ VALUES (?, ?, ?)";
+ $statement = WCF::getDB()->prepareStatement($sql);
+
+ foreach ($this->parameters['pageIDs'] as $pageID) {
+ $statement->execute([
+ $box->boxID,
+ $pageID,
+ ($box->visibleEverywhere ? 0 : 1)
+ ]);
+ }
+ }
+
return $box;
}
}
}
}
+
+ // save box to page
+ if (isset($this->parameters['pageIDs'])) {
+ $sql = "DELETE FROM wcf".WCF_N."_box_to_page
+ WHERE boxID = ?";
+ $deleteStatement = WCF::getDB()->prepareStatement($sql);
+
+ $sql = "INSERT INTO wcf".WCF_N."_box_to_page
+ (boxID, pageID, visible)
+ VALUES (?, ?, ?)";
+ $insertStatement = WCF::getDB()->prepareStatement($sql);
+
+ foreach ($this->objects as $box) {
+ $deleteStatement->execute([$box->boxID]);
+
+ foreach ($this->parameters['pageIDs'] as $pageID) {
+ $insertStatement->execute([$box->boxID, $pageID, ($box->visibleEverywhere ? 0 : 1)]);
+ }
+ }
+ }
}
/**
$boxData = $this->parameters['boxData'];
$boxData['menuID'] = $menu->menuID;
$boxData['identifier'] = '';
- $boxAction = new BoxAction([], 'create', ['data' => $boxData]);
+ $boxAction = new BoxAction([], 'create', ['data' => $boxData, 'pageIDs' => (isset($this->parameters['pageIDs']) ? $this->parameters['pageIDs'] : [])]);
$returnValues = $boxAction->executeAction();
// set generic box identifier
namespace wcf\system\box;
use wcf\data\box\Box;
use wcf\data\box\BoxList;
+use wcf\system\request\RequestHandler;
use wcf\system\SingletonFactory;
/**
* @inheritDoc
*/
protected function init() {
+ // get active page id
+ $pageID = RequestHandler::getInstance()->getActiveRequest()->getPageID();
+
// load box layout for active page
$boxList = new BoxList();
+ if ($pageID) $boxList->getConditionBuilder()->add('(box.visibleEverywhere = ? AND boxID NOT IN (SELECT boxID FROM wcf'.WCF_N.'_box_to_page WHERE pageID = ? AND visible = ?)) OR boxID IN (SELECT boxID FROM wcf'.WCF_N.'_box_to_page WHERE pageID = ? AND visible = ?)', array(1, $pageID, 0, $pageID, 1));
+ else $boxList->getConditionBuilder()->add('box.visibleEverywhere = ?', array(1));
$boxList->sqlOrderBy = 'showOrder';
$boxList->readObjects();
foreach ($boxList as $box) {
KEY (boxID, languageID)
);
+DROP TABLE IF EXISTS wcf1_box_to_page;
+CREATE TABLE wcf1_box_to_page (
+ boxID INT(10) NOT NULL,
+ pageID INT(10) NOT NULL,
+ visible TINYINT(1) NOT NULL DEFAULT 1,
+
+ UNIQUE KEY (pageID, boxID),
+ KEY (pageID, visible)
+);
+
DROP TABLE IF EXISTS wcf1_captcha_question;
CREATE TABLE wcf1_captcha_question (
questionID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
ALTER TABLE wcf1_box_content ADD FOREIGN KEY (languageID) REFERENCES wcf1_language (languageID) ON DELETE CASCADE;
ALTER TABLE wcf1_box_content ADD FOREIGN KEY (imageID) REFERENCES wcf1_media (mediaID) ON DELETE SET NULL;
+ALTER TABLE wcf1_box_to_page ADD FOREIGN KEY (boxID) REFERENCES wcf1_box (boxID) ON DELETE CASCADE;
+ALTER TABLE wcf1_box_to_page ADD FOREIGN KEY (pageID) REFERENCES wcf1_page (pageID) ON DELETE CASCADE;
+
ALTER TABLE wcf1_category ADD FOREIGN KEY (objectTypeID) REFERENCES wcf1_object_type (objectTypeID) ON DELETE CASCADE;
ALTER TABLE wcf1_cli_history ADD FOREIGN KEY (userID) REFERENCES wcf1_user (userID) ON DELETE CASCADE;