Rev 117 | 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 | |||
27 | public function priority() { |
||
28 | return 0; |
||
29 | } |
||
30 | |||
31 | public function action(&$handled) { |
||
32 | } |
||
33 | |||
34 | public function init($html=true) { |
||
35 | } |
||
36 | |||
37 | public function cfgSetValue($name, $value) { |
||
38 | } |
||
39 | |||
40 | public function gui($id, &$out, &$handled) { |
||
41 | if ($id === 'oidplus:system') { |
||
42 | $handled = true; |
||
43 | |||
44 | $out['title'] = OIDplus::config()->systemTitle(); // 'Object Database of ' . $_SERVER['SERVER_NAME']; |
||
106 | daniel-mar | 45 | $out['icon'] = 'plugins/publicPages/'.basename(__DIR__).'/system_big.png'; |
104 | daniel-mar | 46 | $out['text'] = file_get_contents('welcome.html'); |
47 | |||
48 | if (strpos($out['text'], '%%OBJECT_TYPE_LIST%%') !== false) { |
||
49 | $tmp = '<ul>'; |
||
50 | foreach (OIDplus::getRegisteredObjectTypes() as $ot) { |
||
107 | daniel-mar | 51 | $tmp .= '<li><a '.oidplus_link($ot::root()).'>'.htmlentities($ot::objectTypeTitle()).'</a></li>'; |
104 | daniel-mar | 52 | } |
53 | $tmp .= '</ul>'; |
||
54 | $out['text'] = str_replace('%%OBJECT_TYPE_LIST%%', $tmp, $out['text']); |
||
55 | } |
||
56 | |||
57 | return $out; |
||
58 | } |
||
117 | daniel-mar | 59 | |
60 | // Objects will be loaded by includes/classes/OIDplusGui.class.php , if $hanlded=False all page plugins were probed |
||
104 | daniel-mar | 61 | } |
62 | |||
106 | daniel-mar | 63 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
104 | daniel-mar | 64 | if ($nonjs) { |
106 | daniel-mar | 65 | $json[] = array('id' => 'oidplus:system', 'icon' => 'plugins/publicPages/'.basename(__DIR__).'/system.png', 'text' => 'System'); |
104 | daniel-mar | 66 | |
67 | $parent = ''; |
||
106 | daniel-mar | 68 | $res = OIDplus::db()->query("select parent from ".OIDPLUS_TABLENAME_PREFIX."objects where id = '".OIDplus::db()->real_escape_string($req_goto)."'"); |
104 | daniel-mar | 69 | while ($row = OIDplus::db()->fetch_object($res)) { |
70 | $parent = $row->parent; |
||
71 | } |
||
72 | |||
73 | $objTypesChildren = array(); |
||
74 | foreach (OIDplus::getRegisteredObjectTypes() as $ot) { |
||
75 | $icon = 'plugins/objectTypes/'.$ot::ns().'/img/treeicon_root.png'; |
||
76 | $json[] = array('id' => $ot::root(), 'icon' => $icon, 'text' => $ot::objectTypeTitle()); |
||
77 | |||
78 | try { |
||
106 | daniel-mar | 79 | $tmp = OIDplusObject::parse($req_goto); |
104 | daniel-mar | 80 | } catch (Exception $e) { |
81 | $tmp = null; |
||
82 | } |
||
83 | if (!is_null($tmp) && ($ot == get_class($tmp))) { |
||
84 | // 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 |
||
85 | // on the other hand, for giving search engines content, this is good enough |
||
86 | $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."objects where " . |
||
106 | daniel-mar | 87 | "parent = '".OIDplus::db()->real_escape_string($req_goto)."' or " . |
88 | "id = '".OIDplus::db()->real_escape_string($req_goto)."' " . |
||
104 | daniel-mar | 89 | ((!empty($parent)) ? " or id = '".OIDplus::db()->real_escape_string($parent)."' " : "") . |
90 | "order by ".OIDplus::db()->natOrder('id')); |
||
91 | $z_used = 0; |
||
92 | $y_used = 0; |
||
93 | $x_used = 0; |
||
94 | $stufe = 0; |
||
95 | $menu_entries = array(); |
||
96 | $stufen = array(); |
||
97 | while ($row = OIDplus::db()->fetch_object($res)) { |
||
98 | $obj = OIDplusObject::parse($row->id); |
||
99 | if (is_null($obj)) continue; // might happen if the objectType is not available/loaded |
||
100 | if (!$obj->userHasReadRights()) continue; |
||
101 | $txt = $row->title == '' ? '' : ' -- '.htmlentities($row->title); |
||
102 | |||
103 | if ($row->id == $parent) { $stufe=0; $z_used++; } |
||
106 | daniel-mar | 104 | if ($row->id == $req_goto) { $stufe=1; $y_used++; } |
105 | if ($row->parent == $req_goto) { $stufe=2; $x_used++; } |
||
104 | daniel-mar | 106 | |
107 | $menu_entry = array('id' => $row->id, 'icon' => '', 'text' => $txt, 'indent' => 0); |
||
108 | $menu_entries[] = $menu_entry; |
||
109 | $stufen[] = $stufe; |
||
110 | } |
||
111 | if ($x_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 2) $menu_entry['indent'] += 1; |
||
112 | if ($y_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 1) $menu_entry['indent'] += 1; |
||
113 | if ($z_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 0) $menu_entry['indent'] += 1; |
||
114 | $json = array_merge($json, $menu_entries); |
||
115 | } |
||
116 | } |
||
117 | |||
118 | return true; |
||
119 | } else { |
||
120 | if (isset($req_goto)) { |
||
145 | daniel-mar | 121 | $goto = $req_goto; |
122 | $path = array(); |
||
123 | while (true) { |
||
124 | $path[] = $goto; |
||
125 | $res = OIDplus::db()->query("select parent from ".OIDPLUS_TABLENAME_PREFIX."objects where id = '".OIDplus::db()->real_escape_string($goto)."'"); |
||
126 | if (OIDplus::db()->num_rows($res) == 0) break; |
||
127 | $row = OIDplus::db()->fetch_array($res); |
||
128 | $goto = $row['parent']; |
||
129 | } |
||
104 | daniel-mar | 130 | |
145 | daniel-mar | 131 | $goto_path = array_reverse($path); |
104 | daniel-mar | 132 | } else { |
133 | $goto_path = null; |
||
134 | } |
||
135 | |||
136 | $objTypesChildren = array(); |
||
137 | foreach (OIDplus::getRegisteredObjectTypes() as $ot) { |
||
145 | daniel-mar | 138 | $child = array('id' => $ot::root(), |
139 | 'text' => $ot::objectTypeTitle(), |
||
140 | 'state' => array("opened" => true), |
||
141 | 'icon' => 'plugins/objectTypes/'.$ot::ns().'/img/treeicon_root.png', |
||
142 | 'children' => OIDplusTree::tree_populate($ot::root(), $goto_path) |
||
143 | ); |
||
104 | daniel-mar | 144 | if (!file_exists($child['icon'])) $child['icon'] = null; // default icon (folder) |
145 | $objTypesChildren[] = $child; |
||
146 | } |
||
147 | |||
148 | $json[] = array( |
||
149 | 'id' => "oidplus:system", |
||
150 | 'text' => "Objects", |
||
151 | 'state' => array( |
||
152 | "opened" => true, |
||
153 | // "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) |
||
154 | ), |
||
106 | daniel-mar | 155 | 'icon' => 'plugins/publicPages/'.basename(__DIR__).'/system.png', |
104 | daniel-mar | 156 | 'children' => $objTypesChildren |
157 | ); |
||
158 | |||
159 | return true; |
||
160 | } |
||
161 | } |
||
108 | daniel-mar | 162 | |
163 | public function tree_search($request) { |
||
164 | $ary = array(); |
||
165 | if ($obj = OIDplusObject::parse($request)) { |
||
166 | if ($obj->userHasReadRights()) { |
||
167 | do { |
||
168 | $ary[] = $obj->nodeId(); |
||
169 | } while ($obj = $obj->getParent()); |
||
170 | $ary = array_reverse($ary); |
||
171 | } |
||
172 | } |
||
173 | return $ary; |
||
174 | } |
||
104 | daniel-mar | 175 | } |
176 | |||
177 | OIDplus::registerPagePlugin(new OIDplusPagePublicObjects()); |