-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewobjects.php
More file actions
512 lines (464 loc) · 19.2 KB
/
Copy pathviewobjects.php
File metadata and controls
512 lines (464 loc) · 19.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
<?php
/************************************************************************/
/* Oscailt */
/* Indepenent Media Centre Content Management System */
/* ==================================================================== */
/* Copyright (c)2003-2005 by Independent Media Centre Ireland */
/* http://www.indymedia.ie */
/* Development List: oscailt@lists.indymedia.org */
/* See contributions.txt for the list of contributors */
/* */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation. http://www.gnu.org/copyleft/gpl.html */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/************************************************************************/
/* Description: */
/* This file displays basic information about the objects like their */
/* ids, type, oscailt class, name, cache filename. It can sort by and */
/* filter by various fields. */
/************************************************************************/
require_once("oscailt_init.inc");
require_once("objects/indyobjects/indydataobjects.inc");
$OSCAILT_SCRIPT = "viewobjects.php";
addToPageTitle("View Object Usage");
function writeLocalAdminHeader()
{
global $OSCAILT_SCRIPT;
?>
<TABLE class='admin'>
<TR class='admin'><TD class='admin'><a href="<?=$OSCAILT_SCRIPT?>?sort=none">Raw from Db</a> | <a href="<?=$OSCAILT_SCRIPT?>?sort=type-site">Sort By Type & Site Id</a>
| <a href="<?=$OSCAILT_SCRIPT?>?sort=id-type-site">Sort By Obj Id & Type & Site Id</a> </TD></TR>
</TABLE>
<?
}
function getDropdownList( $ObjectArray, $FilteredSelection)
{
$js_string = "<option value=\"No Filter\">No Filter</option>";
$form_string ="<option value=\"";
foreach ( $ObjectArray as $each_type)
{
if ($each_type == $FilteredSelection)
{
$js_string .= "<option selected value=\"" . $each_type ."\">" . $each_type . "</option>";
}
else
{
$js_string .= $form_string . $each_type ."\">" . $each_type . "</option>";
}
}
return $js_string;
}
function getHeadings( $HeadingsList)
{
$table_str = "";
foreach ( $HeadingsList as $each_heading)
{
$table_str .= "<th class=admin> ".ucfirst($each_heading)." </th>";
}
return $table_str;
}
// The input is an array of the meta data tags to use
function getDataFields($ObjectPtr, $DataList)
{
$table_str = "";
foreach ( $DataList as $each_field)
{
if (trim($each_field) == "protected") {
$each_value = $ObjectPtr->protected ? "<b>yes</b>" : "no";
} else {
$each_value = $ObjectPtr->getMeta($each_field);
}
$table_str .= "<td class=admin> ".$each_value." </td>";
}
return $table_str;
}
/******************************************************************************/
/* This function displays a list of all the object ids created and their type */
/* It can sort them by type, site and object id */
/* It can also filter by object type, site id and oscailt class. Any or all */
/* filters can be switched on or off */
/******************************************************************************/
function writeObjectList( $sort_type='none')
{
global $legalDataTypes, $system_config, $userLanguage, $obj_man, $OSCAILT_SCRIPT;
// Making 2 arrays. They must be in sync. It can be done better, but too much hassel
$FilterHdrArray=array("feedimport" => array("page limit","url", "title","convert from UTF-8", "republish"),
"feedexport" => array("feedtype","feedversion"),
"document" => array("protected"),
"box" => array("protected"),
"link" => array("link URL", "protected"),
"list" => array("Bullet Type"),
"site" => array("Use Non-Default Style Sheet Files", "protected"));
$FilterArray = array("feedimport" => array("pagelimit","url", "title","convertfromutf8", "show_republish"),
"feedexport" => array("feedtype","feedversion"),
"document" => array("protected"),
"box" => array("protected"),
"link" => array("linkdestination", "protected"),
"list" => array("bullettype"),
"site" => array("different_css", "protected"));
//$available_objects = $obj_man->obj_set->getAllObjectIDs();
$available_objects = $obj_man->obj_set->getObjectStubs();
$total_objs = count($available_objects);
$filter_object_on = false;
$filter_site_on = false;
$filter_class_on = false;
$def_filter_object="No Filter";
$def_filter_site ="No Filter";
$def_filter_class ="No Filter";
if ( isset($_REQUEST['filter_object'])) { $def_filter_object = $_REQUEST['filter_object'];}
if ( isset($_REQUEST['filter_site'])) { $def_filter_site = $_REQUEST['filter_site'];}
if ( isset($_REQUEST['filter_class'])) { $def_filter_class = $_REQUEST['filter_class'];}
# The value No Filter can still be set in which case it is really off.
if ( $def_filter_object != "No Filter") { $filter_object_on = true; }
if ( $def_filter_site != "No Filter") { $filter_site_on = true; }
if ( $def_filter_class != "No Filter") { $filter_class_on = true; }
# If we filter on the object name then we will display the object name.
$col_span_size = 8;
if ( $filter_object_on == true )
{
$show_pagelayout = false;
$show_newslink = false;
// Not all object types have a layout reference, so we only get it for those that do.
$pageRefTypes = array("document", "preferences", "box", "list", "newswire", "feature", "article", "contact", "publish", "events", "search", "gallery", "archive", "comments", "feedimport");
if (in_array($def_filter_object, $pageRefTypes)) $show_pagelayout = true;
if ($def_filter_object == "picturebox" || $def_filter_object == "headlinebox" ) $show_newslink = true;
# **** BIG FIX TO BE DONE **** Assuming language code is en. For other languages
# we need to move this code to later when we know the code. In fact if you have 2
# or more per object type then you need 2 or more calls.
# You could make use of IndyObjectSet getObjectAvailableLanguages()
$obj_name_info = $obj_man->obj_set->getObjectInfoByTypename($def_filter_object, "en" );
$page_obj_names= $obj_man->obj_set->getObjectInfoByTypename("page", "en" );
if ($show_newslink == true)
$news_obj_names= $obj_man->obj_set->getObjectInfoByTypename("newswire", "en" );
$col_span_size = 9;
if(in_array($def_filter_object, array_keys($FilterArray)) == true) {
$col_span_size = $col_span_size + count(array_values($FilterArray[$def_filter_object]));
}
}
?>
<table align=center>
<tr class=admin>
<th class=admin colspan=<?=$col_span_size?>>Objects: Total = <?=$total_objs?> </td>
</tr>
<?
if ($sort_type != 'none')
{
if ($sort_type == 'type-site') $sort_text = "Type and Site";
else if ($sort_type == 'id-type-site') $sort_text = "Type, Site and Object Id";
?>
<tr class=admin>
<th class=admin colspan=<?=$col_span_size?>>Sorted by <?=$sort_text?> </td>
</tr>
<?
}
if ( $filter_object_on == true )
{
$t_object_url = "<a href='admin.php?action=list&site_id=1&obj_type=".$def_filter_object."&obj_language=en'>". $def_filter_object."</a>";
// Previously was just $def_filter_object
?>
<tr class=admin>
<td class=admin colspan=<?=$col_span_size?>>Filtering by Object Type: <b><?=$t_object_url?></b> </td>
</tr>
<?
}
# Generate the form selections ... would it be more efficient to print each selection or
# as here generate fulls string and then print? Probably sub-millisecond difference anyhow.
?>
<FORM name="viewobjsform" action="<?=$OSCAILT_SCRIPT?>" method="post">
<tr class=admin>
<td align=center colspan=<?=$col_span_size?>><input type=submit name=filter_tag value="Filter"> by Object Type
<select name='filter_object' >
<?
$js_string = getDropdownList(array_keys($legalDataTypes), $def_filter_object);
echo $js_string;
?>
</select>
Site <select name='filter_site' >
<?
$js_string = getDropdownList($obj_man->obj_set->sites, $def_filter_site);
echo $js_string;
?>
</select>
Oscailt Class <select name='filter_class' >
<?
$OscailtClasses = array_unique(array_values($legalDataTypes));
$js_string = getDropdownList($OscailtClasses, $def_filter_class);
echo $js_string;
?>
</select>
</td>
</tr>
</form>
<tr class=admin>
<th class=admin> # </th>
<th class=admin> Object ID </th>
<?
if ( $filter_object_on == true ) {
?>
<th class=admin> Site </th>
<th class=admin>Language Code</th>
<th class=admin> Object Name </th>
<?
} else {
?>
<th class=admin> Object Type </th>
<th class=admin> Site </th>
<th class=admin>Language Code</th>
<?
}
?>
<th class=admin> Oscailt Class </th>
<th class=admin> Object Cache File </th>
<th class=admin> File Exists</th>
<?
// Add a contains field
if ( $filter_object_on == true && ($show_pagelayout == true || $show_newslink == true)) {
// Not all object types have a layout reference, so we only get it for those that do.
if($show_pagelayout == true) {
?> <th class=admin> Page Layout Obj </th> <?
} else if($show_newslink == true) {
?> <th class=admin> Newslink Obj </th> <?
} else {
?> <th class=admin> Page Layout Obj </th> <?
}
if(in_array($def_filter_object, array_keys($FilterArray)) == true) {
$t_headings = getHeadings(array_values($FilterHdrArray[$def_filter_object]));
echo $t_headings;
}
} else {
if(in_array($def_filter_object, array_keys($FilterArray)) == true) {
$t_headings = getHeadings(array_values($FilterHdrArray[$def_filter_object]));
echo $t_headings;
}
}
?>
</tr>
<?
// Grab the data and store in arrays as needed per sort. The PHP sort will rejig all
// the data in all the arrays passed to it.
$counter = 0;
foreach($available_objects as $obj_stub)
{
$arr_order[] = $counter++;
$arr_obj_stub[] = $obj_stub;
$arr_obj_site[] = $obj_stub->site_id;
$arr_obj_type[] = $obj_stub->obj_type;
if ($sort_type == 'id-type-site')
{
$arr_obj_id[] = $obj_stub->obj_id;
}
}
# Best reading up the PHP array_multisort to figure this out..
if ($sort_type == 'type-site')
{
array_multisort($arr_obj_site, $arr_obj_type, $arr_order);
}
else if ($sort_type == 'id-type-site')
{
array_multisort($arr_obj_site, $arr_obj_type, $arr_obj_id, $arr_order);
}
$iRow = 0;
for($aIndex=0;$aIndex < $counter ;$aIndex++)
{
$sortIndex = $arr_order[$aIndex];
if ($sort_type == 'id-type-site')
{
$ob_id = $arr_obj_id[$aIndex];
}
else
{
$ob_id = $arr_obj_stub[$sortIndex]->obj_id;
}
$ob_lang = $arr_obj_stub[$sortIndex]->primary_language_code;
$lang_list = $obj_man->obj_set->getObjectAvailableLanguages($ob_id);
$obj_typename = strtolower($arr_obj_type[$aIndex]);
$ob_site = $arr_obj_site[$aIndex];
$ob_class= $legalDataTypes[$obj_typename];
# This filtering could be done before the sorting. It would be a lot more efficient
# but it was done here, because it allowed for easier debug during development.
if ( $filter_object_on == true && $obj_typename != $def_filter_object) { continue; }
if ( $filter_site_on == true && $ob_site != $def_filter_site) { continue; }
if ( $filter_class_on == true && $ob_class != $def_filter_class) { continue; }
$iRow++;
if ( $filter_object_on == true )
{
$ob_name = $obj_name_info[$ob_id];
}
if($obj_typename == "") $obj_typename = "<span class='error'>unknown object type</span>";
$ob_cache_file = $obj_man->obj_set->getIncludeFileRef($ob_id);
$ob_file_exists = "<b>No</b>";
if (file_exists($ob_cache_file)) { $ob_file_exists = "Yes"; }
// If there is more than 1 language then get the list of associated files.
if (count($lang_list) > 1) {
$lang_files = "";
$lang_file_exists = "";
foreach($lang_list as $lang) {
$lang_cache_file = $obj_man->obj_set->getIncludeFileRefByLang($ob_id, $lang);
if (file_exists($lang_cache_file))
$lang_file_exists .= "<BR>Yes";
else
$lang_file_exists .= "<BR>No";
$lang_files .= "<BR>" . $lang_cache_file;
}
$ob_cache_file .= "<BR>".$lang_files;
$ob_file_exists .="<BR>".$lang_file_exists;
}
//if (($filter_object_on != true) && (count($lang_list) > 1)) {
if (count($lang_list) > 1) {
$ob_lang = "";
foreach($lang_list as $lang) {
$ob_lang .= $lang." ";
}
}
?>
<tr class=admin>
<td class=admin align=center> <?=($iRow)?> </td>
<td class=admin align=center> <?=$ob_id?> </td>
<?
// Check for isProtected and display coloured ball -red or green
if ($filter_object_on != true) {
if (count($lang_list) > 1) {
$t_object_grp_url = "";
$t_object_grp_base = "<a href='admin.php?action=list&site_id=".$ob_site."&obj_type=".$obj_typename."&obj_language=";
$t_cnt =0;
foreach($lang_list as $lang) {
$t_object_grp_url .= $t_object_grp_base . $lang ."'>".ucfirst($obj_typename)."_".$lang."</a>";
$t_cnt++;
if ($t_cnt < count($lang_list) ) $t_object_grp_url .= "<BR> ";
}
?> <td class=admin align=left > <?=$t_object_grp_url?> </td> <?
} else {
$t_object_grp_url = "<a href='admin.php?action=list&site_id=".$ob_site."&obj_type=".$obj_typename."&obj_language=en'>".ucfirst($obj_typename)."</a>";
?> <td class=admin align=left > <?=$t_object_grp_url?> </td> <?
}
}
?>
<td class=admin align=center> <?=$ob_site?> </td>
<td class=admin align=center> <?=$ob_lang?> </td>
<?
if ($filter_object_on == true) {
?> <td class=admin align=center> <?=$ob_name?> </td> <?
}
?>
<td class=admin align=center> <?=$ob_class?> </td>
<td class=admin align=left><?=$ob_cache_file?></td>
<td class=admin align=center><?=$ob_file_exists?></td>
<?
if ($filter_object_on == true) {
$new_obj = $obj_man->obj_set->fetchObject($ob_id, "en");
if ($new_obj == false ) {
$page_layout_id = " N/A";
} else {
// Not all object types have a layout reference, so we only get it for those that do.
// Like headlines has newswireobject.
$page_layout_id = false;
if ($show_pagelayout == true) {
$page_layout_id = $new_obj->getPageLayoutRef();
if ($page_layout_id == false )
$page_layout_id = "Not Set Yet";
else
{
if (isset($page_obj_names[$page_layout_id]))
$page_layout_id .= " " .$page_obj_names[$page_layout_id];
else
$page_layout_id = " Set to None ";
}
}
else if($show_newslink == true) {
if ($new_obj->getMeta('newswireobject') > 0)
$page_layout_id = $new_obj->getMeta('newswireobject');
if ($page_layout_id == false )
$page_layout_id = "Not Set Yet";
else
{
if (isset($news_obj_names[$page_layout_id]))
$page_layout_id .= " " .$news_obj_names[$page_layout_id];
else
$page_layout_id = " Set to None ";
}
}
}
if ($show_pagelayout == true || $show_newslink == true) {
?>
<td class=admin align=center> <?=$page_layout_id?> </td>
<?
}
if(in_array($def_filter_object, array_keys($FilterArray)) == true && $new_obj != false ) {
$t_data = getDataFields($new_obj, array_values($FilterArray[$def_filter_object]));
echo $t_data;
}
}
?>
</tr>
<?
}
?>
</table>
<?
// writeJSFunctions();
}
function writeJSFunctions()
{
global $legalDataTypes, $system_config, $obj_man;
# This function is no longer used. It could be updated to re-submit on selection above.
?>
<script type="text/javascript" language="Javascript">
function checkFilterItemChange()
{
if(document.viewobjsform.filter_object.value=="tag_1")
{
// Do the submit
}
}
</script>
<?
}
function writeError($error)
{
?><BR><BR><font class=error><B><?=$error?></B></font><BR><BR><?
}
function loadManagedObjectSet()
{
global $system_config, $OSCAILT_SCRIPT, $obj_man;
# This ultimately loads the object stubs (i.e. basic info) for all known objects.
$obj_man = new indyObjectManager($system_config->xmltypedef_dir, $OSCAILT_SCRIPT);
$obj_man->obj_set = new indyObjectSet($obj_man->type_dir, $obj_man->storage);
$sites = array("*");
$types = array("*");
if(!$obj_man->obj_set->load($sites, $types, $obj_man->action_req))
{
$obj_man->writeUserMessageBox();
writeError("Programme Error: Failed to Load Set of Managed Objects.");
return false;
}
return true;
}
ob_start();
$obj_man = null;
$admin_table_width = "100%";
// loadManagedObjectSet();
if($editor_session->isSessionOpen())
{
writeAdminHeader("editredirects.php","Edit Friendly URLs");
if($editor_session->editor->allowedReadAccessTo("editdataobjects"))
{
writeLocalAdminHeader();
if( loadManagedObjectSet() == true ) {
$sort_mode = 'none';
if ( isset($_REQUEST['sort']))
{
$sort_mode = $_REQUEST['sort'];
}
writeObjectList($sort_mode);
}
}
else $editor_session->writeNoReadPermissionError();
}
else $editor_session->writeNoSessionError();
include_once("adminfooter.inc");
?>