Index: trunk/kernel/include/theme.php =================================================================== diff -u -N -r766 -r850 --- trunk/kernel/include/theme.php (.../theme.php) (revision 766) +++ trunk/kernel/include/theme.php (.../theme.php) (revision 850) @@ -152,10 +152,11 @@ function IsWriteablePath($new_file = false) { + $path = $this->FullPath(); $path = str_replace('//','/',$path); $ret = $new_file ? is_writable(dirname($path)): is_writable($path); - + if(!$ret) { $this->SetError(THEME_ERROR_1, 1); @@ -245,8 +246,10 @@ $f->Set(array("FilePath","FileName","ThemeId","FileType","Description"), array($Path,$Name,$ThemeId,$Type,$Description)); $f->Create(); - if($contents!=NULL) - $f->SaveFileContents($contents); + if($contents!==NULL) + { + $f->SaveFileContents($contents,$Name); + } //echo $f->Get("FilePath")."/".$f->Get("FileName")."
\n"; return $f; } @@ -473,6 +476,16 @@ $dir = $this->ThemeDirectory(); if(!is_dir($dir)) mkdir($dir); + if(is_dir($dir)) + { + $fp = fopen($dir.'/index.tpl',"w"); + if($fp) + { + fwrite($fp,''); + fclose($fp); + } + + } } function Delete() @@ -584,6 +597,7 @@ $t->Set(array("Name","Description","Enabled","PrimaryTheme","CacheTimeout"), array($Name,$Description,$Enabled,$Primary,$CacheTimeout)); $t->Create(); + $t->Files->ThemeId=$t->Get("ThemeId"); if($Primary==1) { $sql = "UPDATE ".$this->SourceTable." SET PrimaryTheme=0 WHERE ThemeId != ".$t->Get("ThemeId"); @@ -595,6 +609,13 @@ function EditTheme($ThemeId,$Name,$Description,$Enabled,$Primary, $CacheTimeout) { $t = $this->GetItem($ThemeId); + $oldName = $t->Get("Name"); + if($oldName!=$Name) + { + $dir=dirname($t->ThemeDirectory()); + if(!rename($dir.'/'.$oldName,$dir.'/'.$Name)) + $Name=$oldName; + } $t->Set(array("Name","Description","Enabled","PrimaryTheme","CacheTimeout"), array($Name, $Description, $Enabled, $Primary, $CacheTimeout)); $t->Dirty(); @@ -646,41 +667,52 @@ $path = $pathtoroot."themes"; $themes = array(); + $HDDThemes=Array(); if ($dir = @opendir($path)) { while (($file = readdir($dir)) !== false) { if($file !="." && $file !=".." && substr($file,0,1)!="_") { - if(is_dir($path."/".$file)) + if(is_dir($path."/".$file)&&file_exists($path."/".$file.'/index.tpl')) { $file = strtolower($file); $themes[$file]=0; + $HDDThemes[]=$file; } } } } closedir($dir); + + $sql = 'SELECT ThemeId AS i,Name AS n FROM '.$this->SourceTable; + $DBThemes=Array(); + if($rs = $this->adodbConnection->Execute($sql)) + { + while(!$rs->EOF) + { + $DBThemes[$rs->fields['i']] = $fullpath.$rs->fields['n']; + $rs->MoveNext(); + } + $rs->Free(); + } + + $missingThemes=array_diff($HDDThemes,$DBThemes); + $orphanThemes=array_diff($DBThemes,$HDDThemes); + + if($orphanThemes) + { + $sql = 'DELETE FROM '.$this->SourceTable.' WHERE ThemeId IN('.join(',',array_keys($orphanThemes)).')'; + $this->adodbConnection->Execute($sql); + $sql = 'DELETE FROM '.GetTablePrefix().'ThemeFiles WHERE ThemeId IN('.join(',',array_keys($orphanThemes)).')'; + $this->adodbConnection->Execute($sql); + } $this->Clear(); - $this->Query_Item("SELECT * FROM ".$this->SourceTable); - foreach($this->Items as $i) - { - $n = strtolower($i->Get("Name")); - $themes[$n] = $i->Get("ThemeId"); - } - $names = array_keys($themes); - for($i=0;$iAddTheme($name,"New Theme",0,0); - $themes[$name] = $t->Get("ThemeId"); - } - } - $where = implode(",",array_values($themes)); - $sql = "DELETE FROM ".$this->SourceTable." WHERE ThemeId NOT IN ($where)"; + foreach($missingThemes as $theme) + { + $t=$this->AddTheme($theme,"New Theme",0,0); + $t->Files->FindMissingFiles($t->Get('Name')); + } } function CopyFromEditTable()