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

Contents of /trunk/Documentation/tools/web/trunk/drupal/sites/all/modules/isedoc/isedoc.update.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: 4587 byte(s)
added a way to reorganize the images galleries
1 <?php
2
3 require_once ("isedoc.lib.inc");
4
5 function isedoc_update_pages($target,$op) {
6 $output = '';
7 if (user_access('admin isedoc')) {
8 $books = array();
9 $all_books = book_get_books();
10 switch ($target) {
11 case 'all':
12 foreach($all_books as $b) {
13 $books[] = $b['bid'];
14 }
15 break;
16 default:
17 $bn = strtolower($target);
18 foreach($all_books as $b) {
19 //drupal_set_message(var_dump_r($b));
20 if (isedoc_book_title_to_book_name_id($b['title']) == $bn) {
21 $books[] = $b['bid'];
22 }
23 }
24 break;
25 }
26 if (count($books) > 0) {
27 foreach($books as $bid){
28 isedoc_update_pages_of_book($bid,$op);
29 }
30 if ($op) {
31 $output .= "Update $target ($op): completed.";
32 } else {
33 $output .= "Update $target: completed.";
34 }
35 $output .= "<br/>".l(t("Update other books"), "isedoc/update/_")."<br/>";
36 } else {
37 $output .= "<ul>";
38 $output .= "<li><strong>".l(t("Update all the books"), "isedoc/update/all")."</strong></li>";
39 foreach($all_books as $b) {
40 $bn = isedoc_book_title_to_book_name_id($b['title']);
41 $output .= "<li>".l(t("Update only: ").$bn, "isedoc/update/$bn")."</li>";
42 }
43 $output .= "</ul>";
44 }
45 } else {
46 drupal_access_denied();
47 $output .= "Update $target: access denied.";
48 }
49 return $output;
50 }
51
52 function isedoc_book_title_to_book_name_id($a_title) {
53 if (module_exists('pathauto')) {
54 module_load_include('inc', 'pathauto', 'pathauto');
55 $l_url = pathauto_cleanstring($a_title);
56 } else {
57 $l_url = $a_title;
58 }
59 return strtolower($l_url);
60 }
61
62 function isedoc_update_pages_of_book($a_bookid,$a_op) {
63 $node =& node_load(array('nid' => $a_bookid), NULL, FALSE);
64 if ($node) {
65 if (isset($node->book)) {
66 list($l_unused, $l_book_name_id) = explode('/', $node->path);
67 $l_book_short_path = "book/$l_book_name_id";
68 drupal_set_message("<h3>Update book $a_bookid: $l_book_short_path</h3>");
69 $tree = book_menu_subtree_data($node->book);
70 isedoc_update_book_traverse(&$tree, $l_book_short_path,$a_op);
71 }
72 }
73 }
74
75 function isedoc_update_book_traverse(&$a_tree, $a_book_short_path, $a_op='all') {
76 foreach($a_tree as $data) {
77 $b_save = FALSE;
78 $b_revision = FALSE;
79 $l_log = '';
80 if ($node = node_load($data['link']['nid'], FALSE)) {
81 drupal_set_message("<strong>" . l($node->title, $node->path) . "</strong>");
82 if ($a_op == 'all' or $a_op == 'uuid') {
83 if (is_callable(array($node, 'field_uuid'), TRUE)) {
84 $l_uuid = $node->field_uuid[0]['value'];
85 if (!$l_uuid) {
86 $l_uuid = isedoc_uuid();
87 $l_log .= "(new uuid=$l_uuid)";
88 //drupal_set_message($node->title . ": New uuid=$l_uuid");
89 $node->field_uuid[0]['value'] = $l_uuid;;
90 $b_save = TRUE;
91 //$b_revision = TRUE;
92 }
93 }
94 }
95 if ($a_op == 'all' or $a_op == 'alias') {
96 if (module_exists('pathauto')) {
97 //drupal_set_message("cmp=".strncasecmp($a_book_short_path, $node->path, strlen($a_book_short_path) ));
98 if (strncasecmp($a_book_short_path, $node->path, strlen($a_book_short_path) - 1) != 0) {
99 drupal_set_message($a_book_short_path . " node=" .$node->path . ": Update url alias");
100 $l_log .= "(update url alias)";
101 $b_save = TRUE;
102 }
103 }
104 }
105 if ($a_op == 'blockimage') {
106 $pat = "/\\n\[\[Image:/";
107 $txt = preg_replace($pat, '[[Image:',$node->body);
108 if (strlen($txt) < strlen($node->body)) {
109 drupal_set_message($a_book_short_path . " node=" .$node->path . ": Clean imageblock usage");
110 $node->body = $txt;
111 $b_save = TRUE;
112 $b_revision = TRUE;
113 }
114 }
115 if ($a_op == 'templateseealso') {
116 $pat = "/{{\s*seealso\s*\|[' ]*see also[': ]*/i";
117 $txt = preg_replace($pat, '{{seealso|',$node->body);
118 if (strlen($txt) < strlen($node->body)) {
119 drupal_set_message($a_book_short_path . " node=" .$node->path . ": Clean template SeeAlso usage");
120 $node->body = $txt;
121 $b_save = TRUE;
122 $b_revision = TRUE;
123 }
124 }
125 if ($a_op == 'template') {
126 $pat = "/{{\s*([a-z]+)\s*\|[' ]*\\1[': ]*/i";
127 $txt = preg_replace($pat, '{{${1}|',$node->body);
128 if (strlen($txt) < strlen($node->body)) {
129 drupal_set_message($a_book_short_path . " node=" .$node->path . ": Clean template usage");
130 $node->body = $txt;
131 $b_save = TRUE;
132 $b_revision = TRUE;
133 }
134 }
135 if ($b_save) {
136 $node->revision = $b_revision;
137 node_save(&$node);
138 drupal_set_message("Saved: " . l($node->title,$node->path). " <em>log=$l_log</em>");
139 }
140 }
141 if ($data['below']) {
142 isedoc_update_book_traverse(&$data['below'], $a_book_short_path,$a_op);
143 }
144 }
145 }
146
147 ?>

Properties

Name Value
svn:eol-style native

  ViewVC Help
Powered by ViewVC 1.1.23