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