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