XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
theme.php
1<?php
2
3if (!defined('XOOPS_ROOT_PATH')) {
4 exit();
5}
6
8{
9 public $mPackage = [];
10 public $mActiveResource = true;
11
12 public function __construct()
13 {
14 static $initVars;
15 if (isset($initVars)) {
16 $this->mVars = $initVars;
17 return;
18 }
19 $this->initVar('id', XOBJ_DTYPE_INT, '', true);
20 $this->initVar('name', XOBJ_DTYPE_STRING, '', true, 255);
21 $this->initVar('tplset_id', XOBJ_DTYPE_INT, '0', true);
22 $this->initVar('enable_select', XOBJ_DTYPE_BOOL, '0', true);
23 $initVars=$this->mVars;
24 }
25
26 public function loadPackage()
27 {
28 $themeDir = XOOPS_THEME_PATH . '/' . $this->get('name');
29
30 if (file_exists($mnfFile = $themeDir . '/manifesto.ini.php')) {
31 $iniHandler = new XCube_IniHandler($mnfFile, true);
32 $this->mPackage = $iniHandler->getAllConfig();
33 }
34
35 if (isset($this->mPackage['Manifesto'])) {
36 //
37 // If this system can use this theme, add this to list.
38 // @gigamaster merged isset and applied strict comparision ( === )
39 if (isset($this->mPackage['Manifesto'], $this->mPackage['Manifesto']['Depends'])) {
40 $this->mActiveResource = ('Legacy_RenderSystem' === $this->mPackage['Manifesto']['Depends']);
41 }
42 } else {
43 $file = XOOPS_THEME_PATH . '/' . $this->get('name') . '/theme.html';
44 $this->mActiveResource = file_exists($file);
45 }
46 }
47
48 public function isActiveResource()
49 {
50 return $this->mActiveResource;
51 }
52}
53
55{
56 public $mTable = 'legacyrender_theme';
57 public $mPrimary = 'id';
58 public $mClass = 'LegacyRenderThemeObject';
59
60 public function &getByName($themeName)
61 {
62 $criteria = new Criteria('name', $themeName);
63 $obj =& $this->getObjects($criteria);
64 if ((is_countable($obj) ? count($obj) : 0) > 0) {
65 return $obj[0];
66 }
67 // @gigamaster split workflow
68 $obj =& $this->create();
69 return $obj;
70 }
71
75 public function searchThemes()
76 {
77 $themeList = [];
78
79 if ($handler=opendir(XOOPS_THEME_PATH)) {
80 while (false !== ($dir=readdir($handler))) {
81 if ('.' === $dir || '..' === $dir) {
82 continue;
83 }
84
85 $themeDir= XOOPS_THEME_PATH . '/' . $dir;
86 if (is_dir($themeDir)) {
87 $manifesto = [];
88 if (file_exists($mnfFile = $themeDir . '/manifesto.ini.php')) {
89 $iniHandler = new XCube_IniHandler($mnfFile, true);
90 $manifesto = $iniHandler->getAllConfig();
91 }
92
93 if ((is_countable($manifesto) ? count($manifesto) : 0) > 0) {
94 //
95 // If this system can use this theme, add this to list.
96 // @gigamaster merged isset
97//if (isset($manifesto['Manifesto']) && isset($manifesto['Manifesto']['Depends']) && preg_match('/Legacy_RenderSystem(\s|,|$)/', $manifesto['Manifesto']['Depends'])) {
98
99 if (isset($manifesto['Manifesto'], $manifesto['Manifesto']['Depends']) && preg_match('/Legacy_RenderSystem(\s|,|$)/', $manifesto['Manifesto']['Depends'])) {
100 $themeList[]=$dir;
101 }
102 } else {
103 $file= $themeDir . '/theme.html';
104 if (file_exists($file)) {
105 $themeList[]=$dir;
106 }
107 }
108 }
109 }
110 closedir($handler);
111 }
112
113 return $themeList;
114 }
115
116 public function updateThemeList()
117 {
118 $diskThemeNames = $this->searchThemes();
119 $DBthemes =& $this->getObjects();
120
121 //
122 // At first, check new theme.
123 //
124 foreach ($diskThemeNames as $name) {
125 $findFlag = false;
126 foreach ($DBthemes as $theme) {
127 if ($theme->get('name') === $name) {
128 $findFlag = true;
129 break;
130 }
131 }
132
133 //
134 // If $findFlag is false, $name is new theme that is not registered to DB, yet.
135 //
136 if (!$findFlag) {
137 $obj =& $this->create();
138 $obj->set('name', $name);
139 $this->insert($obj, true);
140 }
141 }
142
143 //
144 // Next, check themes that we got from DB. If it had removed from disk system,
145 // We also have to remove from DB.
146 //
147 foreach ($DBthemes as $theme) {
148 if (!in_array($theme->get('name'), $diskThemeNames)) {
149 $this->delete($theme, true);
150 }
151 }
152 }
153}
& getObjects($criteria=null, $limit=null, $start=null, $id_as_key=false)
Definition handler.php:83
insert(&$object)
Definition object.php:721