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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 74850 - (show annotations)
Fri Sep 26 17:38:58 2008 UTC (11 years, 4 months ago) by jfiat
File size: 6358 byte(s)
added a way to reorganize the images galleries
1 <?php
2
3
4 /*
5 * Helpers
6 */
7
8 function var_dump_r(&$ref, $pre=TRUE) {
9 ob_start(); var_dump($ref); $a=htmlspecialchars(ob_get_contents(),ENT_QUOTES); ob_end_clean();
10 if ($pre) {
11 return "<pre>DUMP=".$a . '</pre>';
12 } else {
13 return 'DUMP='.$a;
14 }
15 }
16 function var_dump_global($refname) {
17 global $$refname;
18 ob_start(); var_dump($$refname); $a=htmlspecialchars(ob_get_contents(),ENT_QUOTES); ob_end_clean();
19 return "DUMP[".$refname."]=".$a;
20 }
21
22 function isedoc_mkdir($a_dir) {
23 if (!file_check_directory($a_dir)) {
24 //drupal_set_message("create directory: $a_dir", 'status');
25 mkdir($a_dir, 0775, TRUE);
26 }
27 }
28
29 function isedoc_rm_recursive($filepath) {
30 if (is_dir($filepath) && !is_link($filepath))
31 {
32 if ($dh = opendir($filepath))
33 {
34 while (($sf = readdir($dh)) !== false)
35 {
36 if ($sf == '.' || $sf == '..')
37 {
38 continue;
39 }
40 if (!isedoc_rm_recursive($filepath.'/'.$sf))
41 {
42 throw new Exception($filepath.'/'.$sf.' could not be deleted.');
43 }
44 }
45 closedir($dh);
46 }
47 return rmdir($filepath);
48 }
49 return unlink($filepath);
50 }
51
52 /**
53 * Returns an array of all books.
54 *
55 * This list may be used for generating a list of all the books, or for building
56 * the options for a form select.
57 */
58
59 function book_doc_page_exists($a_title) {
60 //$res = db_query("SELECT nid FROM {node} WHERE LOWER(title) = LOWER('%s') AND type IN ()", $a_title);
61 //$res = db_query("SELECT nid FROM {node} WHERE LOWER(title) = LOWER('%s') AND type = 'doc' ", $a_title);
62 $res = db_query("SELECT nid FROM {node} WHERE type = 'doc' AND LOWER(title) = LOWER('%s') ", $a_title);
63 if ($res === FALSE) {
64 return FALSE;
65 } else {
66 $v = db_fetch_object($res);
67 return $v->nid;
68 }
69 }
70
71 function isedoc_book_parent_of($nid) {
72 $parent_sql = "SELECT b.nid FROM {book} b INNER JOIN {menu_links} m ON m.mlid = b.mlid INNER JOIN {menu_links} m2 ON m.mlid = m2.plid INNER JOIN {book} b2 ON b2.nid = '%d' AND m2.mlid = b2.mlid ";
73 $parent = db_result(db_query(db_rewrite_sql($parent_sql), $nid));
74 if ($parent) {
75 return $parent;
76 } else {
77 return FALSE;
78 }
79 }
80
81 function isedoc_book_get_books() {
82 static $all_books;
83
84 if (!isset($all_books)) {
85 $all_books = array();
86 $result = db_query("SELECT DISTINCT(bid) FROM {book}");
87 $nids = array();
88 while ($book = db_fetch_array($result)) {
89 $nids[] = $book['bid'];
90 }
91 if ($nids) {
92 $result2 = db_query(db_rewrite_sql("SELECT n.type, n.title, b.*, ml.* FROM {book} b INNER JOIN {node} n on b.nid = n.nid INNER JOIN {menu_links} ml ON b.mlid = ml.mlid WHERE n.nid IN (". implode(',', $nids) .") AND n.status = 1 ORDER BY ml.weight, ml.link_title"));
93 while ($link = db_fetch_array($result2)) {
94 $link['href'] = $link['link_path'];
95 $link['options'] = unserialize($link['options']);
96 $all_books[$link['bid']] = $link;
97 }
98 }
99 }
100 return $all_books;
101 }
102
103 function isedoc_book_name ($bid) {
104 static $s_book_names;
105 if (!$s_book_names) {
106 $s_book_names = array();
107 }
108 if (isset($s_book_names[$bid])) {
109 $bn = $s_book_names[$bid];
110 } else {
111 $b =& node_load($bid);
112 if ($b) {
113 $bn = $b->title;
114 } else {
115 $bn = "Book id#$bid";
116 }
117 $s_book_names[$bid]=$bn;
118 }
119 return $bn;
120 }
121
122 function isedoc_node_ids_by_title($title,$type='') {
123 if ($type == '') {
124 $sql_type = '';
125 } else {
126 if (is_array($type)) {
127 $sql_type = '(';
128 foreach($type as $t) {
129 $sql_type .= " n.type = '$t' OR";
130 }
131 $sql_type = substr($sql_type,0, -2);
132 $sql_type .= ')';
133 } else {
134 $sql_type = " n.type = '$type' AND ";
135 }
136 }
137 $sql = "SELECT n.nid, n.title, n.vid FROM {node} n INNER JOIN {node_revisions} r ON n.nid = r.nid AND n.vid = r.vid WHERE $sql_type LOWER(r.title) = LOWER('%s') ORDER BY nid";
138 $res = db_query($sql, $title);
139 if ($res === FALSE) {
140 return FALSE;
141 } else {
142 $nids = array();
143 while ($v = db_fetch_array($res)) {
144 $nids[] = $v['nid'];
145 }
146 return $nids;
147 }
148 }
149
150 function isedoc_node_ids_by_uuid($uuid) {
151 $sql = "SELECT nid, vid FROM {content_type_".'doc'."} WHERE LOWER(field_uuid_value) = LOWER('%s') ORDER BY nid ASC ,vid ASC";
152 $res = db_query($sql, $uuid);
153 if ($res === FALSE) {
154 return FALSE;
155 } else {
156 $nids = array();
157 while ($v = db_fetch_array($res)) {
158 $nid = $v['nid'];
159 $vid = $v['vid'];
160 //drupal_set_message("nid=$nid; v=$vid");
161 $nids[$nid] = $vid;
162 }
163 return $nids;
164 }
165 }
166
167 /*
168 * Query References
169 */
170
171 function isedoc_pages_referencing_image($a_title) {
172 $l_body_filter = 'REGEXP \'[[.[.]][[.[.]]Image:[:blank:]*'.strtolower($a_title).'[:blank:]*([[.|.]]|[[.].]][[.].]])\'';
173 $sql = "SELECT n.nid, n.title, n.vid FROM {node} n INNER JOIN {node_revisions} r ON n.nid = r.nid AND n.vid = r.vid WHERE n.type = 'doc' AND LOWER(r.body) $l_body_filter ";
174 $sql .= " ORDER BY n.nid, n.vid ";
175 $res = db_query($sql);
176 $result = array();
177 if ($res === FALSE) {
178 return FALSE;
179 } else {
180 while ($r = db_fetch_array($res)) {
181 $result[$r['nid']] = $r;
182 }
183 return $result;
184 }
185 }
186
187 function isedoc_pages_referencing_template($a_title) {
188 $l_body_filter = 'REGEXP \'[[.left-brace.]][[.left-brace.]][:blank:]*'.strtolower($a_title).'[:blank:]*[[.|.]]\'';
189 $sql = "SELECT n.nid, n.title, n.vid FROM {node} n INNER JOIN {node_revisions} r ON n.nid = r.nid AND n.vid = r.vid WHERE n.type = 'doc' AND LOWER(r.body) $l_body_filter ";
190 $sql .= " ORDER BY n.nid, n.vid ";
191 $res = db_query(db_rewrite_sql($sql));
192 $result = array();
193 if ($res === FALSE) {
194 return FALSE;
195 } else {
196 while ($r = db_fetch_array($res)) {
197 $result[$r['nid']] = $r;
198 }
199 return $result;
200 }
201 }
202
203 function isedoc_pages_referencing($a_title) {
204 $l_body_filter = 'REGEXP \'[[.[.]][[.[.]][:blank:]*'.strtolower($a_title).'[:blank:]*([[.|.]]|[[.].]][[.].]])\'';
205 //$l_body_filter = 'LIKE LOWER(\'%[['.$a_title.'%\')';
206 $sql = "SELECT n.nid, n.title, n.vid FROM {node} n INNER JOIN {node_revisions} r ON n.nid = r.nid AND n.vid = r.vid WHERE n.type = 'doc' AND LOWER(r.body) $l_body_filter ";
207 $sql .= " ORDER BY n.nid, n.vid ";
208 $res = db_query($sql);
209 $result = array();
210 if ($res === FALSE) {
211 return FALSE;
212 } else {
213 while ($r = db_fetch_array($res)) {
214 $result[$r['nid']] = $r;
215 }
216 return $result;
217 }
218 }
219
220
221 ?>

Properties

Name Value
svn:eol-style native

  ViewVC Help
Powered by ViewVC 1.1.23