/** * Add a theme to the site * @param string $thememodule * @param string $name * @param string $template * @param string $patterntype * @param string $url * @return false */ protected function addThemeAction($thememodule, $name, $patterntype, $template, $url = '') { $name = \tools::sanitizeTechString($name); if (!is_dir(PROFILE_PATH . $thememodule . '/themes/' . $name)) { \tools::createDirectory(PROFILE_PATH . $thememodule . '/themes/' . $name, 0777); if ($patterntype === 'template' && !empty($template)) { list($oldModule, $oldName) = explode(';', $template); $theme = array(); foreach (\app::$devices as $device) { $theme[$device['name']] = \theme::get($oldModule, $oldName, $device['name']); $theme[$device['name']]->setModule($thememodule); $theme[$device['name']]->setName($name); $theme[$device['name']]->onMove('theme', $thememodule, $name, $device['name'], TRUE); } if (is_dir('modules/' . $thememodule . '/themes/' . $oldName . '/')) { \tools::copy_dir('modules/' . $thememodule . '/themes/' . $oldName . '/', PROFILE_PATH . $thememodule . '/themes/' . $name . '/'); } else { \tools::copy_dir(PROFILE_PATH . $thememodule . '/themes/' . $oldName . '/', PROFILE_PATH . $thememodule . '/themes/' . $name . '/'); } foreach (\app::$devices as $device) { $theme[$device['name']]->save(); } } else { $theme = new \theme('container', $name, $thememodule); $theme->save(); } /* Set theme in preview mode */ setcookie('THEMEMODULE', $thememodule, time() + 60 * 60 * 24 * 30, '/'); setcookie('THEME', $name, time() + 60 * 60 * 24 * 30, '/'); $return = array('eval' => 'top.window.location.reload()', 'notification' => t('The Theme has been created'), 'notificationType' => 'positive'); } else { $return = array('notification' => t('The Theme has not been created, theme already exists'), 'notificationType' => 'negative'); } return $this->returnResult($return); }
/** * Serialize and Save this theme object * @param string $module * @param string $name */ public static function get($module, $name) { $file = stream_resolve_include_path($module . '/themes/' . $name . '/theme.' . \app::$config['dev']['serialization']); if ($file) { return \tools::unserialize(substr($file, 0, -4)); } else { $theme = new theme('container', $name, $module); $theme->save(); return $theme; } }