Rev 224 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
104 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
5 | * Copyright 2019 Daniel Marschall, ViaThinkSoft |
||
6 | * |
||
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
||
8 | * you may not use this file except in compliance with the License. |
||
9 | * You may obtain a copy of the License at |
||
10 | * |
||
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
12 | * |
||
13 | * Unless required by applicable law or agreed to in writing, software |
||
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
16 | * See the License for the specific language governing permissions and |
||
17 | * limitations under the License. |
||
18 | */ |
||
19 | |||
112 | daniel-mar | 20 | if (!defined('IN_OIDPLUS')) die(); |
21 | |||
104 | daniel-mar | 22 | class OIDplusPagePublicObjects extends OIDplusPagePlugin { |
23 | public function type() { |
||
24 | return 'public'; |
||
25 | } |
||
26 | |||
222 | daniel-mar | 27 | public static function getPluginInformation() { |
28 | $out = array(); |
||
29 | $out['name'] = 'Objects'; |
||
30 | $out['author'] = 'ViaThinkSoft'; |
||
31 | $out['version'] = null; |
||
32 | $out['descriptionHTML'] = null; |
||
33 | return $out; |
||
34 | } |
||
35 | |||
104 | daniel-mar | 36 | public function priority() { |
37 | return 0; |
||
38 | } |
||
39 | |||
40 | public function action(&$handled) { |
||
41 | } |
||
42 | |||
43 | public function init($html=true) { |
||
44 | } |
||
45 | |||
46 | public function cfgSetValue($name, $value) { |
||
47 | } |
||
48 | |||
49 | public function gui($id, &$out, &$handled) { |
||
50 | if ($id === 'oidplus:system') { |
||
51 | $handled = true; |
||
52 | |||
53 | $out['title'] = OIDplus::config()->systemTitle(); // 'Object Database of ' . $_SERVER['SERVER_NAME']; |
||
148 | daniel-mar | 54 | $out['icon'] = 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/system_big.png'; |
104 | daniel-mar | 55 | $out['text'] = file_get_contents('welcome.html'); |
56 | |||
57 | if (strpos($out['text'], '%%OBJECT_TYPE_LIST%%') !== false) { |
||
58 | $tmp = '<ul>'; |
||
227 | daniel-mar | 59 | foreach (OIDplus::getEnabledObjectTypes() as $ot) { |
107 | daniel-mar | 60 | $tmp .= '<li><a '.oidplus_link($ot::root()).'>'.htmlentities($ot::objectTypeTitle()).'</a></li>'; |
104 | daniel-mar | 61 | } |
62 | $tmp .= '</ul>'; |
||
63 | $out['text'] = str_replace('%%OBJECT_TYPE_LIST%%', $tmp, $out['text']); |
||
64 | } |
||
65 | |||
66 | return $out; |
||
67 | } |
||
117 | daniel-mar | 68 | |
147 | daniel-mar | 69 | // Objects will be loaded by includes/classes/OIDplusGui.class.php , if $handled=False all page plugins were probed |
104 | daniel-mar | 70 | } |
71 | |||
106 | daniel-mar | 72 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
104 | daniel-mar | 73 | if ($nonjs) { |
148 | daniel-mar | 74 | $json[] = array('id' => 'oidplus:system', 'icon' => 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/system.png', 'text' => 'System'); |
104 | daniel-mar | 75 | |
76 | $parent = ''; |
||
150 | daniel-mar | 77 | $res = OIDplus::db()->query("select parent from ".OIDPLUS_TABLENAME_PREFIX."objects where id = ?", array($req_goto)); |
104 | daniel-mar | 78 | while ($row = OIDplus::db()->fetch_object($res)) { |
79 | $parent = $row->parent; |
||
80 | } |
||
81 | |||
82 | $objTypesChildren = array(); |
||
227 | daniel-mar | 83 | foreach (OIDplus::getEnabledObjectTypes() as $ot) { |
104 | daniel-mar | 84 | $icon = 'plugins/objectTypes/'.$ot::ns().'/img/treeicon_root.png'; |
85 | $json[] = array('id' => $ot::root(), 'icon' => $icon, 'text' => $ot::objectTypeTitle()); |
||
86 | |||
87 | try { |
||
106 | daniel-mar | 88 | $tmp = OIDplusObject::parse($req_goto); |
104 | daniel-mar | 89 | } catch (Exception $e) { |
90 | $tmp = null; |
||
91 | } |
||
92 | if (!is_null($tmp) && ($ot == get_class($tmp))) { |
||
93 | // TODO: Instead of just having 3 levels (parent, this and children), it would be better if we'd had a full tree of all parents |
||
94 | // on the other hand, for giving search engines content, this is good enough |
||
150 | daniel-mar | 95 | if (empty($parent)) { |
96 | $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."objects where " . |
||
97 | "parent = ? or " . |
||
98 | "id = ? " . |
||
99 | "order by ".OIDplus::db()->natOrder('id'), array($req_goto, $req_goto)); |
||
100 | } else { |
||
101 | $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."objects where " . |
||
102 | "parent = ? or " . |
||
103 | "id = ? or " . |
||
104 | "id = ? ". |
||
105 | "order by ".OIDplus::db()->natOrder('id'), array($req_goto, $req_goto, $parent)); |
||
106 | } |
||
107 | |||
104 | daniel-mar | 108 | $z_used = 0; |
109 | $y_used = 0; |
||
110 | $x_used = 0; |
||
111 | $stufe = 0; |
||
112 | $menu_entries = array(); |
||
113 | $stufen = array(); |
||
114 | while ($row = OIDplus::db()->fetch_object($res)) { |
||
115 | $obj = OIDplusObject::parse($row->id); |
||
116 | if (is_null($obj)) continue; // might happen if the objectType is not available/loaded |
||
117 | if (!$obj->userHasReadRights()) continue; |
||
118 | $txt = $row->title == '' ? '' : ' -- '.htmlentities($row->title); |
||
119 | |||
120 | if ($row->id == $parent) { $stufe=0; $z_used++; } |
||
106 | daniel-mar | 121 | if ($row->id == $req_goto) { $stufe=1; $y_used++; } |
122 | if ($row->parent == $req_goto) { $stufe=2; $x_used++; } |
||
104 | daniel-mar | 123 | |
124 | $menu_entry = array('id' => $row->id, 'icon' => '', 'text' => $txt, 'indent' => 0); |
||
125 | $menu_entries[] = $menu_entry; |
||
126 | $stufen[] = $stufe; |
||
127 | } |
||
128 | if ($x_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 2) $menu_entry['indent'] += 1; |
||
129 | if ($y_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 1) $menu_entry['indent'] += 1; |
||
130 | if ($z_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 0) $menu_entry['indent'] += 1; |
||
131 | $json = array_merge($json, $menu_entries); |
||
132 | } |
||
133 | } |
||
134 | |||
135 | return true; |
||
136 | } else { |
||
137 | if (isset($req_goto)) { |
||
145 | daniel-mar | 138 | $goto = $req_goto; |
139 | $path = array(); |
||
140 | while (true) { |
||
141 | $path[] = $goto; |
||
150 | daniel-mar | 142 | $res = OIDplus::db()->query("select parent from ".OIDPLUS_TABLENAME_PREFIX."objects where id = ?", array($goto)); |
145 | daniel-mar | 143 | if (OIDplus::db()->num_rows($res) == 0) break; |
144 | $row = OIDplus::db()->fetch_array($res); |
||
145 | $goto = $row['parent']; |
||
150 | daniel-mar | 146 | if ($goto == '') continue; |
145 | daniel-mar | 147 | } |
104 | daniel-mar | 148 | |
145 | daniel-mar | 149 | $goto_path = array_reverse($path); |
104 | daniel-mar | 150 | } else { |
151 | $goto_path = null; |
||
152 | } |
||
153 | |||
154 | $objTypesChildren = array(); |
||
227 | daniel-mar | 155 | foreach (OIDplus::getEnabledObjectTypes() as $ot) { |
145 | daniel-mar | 156 | $child = array('id' => $ot::root(), |
157 | 'text' => $ot::objectTypeTitle(), |
||
158 | 'state' => array("opened" => true), |
||
159 | 'icon' => 'plugins/objectTypes/'.$ot::ns().'/img/treeicon_root.png', |
||
160 | 'children' => OIDplusTree::tree_populate($ot::root(), $goto_path) |
||
161 | ); |
||
104 | daniel-mar | 162 | if (!file_exists($child['icon'])) $child['icon'] = null; // default icon (folder) |
163 | $objTypesChildren[] = $child; |
||
164 | } |
||
165 | |||
166 | $json[] = array( |
||
167 | 'id' => "oidplus:system", |
||
168 | 'text' => "Objects", |
||
169 | 'state' => array( |
||
170 | "opened" => true, |
||
171 | // "selected" => true) // "selected" ist buggy: 1) Das select-Event wird beim Laden nicht gefeuert 2) Die direkt untergeordneten Knoten lassen sich nicht öffnen (laden für ewig) |
||
172 | ), |
||
148 | daniel-mar | 173 | 'icon' => 'plugins/'.basename(dirname(__DIR__)).'/'.basename(__DIR__).'/system.png', |
104 | daniel-mar | 174 | 'children' => $objTypesChildren |
175 | ); |
||
176 | |||
177 | return true; |
||
178 | } |
||
179 | } |
||
108 | daniel-mar | 180 | |
181 | public function tree_search($request) { |
||
182 | $ary = array(); |
||
183 | if ($obj = OIDplusObject::parse($request)) { |
||
184 | if ($obj->userHasReadRights()) { |
||
185 | do { |
||
186 | $ary[] = $obj->nodeId(); |
||
187 | } while ($obj = $obj->getParent()); |
||
188 | $ary = array_reverse($ary); |
||
189 | } |
||
190 | } |
||
191 | return $ary; |
||
192 | } |
||
104 | daniel-mar | 193 | } |