Commit | Line | Data |
---|---|---|
60488185 | 1 | <?php |
bccdda02 J |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM Widget Creation Interface (WCI) Version 1.0 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright Zyxware Technologies (c) 2014 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | This file is a part of CiviCRM WCI. | | |
9 | | | | |
10 | | CiviCRM WCI is free software; you can copy, modify, and distribute | | |
11 | | it under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007. | | |
13 | | | | |
14 | | CiviCRM WCI is distributed in the hope that it will be useful, | | |
15 | | but WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License along with this program; if not, contact Zyxware | | |
21 | | Technologies at info[AT]zyxware[DOT]com. | | |
22 | +--------------------------------------------------------------------+ | |
23 | */ | |
60488185 M |
24 | // AUTO-GENERATED FILE -- Civix may overwrite any changes made to this file |
25 | ||
26 | /** | |
27 | * (Delegated) Implementation of hook_civicrm_config | |
28 | * | |
29 | * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config | |
30 | */ | |
31 | function _wci_civix_civicrm_config(&$config = NULL) { | |
32 | static $configured = FALSE; | |
33 | if ($configured) return; | |
34 | $configured = TRUE; | |
35 | ||
36 | $template =& CRM_Core_Smarty::singleton(); | |
37 | ||
38 | $extRoot = dirname( __FILE__ ) . DIRECTORY_SEPARATOR; | |
39 | $extDir = $extRoot . 'templates'; | |
40 | ||
41 | if ( is_array( $template->template_dir ) ) { | |
42 | array_unshift( $template->template_dir, $extDir ); | |
43 | } else { | |
44 | $template->template_dir = array( $extDir, $template->template_dir ); | |
45 | } | |
46 | ||
47 | $include_path = $extRoot . PATH_SEPARATOR . get_include_path( ); | |
48 | set_include_path( $include_path ); | |
49 | } | |
50 | ||
51 | /** | |
52 | * (Delegated) Implementation of hook_civicrm_xmlMenu | |
53 | * | |
54 | * @param $files array(string) | |
55 | * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_xmlMenu | |
56 | */ | |
57 | function _wci_civix_civicrm_xmlMenu(&$files) { | |
58 | foreach (_wci_civix_glob(__DIR__ . '/xml/Menu/*.xml') as $file) { | |
59 | $files[] = $file; | |
60 | } | |
61 | } | |
62 | ||
63 | /** | |
64 | * Implementation of hook_civicrm_install | |
65 | * | |
66 | * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install | |
67 | */ | |
68 | function _wci_civix_civicrm_install() { | |
69 | _wci_civix_civicrm_config(); | |
70 | if ($upgrader = _wci_civix_upgrader()) { | |
ae48345c | 71 | $upgrader->onInstall(); |
60488185 M |
72 | } |
73 | } | |
74 | ||
75 | /** | |
76 | * Implementation of hook_civicrm_uninstall | |
77 | * | |
78 | * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_uninstall | |
79 | */ | |
80 | function _wci_civix_civicrm_uninstall() { | |
81 | _wci_civix_civicrm_config(); | |
82 | if ($upgrader = _wci_civix_upgrader()) { | |
ae48345c | 83 | $upgrader->onUninstall(); |
60488185 M |
84 | } |
85 | } | |
86 | ||
87 | /** | |
88 | * (Delegated) Implementation of hook_civicrm_enable | |
89 | * | |
90 | * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_enable | |
91 | */ | |
92 | function _wci_civix_civicrm_enable() { | |
93 | _wci_civix_civicrm_config(); | |
94 | if ($upgrader = _wci_civix_upgrader()) { | |
95 | if (is_callable(array($upgrader, 'onEnable'))) { | |
ae48345c | 96 | $upgrader->onEnable(); |
60488185 M |
97 | } |
98 | } | |
99 | } | |
100 | ||
101 | /** | |
102 | * (Delegated) Implementation of hook_civicrm_disable | |
103 | * | |
104 | * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_disable | |
ae48345c | 105 | * @return mixed |
60488185 M |
106 | */ |
107 | function _wci_civix_civicrm_disable() { | |
108 | _wci_civix_civicrm_config(); | |
109 | if ($upgrader = _wci_civix_upgrader()) { | |
110 | if (is_callable(array($upgrader, 'onDisable'))) { | |
ae48345c | 111 | $upgrader->onDisable(); |
60488185 M |
112 | } |
113 | } | |
114 | } | |
115 | ||
116 | /** | |
117 | * (Delegated) Implementation of hook_civicrm_upgrade | |
118 | * | |
119 | * @param $op string, the type of operation being performed; 'check' or 'enqueue' | |
120 | * @param $queue CRM_Queue_Queue, (for 'enqueue') the modifiable list of pending up upgrade tasks | |
121 | * | |
122 | * @return mixed based on op. for 'check', returns array(boolean) (TRUE if upgrades are pending) | |
123 | * for 'enqueue', returns void | |
124 | * | |
125 | * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_upgrade | |
126 | */ | |
127 | function _wci_civix_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) { | |
128 | if ($upgrader = _wci_civix_upgrader()) { | |
129 | return $upgrader->onUpgrade($op, $queue); | |
130 | } | |
131 | } | |
132 | ||
133 | /** | |
134 | * @return CRM_Wci_Upgrader | |
135 | */ | |
136 | function _wci_civix_upgrader() { | |
137 | if (!file_exists(__DIR__.'/CRM/Wci/Upgrader.php')) { | |
138 | return NULL; | |
139 | } else { | |
140 | return CRM_Wci_Upgrader_Base::instance(); | |
141 | } | |
142 | } | |
143 | ||
144 | /** | |
145 | * Search directory tree for files which match a glob pattern | |
146 | * | |
147 | * Note: Dot-directories (like "..", ".git", or ".svn") will be ignored. | |
148 | * Note: In Civi 4.3+, delegate to CRM_Utils_File::findFiles() | |
149 | * | |
150 | * @param $dir string, base dir | |
151 | * @param $pattern string, glob pattern, eg "*.txt" | |
152 | * @return array(string) | |
153 | */ | |
154 | function _wci_civix_find_files($dir, $pattern) { | |
155 | if (is_callable(array('CRM_Utils_File', 'findFiles'))) { | |
156 | return CRM_Utils_File::findFiles($dir, $pattern); | |
157 | } | |
158 | ||
159 | $todos = array($dir); | |
160 | $result = array(); | |
161 | while (!empty($todos)) { | |
162 | $subdir = array_shift($todos); | |
163 | foreach (_wci_civix_glob("$subdir/$pattern") as $match) { | |
164 | if (!is_dir($match)) { | |
165 | $result[] = $match; | |
166 | } | |
167 | } | |
168 | if ($dh = opendir($subdir)) { | |
169 | while (FALSE !== ($entry = readdir($dh))) { | |
170 | $path = $subdir . DIRECTORY_SEPARATOR . $entry; | |
171 | if ($entry{0} == '.') { | |
172 | } elseif (is_dir($path)) { | |
173 | $todos[] = $path; | |
174 | } | |
175 | } | |
176 | closedir($dh); | |
177 | } | |
178 | } | |
179 | return $result; | |
180 | } | |
181 | /** | |
182 | * (Delegated) Implementation of hook_civicrm_managed | |
183 | * | |
184 | * Find any *.mgd.php files, merge their content, and return. | |
185 | * | |
186 | * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_managed | |
187 | */ | |
188 | function _wci_civix_civicrm_managed(&$entities) { | |
189 | $mgdFiles = _wci_civix_find_files(__DIR__, '*.mgd.php'); | |
190 | foreach ($mgdFiles as $file) { | |
191 | $es = include $file; | |
192 | foreach ($es as $e) { | |
193 | if (empty($e['module'])) { | |
dcd2221d | 194 | $e['module'] = 'com.zyxware.civiwci'; |
60488185 M |
195 | } |
196 | $entities[] = $e; | |
197 | } | |
198 | } | |
199 | } | |
200 | ||
201 | /** | |
202 | * (Delegated) Implementation of hook_civicrm_caseTypes | |
203 | * | |
204 | * Find any and return any files matching "xml/case/*.xml" | |
205 | * | |
206 | * Note: This hook only runs in CiviCRM 4.4+. | |
207 | * | |
208 | * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_caseTypes | |
209 | */ | |
210 | function _wci_civix_civicrm_caseTypes(&$caseTypes) { | |
211 | if (!is_dir(__DIR__ . '/xml/case')) { | |
212 | return; | |
213 | } | |
214 | ||
215 | foreach (_wci_civix_glob(__DIR__ . '/xml/case/*.xml') as $file) { | |
216 | $name = preg_replace('/\.xml$/', '', basename($file)); | |
217 | if ($name != CRM_Case_XMLProcessor::mungeCaseType($name)) { | |
218 | $errorMessage = sprintf("Case-type file name is malformed (%s vs %s)", $name, CRM_Case_XMLProcessor::mungeCaseType($name)); | |
219 | CRM_Core_Error::fatal($errorMessage); | |
220 | // throw new CRM_Core_Exception($errorMessage); | |
221 | } | |
222 | $caseTypes[$name] = array( | |
dcd2221d | 223 | 'module' => 'com.zyxware.civiwci', |
60488185 M |
224 | 'name' => $name, |
225 | 'file' => $file, | |
226 | ); | |
227 | } | |
228 | } | |
229 | ||
230 | /** | |
231 | * Glob wrapper which is guaranteed to return an array. | |
232 | * | |
233 | * The documentation for glob() says, "On some systems it is impossible to | |
234 | * distinguish between empty match and an error." Anecdotally, the return | |
235 | * result for an empty match is sometimes array() and sometimes FALSE. | |
236 | * This wrapper provides consistency. | |
237 | * | |
238 | * @link http://php.net/glob | |
239 | * @param string $pattern | |
240 | * @return array, possibly empty | |
241 | */ | |
242 | function _wci_civix_glob($pattern) { | |
243 | $result = glob($pattern); | |
244 | return is_array($result) ? $result : array(); | |
245 | } | |
246 | ||
247 | /** | |
248 | * Inserts a navigation menu item at a given place in the hierarchy | |
249 | * | |
250 | * $menu - menu hierarchy | |
251 | * $path - path where insertion should happen (ie. Administer/System Settings) | |
252 | * $item - menu you need to insert (parent/child attributes will be filled for you) | |
253 | * $parentId - used internally to recurse in the menu structure | |
254 | */ | |
255 | function _wci_civix_insert_navigation_menu(&$menu, $path, $item, $parentId = NULL) { | |
256 | static $navId; | |
257 | ||
258 | // If we are done going down the path, insert menu | |
259 | if (empty($path)) { | |
260 | if (!$navId) $navId = CRM_Core_DAO::singleValueQuery("SELECT max(id) FROM civicrm_navigation"); | |
261 | $navId ++; | |
262 | $menu[$navId] = array ( | |
263 | 'attributes' => array_merge($item, array( | |
264 | 'label' => CRM_Utils_Array::value('name', $item), | |
265 | 'active' => 1, | |
266 | 'parentID' => $parentId, | |
267 | 'navID' => $navId, | |
268 | )) | |
269 | ); | |
270 | return true; | |
271 | } else { | |
272 | // Find an recurse into the next level down | |
273 | $found = false; | |
274 | $path = explode('/', $path); | |
275 | $first = array_shift($path); | |
276 | foreach ($menu as $key => &$entry) { | |
277 | if ($entry['attributes']['name'] == $first) { | |
278 | if (!$entry['child']) $entry['child'] = array(); | |
279 | $found = _wci_civix_insert_navigation_menu($entry['child'], implode('/', $path), $item, $key); | |
280 | } | |
281 | } | |
282 | return $found; | |
283 | } | |
284 | } | |
285 | ||
286 | /** | |
287 | * (Delegated) Implementation of hook_civicrm_alterSettingsFolders | |
288 | * | |
289 | * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_alterSettingsFolders | |
290 | */ | |
291 | function _wci_civix_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) { | |
292 | static $configured = FALSE; | |
293 | if ($configured) return; | |
294 | $configured = TRUE; | |
295 | ||
296 | $settingsDir = __DIR__ . DIRECTORY_SEPARATOR . 'settings'; | |
297 | if(is_dir($settingsDir) && !in_array($settingsDir, $metaDataFolders)) { | |
298 | $metaDataFolders[] = $settingsDir; | |
299 | } | |
ae48345c | 300 | } |