7272 */
7373class DATA {
7474
75+ private $ metadata ;
76+
7577 /**
7678 *
7779 */
78- public function Data () {
80+ public function __construct () {
7981
8082 // Defined in config.php.
8183 include_once METADATAPATH ;
84+ $ this ->metadata = new Metadata ();
8285
8386 }
8487
@@ -103,14 +106,14 @@ public function set_section() {
103106 * $key is the element of metadata you want to retrieve.
104107 */
105108 public function page_metadata ($ page , $ key ) {
106- return $ this ->_get_metadata (["page " => $ page , "key " => $ key ], "page " );
109+ return $ this ->metadata -> get_metadata (["page " => $ page , "key " => $ key ], "page " );
107110 }
108111
109112 /**
110113 *
111114 */
112115 public function section_metadata ($ section , $ key ) {
113- return $ this ->_get_metadata (["section " => $ section , "key " => $ key ], "section " );
116+ return $ this ->metadata -> get_metadata (["section " => $ section , "key " => $ key ], "section " );
114117 }
115118
116119 // Setting page and section.
@@ -119,14 +122,14 @@ public function section_metadata($section, $key) {
119122 * $page/$section, $key and $value should make sense...
120123 */
121124 public function set_page_metadata ($ page , $ key , $ value ) {
122- $ this ->_set_metadata (["page " => $ page , "key " => $ key , "value " => $ value ]);
125+ $ this ->metadata -> set_metadata (["page " => $ page , "key " => $ key , "value " => $ value ]);
123126 }
124127
125128 /**
126129 *
127130 */
128131 public function set_section_metadata ($ section , $ key , $ value ) {
129- $ this ->_set_metadata (["section " => $ section , "key " => $ key , "value " => $ value ]);
132+ $ this ->metadata -> set_metadata (["section " => $ section , "key " => $ key , "value " => $ value ]);
130133 }
131134
132135 // DEPRECATED.
@@ -135,97 +138,9 @@ public function set_section_metadata($section, $key, $value) {
135138 * Directly access an item.
136139 */
137140 public function metadata ($ type , $ item , $ key ) {
138- if ($ this ->test_for_metadata ($ type , $ item , $ key )) {
139- return $ this ->$ type [$ item ][$ key ];
140- }
141- else {
142- return "INVALID METADATA: $ type [$ item ][ $ key] " ;
143- }
144- }
145-
146- // Test for the presence of something.
147-
148- /**
149- * Eg $exists = $DATA->test_for_metadata("page", "about", "title")
150- */
151- public function test_for_metadata ($ type , $ item , $ key ) {
152- $ dataarray =& $ this ->$ type ;
153-
154- if (isset ($ dataarray [$ item ][$ key ])) {
155- return TRUE ;
156- }
157- else {
158- return FALSE ;
159- }
141+ return "ACCESS DEBIED FOR type[ $ item][ $ key] USE THE PUBLIC METHODS " ;
160142 }
161143
162- //
163- // PRIVATE METADATA ACCESS FUNCTIONS //
164- // .
165-
166- /**
167- * Only accessed through page_metadata() or section_metadata()
168- */
169- public function _get_metadata ($ args = "" , $ type ) {
170- // $type is either 'page' or 'section'
171- global $ this_page , $ this_section ;
172-
173- if (is_array ($ args )) {
174- $ item = $ args [$ type ];
175- $ key = $ args ['key ' ];
176- }
177- else {
178- $ var = "this_ " . $ type ;
179- // $this_page or $this_section.
180- $ item = $ $ var ;
181- $ key = $ args ;
182- }
183-
184- twfy_debug ("DATA " , "$ type: $ item, $ key " );
185- $ dataarray =& $ this ->$ type ;
186-
187- if ($ this ->test_for_metadata ($ type , $ item , $ key )) {
188- $ return = $ dataarray [$ item ][$ key ];
189- $ debugtext = "Key: " . $ type . "[ " . $ item . "][ " . $ key . "] " ;
190-
191- }
192- elseif ($ this ->test_for_metadata ($ type , "default " , $ key )) {
193- $ return = $ dataarray ["default " ][$ key ];
194- $ debugtext = "Key: " . $ type . "['default'][ " . $ key . "] " ;
195-
196- }
197- else {
198- $ return = FALSE ;
199- $ debugtext = "No metadata found for key ' $ key' " ;
200- }
201-
202- twfy_debug ("DATA " , "$ debugtext, returning ' " . print_r ($ return , TRUE ) . "'. " );
203-
204- return $ return ;
205- }
206-
207- /**
208- *
209- */
210- public function _set_metadata ($ args ) {
211-
212- if (isset ($ args ["section " ])) {
213- $ type = "section " ;
214- $ item = $ args ["section " ];
215- }
216- else {
217- $ type = "page " ;
218- $ item = $ args ["page " ];
219- }
220-
221- $ key = $ args ["key " ];
222- $ value = $ args ["value " ];
223-
224- twfy_debug ("DATA " , "Setting: " . $ type . "[ " . $ item . "][ " . $ key . "] = ' " . print_r ($ value , TRUE ) . "' " );
225-
226- $ dataarray =& $ this ->$ type ;
227- $ dataarray [$ item ][$ key ] = $ value ;
228- }
229144
230145}
231146
0 commit comments