Permalink
Browse files

theme installation change doctype

  • Loading branch information...
1 parent 5a82d9f commit e40010222e2c402a073c115a10dad4babbb76d0b @maskas maskas committed Apr 11, 2012
@@ -0,0 +1,71 @@
+<?php
+/**
+ * @package ImpressPages
+ * @copyright Copyright (C) 2011 ImpressPages LTD.
+ * @license GNU/GPL, see ip_license.html
+ */
+
+namespace Modules\administrator\theme;
+
+if (!defined('BACKEND')) exit;
+
+class ConfigurationFile{
+ private $themeTitle;
+ private $themeVersion;
+ private $themeDoctype;
+
+ public function __construct($file){
+ global $parametersMod;
+
+ $this->requiredModules = array();
+
+ $moduleGroupAdmin = 0;
+ $moduleAdmin = 0;
+
+ $config = $this->getInitVariables($file);
+
+ foreach($config as $variable){
+ $key = $variable['name'];
+ $value = $variable['value'];
+ switch($key){
+ case 'title':
+ $this->themeTitle = $value;
+ break;
+ case 'version':
+ $this->themeVersion = $value;
+ break;
+ case 'doctype':
+ $this->themeDoctype = $value;
+ break;
+ }
+ }
+ }
+
+
+ public function getThemeTitle(){
+ return $this->themeTitle;
+ }
+ public function getThemeVersion(){
+ return $this->themeVersion;
+ }
+ public function getThemeDoctype(){
+ return $this->themeDoctype;
+ }
+
+ private function getInitVariables($file){
+ $answer = array();
+
+ if(file_exists($file)){
+ $config = file($file);
+ foreach($config as $key => $configRow){
+ $configName = substr($configRow, 0, strpos($configRow, ':'));
+ $value = substr($configRow, strpos($configRow, ':') + 1);
+ $value = str_replace("\n", "", str_replace("\r", "", $value));
+ $answer[] = array('name'=>$configName, 'value' => $value);
+ }
+ } else {
+ return array();
+ }
+ return $answer;
+ }
+}
@@ -44,7 +44,9 @@ public static function installTheme($themeName) {
throw new \Exception("Theme '".$themeName."' does not exist.");
}
- self::writeThemeNameToConfig(BASE_DIR.'ip_config.php', $theme->getName());
+ $configModel = new \Modules\standard\configuration\Model();
+ $configModel->changeConfigurationConstantValue('THEME', THEME, $theme->getName());
+ $configModel->changeConfigurationConstantValue('DEFAULT_DOCTYPE', DEFAULT_DOCTYPE, $theme->getDoctype());
$parametersFile = BASE_DIR.THEME_DIR.$themeName.'/'.Theme::INSTALL_DIR.'/'.Theme::PARAMETERS_FILE;
if (file_exists($parametersFile)) {
@@ -56,19 +58,4 @@ public static function installTheme($themeName) {
}
- private static function writeThemeNameToConfig($configFileName, $themeName){
- if (!is_writable($configFileName)) {
- throw new \Exception("Error: ip_config.php file is not writable. You can make it writable using FTP client or Linux chmod command.");
- }
- $config = file_get_contents($configFileName);
-
- $count;
- $config = preg_replace('/[\'\"]THEME[\'\"][ \n]*,[ \n]*[\'\"]'.THEME.'[\'\"]/s', "'THEME', '".$themeName."'", $config, 1, $count);
-
- if ($count != 1) {
- throw new \Exception('Can\'t find theme definition in configuration file');
- }
-
- file_put_contents($configFileName, $config);
- }
}
@@ -7,6 +7,8 @@
namespace Modules\administrator\theme;
+
+
if (!defined('CMS')) exit;
@@ -15,6 +17,9 @@ class Theme{
const PARAMETERS_FILE = 'parameters.php';
private $name;
+ private $title;
+ private $doctype;
+ private $version;
private $previewImage;
public function __construct($name) {
@@ -27,6 +32,22 @@ public function __construct($name) {
if (file_exists(BASE_DIR.THEME_DIR.$name.'/'.self::INSTALL_DIR.'preview.png')) {
$this->previewImage = THEME_DIR.$name.'/'.self::INSTALL_DIR.'preview.png';
}
+
+ $configuration = new ConfigurationFile(BASE_DIR.THEME_DIR.$name.'/'.self::INSTALL_DIR.'theme.ini');
+ if ($configuration->getThemeTitle()) {
+ $this->title = $configuration->getThemeTitle();
+ } else {
+ $this->title = $name;
+ }
+
+ $this->version = $configuration->getThemeVersion();
+
+ if (defined('\Ip\View::'.$configuration->getThemeDoctype())) {
+ $this->doctype = $configuration->getThemeDoctype();
+ } else {
+ $this->doctype = 'DOCTYPE_HTML5';
+ }
+
}
public function getPreviewImage() {
@@ -37,4 +58,12 @@ public function getName() {
return $this->name;
}
+ public function getDoctype() {
+ return $this->doctype;
+ }
+
+ public function getVersion() {
+ return $this->version;
+ }
+
}
@@ -0,0 +1,40 @@
+<?php
+/**
+ * @package ImpressPages
+ * @copyright Copyright (C) 2012 ImpressPages LTD.
+ * @license see ip_license.html
+ */
+
+namespace Modules\standard\configuration;
+
+if (!defined('CMS')) exit;
+
+
+class Model{
+
+ const CONFIG_FILE_NAME = 'ip_config.php';
+
+ /**
+ *
+ * Change constant value in ip_config.php file
+ * @param stsring $constantName
+ * @param string $curValue
+ * @param string $newValue
+ * @throws \Exception
+ */
+ public function changeConfigurationConstantValue($constantName, $curValue, $newValue) {
+ if (!is_writable(BASE_DIR.self::CONFIG_FILE_NAME)) {
+ throw new \Exception("Error: ip_config.php file is not writable. You can make it writable using FTP client or Linux chmod command.");
+ }
+ $config = file_get_contents(BASE_DIR.self::CONFIG_FILE_NAME);
+
+ $count;
+ $config = preg_replace('/[\'\"]'.$constantName.'[\'\"][ \n]*,[ \n]*[\'\"]'.$curValue.'[\'\"]/s', "'".$constantName."', '".$newValue."'", $config, 1, $count);
+
+ if ($count != 1) {
+ throw new \Exception('Can\'t find theme definition in configuration file');
+ }
+
+ file_put_contents(BASE_DIR.self::CONFIG_FILE_NAME, $config);
+ }
+}

0 comments on commit e400102

Please sign in to comment.