public static function installTheme($theme)
{
$pathInfoXml = FRONTEND_PATH . '/Themes/' . $theme . '/info.xml';
$infoXml = @new \SimpleXMLElement($pathInfoXml, LIBXML_NOCDATA, true);
$information = self::processThemeXml($infoXml);
if (!$information) {
throw new Exception('Invalid info.xml');
}
foreach ($information['templates'] as $template) {
$item = array();
$item['theme'] = $information['name'];
$item['label'] = $template['label'];
$item['path'] = $template['path'];
$item['active'] = 'Y';
$item['data']['format'] = $template['format'];
$item['data']['image'] = $template['image'];
// build positions
$item['data']['names'] = array();
$item['data']['default_extras'] = array();
foreach ($template['positions'] as $position) {
$item['data']['names'][] = $position['name'];
$item['data']['default_extras'][$position['name']] = array();
// add default widgets
foreach ($position['widgets'] as $widget) {
// fetch extra_id for this extra
$extraId = (int) BackendModel::getContainer()->get('database')->getVar('SELECT i.id
FROM modules_extras AS i
WHERE type = ? AND module = ? AND action = ? AND data IS NULL AND hidden = ?', array('widget', $widget['module'], $widget['action'], 'N'));
// add extra to defaults
if ($extraId) {
$item['data']['default_extras'][$position['name']][] = $extraId;
}
}
// add default editors
foreach ($position['editors'] as $editor) {
$item['data']['default_extras'][$position['name']][] = 0;
}
}
$item['data'] = serialize($item['data']);
$item['id'] = self::insertTemplate($item);
}
}