/[eiffelstudio]/trunk/Documentation/tools/web/trunk/drupal/sites/all/modules/isedoc/isedoc.report.inc
ViewVC logotype

Contents of /trunk/Documentation/tools/web/trunk/drupal/sites/all/modules/isedoc/isedoc.report.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 74850 - (show annotations)
Fri Sep 26 17:38:58 2008 UTC (11 years, 3 months ago) by jfiat
File size: 11144 byte(s)
added a way to reorganize the images galleries
1 <?php
2
3 require_once ("isedoc.lib.inc");
4
5 function _isedoc_images_by_nid($a_type='doc') {
6 $results = array();
7
8 $l_body_filter = 'REGEXP \'[[.[.]][[.[.]]Image:[a-z0-9:_ -]*([[.|.]]|[[.].]][[.].]])\' ';
9 $sql = "SELECT n.nid, n.title FROM {node} n INNER JOIN {node_revisions} r ON n.nid = r.nid AND n.vid = r.vid WHERE n.type = '$a_type' AND LOWER(r.body) $l_body_filter ";
10 $sql .= " ORDER BY n.nid, n.vid ";
11
12 $pat = '/\[\[Image:([a-zA-Z0-9:_ -]+)(\||\]\])/';
13 $res = db_query($sql);
14 while ($r = db_fetch_array($res)) {
15 $nid = $r['nid'];
16 $n = node_load($nid);
17 if ($n) {
18 $n_bid = $n->book['bid'];
19 preg_match_all($pat, $n->body, $matches, PREG_PATTERN_ORDER);
20 if (count($matches[1]) > 0) {
21 foreach($matches[1] as $mk => $i_title) {
22 $t = strtolower($i_title);
23 //if (!isset($results[$t])) { $results[$t]= array(); }
24 $results[$t][$nid] = $n_bid;
25 }
26 }
27 } else {
28 drupal_set_message("Can not load node #$nid");
29 }
30 }
31
32 //drupal_set_message("results=".var_dump_r($results));
33 return $results;
34 }
35
36 function isedoc_gallery_taxonomy($vid,$a_name) {
37 //drupal_set_message("isedoc_gallery_taxonomy($vid,$a_name) .. ");
38 $n = strtolower($a_name);
39 $sqlres = db_query("SELECT tid,vid,name,description,weight FROM {term_data} WHERE vid = '%s' AND LOWER(name) = LOWER('%s')", $vid, $n);
40 if ($sqlres) {
41 $res = db_fetch_object($sqlres);
42 }
43 if ($res) {
44 //drupal_set_message("isedoc_gallery_taxonomy($vid,$a_name) -> tid=".$res->tid . " name=".$res->name);
45 return $res;
46 } else {
47 $tid = db_result (db_query("SELECT tid FROM {term_data} WHERE vid = '%s' AND LOWER(name) = LOWER('%s')", $vid, 'documentation'));
48 $parents = taxonomy_get_parents ($tid);
49 if ($parents) {
50 $parent = array_shift ($parents);
51 $parent = $parent->tid;
52 } else {
53 $parent = 0;
54 }
55 $t = array('parent' => array($parent), 'vid' => $vid, 'name' => $n, "description" => "Images for book $a_name");
56 $st = taxonomy_save_term(&$t);
57 //drupal_set_message("taxonomy_save_term($vid, $a_name) -> $st");
58 return isedoc_gallery_taxonomy($vid,$a_name);
59 }
60 }
61 function isedoc_gallery_set_taxonomy(&$node,$vid,$a_name) {
62 //drupal_set_message("isedoc_gallery_set_taxonomy($vid,$a_name)");
63
64 $taxo = isedoc_gallery_taxonomy($vid, $a_name);
65
66 $o = taxonomy_nodeapi($node, 'load');
67 $taxonomy = $o['taxonomy'];
68 $taxonomy[$taxo->tid] = $taxo;
69
70 $node->taxonomy = $taxonomy;
71 }
72
73 function isedoc_report($a_type='doc',$target, $a_op='') {
74 drupal_add_css(drupal_get_path('module', 'system') .'/system.css');
75 drupal_add_js('misc/collapse.js');
76 $output = '';
77 if (user_access('admin isedoc') or user_access('query isedoc')) {
78 switch ($a_type) {
79 case 'gallery':
80 $output .= "Gallery $target";
81
82 /* Build the images usage by nid */
83 $cat = _isedoc_images_by_nid();
84
85 //$galleries = taxonomy_get_tree(_image_gallery_get_vid(), $tid, -1, 3);
86 $vid = db_result (db_query ("SELECT vid FROM {vocabulary} WHERE module='image_gallery'"));
87 $tid = db_result (db_query("SELECT tid FROM {term_data} WHERE vid = '%s' AND LOWER(name) = LOWER('%s')", $vid, $target));
88 if ($tid) {
89 $sql = "SELECT n.nid, n.title FROM {node} n ";
90 $sql .= "INNER JOIN {term_node} t ON t.tid = '%s' ";
91 $sql .= "INNER JOIN {node_revisions} r ON r.nid = t.nid AND r.vid = t.vid ";
92 $sql .= "WHERE n.nid = t.nid AND n.vid = r.vid ";
93 $sql .= "ORDER BY t.nid, t.vid ";
94 $res = db_query($sql, $tid);
95
96 if ($res) {
97 $output .= "<ol>";
98 while ($v = db_fetch_array($res)) {
99 $b_save = FALSE;
100
101 $v_nid = $v['nid'];
102 $v_title = strtolower($v['title']);
103 $v_node = node_load($v_nid);
104 //drupal_set_message("image $v_title: " .var_dump_r($v_node));
105
106 //Too slow: $refs = isedoc_pages_referencing_image($v_title);
107 if (isset($cat[$v_title])) {
108 $refs =& $cat[$v_title];
109 $nb = count($refs);
110 //$refs = array_unique($refs);
111 } else {
112 $nb = 0;
113 $refs = NULL;
114 }
115 //drupal_set_message("img=$v_title -> ". count($refs));
116
117 $output .= "<li>";
118 $output .= $v_title;
119 $output .= " " . l("view", "node/".$v_nid);
120 //$output .= ": $nb";
121 if ($refs) {
122 $bids = array();
123 foreach($refs as $r_nid => $r_bid) {
124 $bids[$r_bid][] = $r_nid;
125 }
126 switch (count($bids)) {
127 case 0:
128 $output .= ":<strong> UNUSED</strong>";
129 isedoc_gallery_set_taxonomy(&$v_node, $vid, "unused");
130 $b_save = TRUE;
131 break;
132 case 1:
133 end($bids);
134 $r_bid = key($bids);
135 $r_nids = current($bids);
136 $r_bn = isedoc_book_name($r_bid);
137 $output .= ": only from book '".l($r_bn, "node/$r_bid")."' (count=".count($r_nids).")";
138
139 isedoc_gallery_set_taxonomy(&$v_node, $vid, "book-$r_bn");
140 $b_save = TRUE;
141
142 break;
143 default:
144 $output .= ":<strong class=\"error\"> from ".count($bids)." books (CHECK)</strong>";
145 $output .= "<ul style=\"margin: 0 0 4px 0;\">";
146 foreach($bids as $r_bid => $nids) {
147 $output .= "<li>book ".l(isedoc_book_name($r_bid),"node/$r_bid")." (count=".count($nids).")</li>";
148 /*
149 $output .= "<ul style=\"margin: 0 0 4px 0;\">";
150 foreach($nids as $r_nid) {
151 $output .= "<li>";
152 $output .= l("node/$r_nid", "node/$r_nid");
153 $output .= " from ".$r_bid;
154 $output .= "</li>";
155 }
156 $output .= "</ul>";
157 */
158 }
159 $output .= "</ul>";
160
161 break;
162 }
163 } else {
164 $output .= ":<strong> UNUSED</strong>";
165 isedoc_gallery_set_taxonomy(&$v_node, $vid, "unused");
166 $b_save = TRUE;
167 }
168 $output .= "</li>";
169 if ($b_save) {
170 //$node->revision = FALSE;
171 node_save(&$v_node);
172 //drupal_set_message("Saved: " . l($v_node->title,$v_node->path));
173 }
174 }
175 $output .= "</ol>";
176 }
177 }
178 break;
179 case 'doc':
180 $op = $a_op;
181 if ($op == '') {
182 $op = 'all';
183 }
184 $books = array ();
185 $all_books = book_get_books ();
186 switch ($target) {
187 case 'all':
188 foreach ($all_books as $b) {
189 $books[] = $b['bid'];
190 }
191 break;
192 default:
193 $bn = strtolower ($target);
194 foreach ($all_books as $b) {
195 if (isedoc_book_title_to_book_name_id ($b['title']) == $bn) {
196 $books[] = $b['bid'];
197 }
198 }
199 break;
200 }
201
202 if (count ($books) > 0) {
203 foreach ($books as $bid) {
204 $output .= isedoc_report_on_book ($bid, $op);
205 }
206 if ($op) {
207 $output .= "Report $target ($op): completed.";
208 } else {
209 $output .= "Report $target: completed.";
210 }
211 $output .= "<br/>".l (t ("Report other books"), "isedoc/report/$a_type/_")."<br/>";
212 } else {
213 $output .= "<ul>";
214 $output .= "<li><strong>".l (t ("Report all the books"), "isedoc/report/$a_type/all")."</strong></li>";
215 foreach ($all_books as $b) {
216 $bn = isedoc_book_title_to_book_name_id ($b['title']);
217 $output .= "<li>".l (t ("Report only: ").$bn, "isedoc/report/$a_type/$bn")."</li>";
218 }
219 $output .= "</ul>";
220 }
221 break;
222 default:
223 break;
224 }
225 } else {
226 //drupal_access_denied();
227 $output .= "Report $target: access denied.";
228 }
229 return $output;
230 }
231
232 function isedoc_book_title_to_book_name_id($a_title) {
233 if (module_exists('pathauto')) {
234 module_load_include('inc', 'pathauto', 'pathauto');
235 $l_url = pathauto_cleanstring($a_title);
236 } else {
237 $l_url = $a_title;
238 }
239 return strtolower($l_url);
240 }
241
242 function isedoc_report_on_book($a_bookid,$a_op) {
243 $output = '';
244 $node =& node_load(array('nid' => $a_bookid), NULL, FALSE);
245 if ($node) {
246 if (isset($node->book)) {
247 list($l_unused, $l_book_name_id) = explode('/', $node->path);
248 $l_book_short_path = "book/$l_book_name_id";
249 $tree = book_menu_subtree_data($node->book);
250 $output .= '<fieldset class="collapsible">';
251 $output .= '<legend><a href="#">';
252 $output .= "Report on book $a_bookid: $l_book_short_path";
253 $output .= '</a></legend>';
254 $output .= '<div class="fieldset-wrapper">';
255 $o .= isedoc_report_on_book_traverse(&$tree, $l_book_short_path,$a_op);
256 if ($o == '') {
257 $o = t("Nothing special to report.");
258 }
259 $output .= $o;
260 $output .= '</div>';
261 $output .= '</fieldset>';
262 }
263 }
264 return $output;
265 }
266
267 function isedoc_report_on_book_traverse(&$a_tree, $a_book_short_path, $a_op) {
268 $output = '';
269 foreach($a_tree as $data) {
270 $o = '';
271 $l_log = '';
272 if ($node = node_load($data['link']['nid'], FALSE)) {
273 $o .= isedoc_report_on_node(&$node,$a_book_short_path, $a_op);
274 }
275 $c = '';
276 if ($data['below']) {
277 $c = isedoc_report_on_book_traverse(&$data['below'], $a_book_short_path,$a_op);
278 }
279 $output .= $o.$c;
280 }
281 return $output;
282 }
283
284 function isedoc_report_on_node(&$node, $a_book_short_path, $a_op='all') {
285 $output = "<strong>" . l($node->title, $node->path) . "</strong>";
286 $node_bid = $node->book['bid'];
287 $out = '';
288 if ($a_op == 'all' or $a_op == 'uuid') {
289 if (is_callable(array($node, 'field_uuid'), TRUE)) {
290 $l_uuid = $node->field_uuid[0]['value'];
291 if (!$l_uuid) {
292 $out .= "<li>".$node->title . ": missing uuid"."</li>";
293 }
294 }
295 }
296 if ($a_op == 'all' or $a_op == 'wikilinks') {
297 $pat = '/\[\[\s*([a-zA-Z0-9:_ -]+)\s*(\||\]\])/';
298 $lnk_count = 0;
299 preg_match_all($pat, $node->body, $matches, PREG_PATTERN_ORDER);
300 if (count($matches[1]) > 0) {
301 $o = '';
302 foreach($matches[1] as $mk => $n_title) {
303 if (strlen($n_title) > 6 and strtolower(substr($n_title,0,6)) == "image:") {
304 $t = NULL;
305 } else {
306 $lnk_count += 1;
307 $nids = isedoc_node_ids_by_title($n_title,'doc');
308 if ($nids) {
309 $nb = count($nids);
310 if ($nb > 0 ) {
311 $t = '';
312 foreach($nids as $n_nid) {
313 $n = node_load($n_nid);
314 $tt = '';
315 if ($n) {
316 $bid = $n->book['bid'];
317 if ($bid != $node_bid) {
318 $bn = isedoc_book_name($bid);
319 $tt .= " from other book <strong>".l($bn,"node/$bid")."</strong>";
320 } elseif ($nb > 1) {
321 $tt .= " same book";
322 }
323 if (defined('STATUS_TRASH') and $n->status == STATUS_TRASH) {
324 $tt .= ' <span class="error">TRASHED</span>';
325 }
326 } else {
327 $tt .= " unable to load";
328 }
329 if ($tt != '') {
330 $tt = l("node/$n_nid", "node/$n_nid") . ": $tt";
331 if ($nb > 1) {
332 $tt = "<li>$tt</li>";
333 }
334 $t .= $tt;
335 }
336 }
337 if ($t == '') {
338 //$t = "$n_title: <strong>$nb page(s)</strong>";
339 } else {
340 if ($nb > 1) {
341 $t = "$n_title: <strong>$nb page(s)</strong><ul>$t</ul>";
342 } else {
343 $t = "$n_title: $t";
344 }
345 }
346 }
347 } else {
348 $t = "$n_title: <strong>missing node</strong>";
349 }
350 }
351 if ($t != '') {
352 $o .= "<li>$t</li>";
353 }
354 }
355 }
356 if ($o != '') {
357 $out .= $o;
358 }
359 }
360
361 if ($lnk_count === FALSE) {
362 } else {
363 $output .= " <em>($lnk_count link";
364 if ($lnk_count > 1) {
365 $output .= "s";
366 }
367 $output .= ")</em>";
368 }
369 if ($out == '') {
370 $output = '';
371 } else {
372 $output .= "<ul style=\"margin: 0 0 5px 0; border-bottom: dotted 1px #ccc;\">$out</ul>\n";
373 }
374 return $output;
375 }
376
377 ?>

  ViewVC Help
Powered by ViewVC 1.1.23