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. |
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. |
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. |
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 +--------------------------------------------------------------------+
24 // AUTO-GENERATED FILE -- Civix may overwrite any changes made to this file
27 * (Delegated) Implementation of hook_civicrm_config
29 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config
31 function _wci_civix_civicrm_config(&$config = NULL) {
32 static $configured = FALSE;
33 if ($configured) return;
36 $template =& CRM_Core_Smarty
::singleton();
38 $extRoot = dirname( __FILE__
) . DIRECTORY_SEPARATOR
;
39 $extDir = $extRoot . 'templates';
41 if ( is_array( $template->template_dir
) ) {
42 array_unshift( $template->template_dir
, $extDir );
44 $template->template_dir
= array( $extDir, $template->template_dir
);
47 $include_path = $extRoot . PATH_SEPARATOR
. get_include_path( );
48 set_include_path( $include_path );
52 * (Delegated) Implementation of hook_civicrm_xmlMenu
54 * @param $files array(string)
55 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_xmlMenu
57 function _wci_civix_civicrm_xmlMenu(&$files) {
58 foreach (_wci_civix_glob(__DIR__
. '/xml/Menu/*.xml') as $file) {
64 * Implementation of hook_civicrm_install
66 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install
68 function _wci_civix_civicrm_install() {
69 _wci_civix_civicrm_config();
70 if ($upgrader = _wci_civix_upgrader()) {
71 $upgrader->onInstall();
76 * Implementation of hook_civicrm_uninstall
78 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_uninstall
80 function _wci_civix_civicrm_uninstall() {
81 _wci_civix_civicrm_config();
82 if ($upgrader = _wci_civix_upgrader()) {
83 $upgrader->onUninstall();
88 * (Delegated) Implementation of hook_civicrm_enable
90 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_enable
92 function _wci_civix_civicrm_enable() {
93 _wci_civix_civicrm_config();
94 if ($upgrader = _wci_civix_upgrader()) {
95 if (is_callable(array($upgrader, 'onEnable'))) {
96 $upgrader->onEnable();
102 * (Delegated) Implementation of hook_civicrm_disable
104 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_disable
107 function _wci_civix_civicrm_disable() {
108 _wci_civix_civicrm_config();
109 if ($upgrader = _wci_civix_upgrader()) {
110 if (is_callable(array($upgrader, 'onDisable'))) {
111 $upgrader->onDisable();
117 * (Delegated) Implementation of hook_civicrm_upgrade
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
122 * @return mixed based on op. for 'check', returns array(boolean) (TRUE if upgrades are pending)
123 * for 'enqueue', returns void
125 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_upgrade
127 function _wci_civix_civicrm_upgrade($op, CRM_Queue_Queue
$queue = NULL) {
128 if ($upgrader = _wci_civix_upgrader()) {
129 return $upgrader->onUpgrade($op, $queue);
134 * @return CRM_Wci_Upgrader
136 function _wci_civix_upgrader() {
137 if (!file_exists(__DIR__
.'/CRM/Wci/Upgrader.php')) {
140 return CRM_Wci_Upgrader_Base
::instance();
145 * Search directory tree for files which match a glob pattern
147 * Note: Dot-directories (like "..", ".git", or ".svn") will be ignored.
148 * Note: In Civi 4.3+, delegate to CRM_Utils_File::findFiles()
150 * @param $dir string, base dir
151 * @param $pattern string, glob pattern, eg "*.txt"
152 * @return array(string)
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);
159 $todos = array($dir);
161 while (!empty($todos)) {
162 $subdir = array_shift($todos);
163 foreach (_wci_civix_glob("$subdir/$pattern") as $match) {
164 if (!is_dir($match)) {
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)) {
182 * (Delegated) Implementation of hook_civicrm_managed
184 * Find any *.mgd.php files, merge their content, and return.
186 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_managed
188 function _wci_civix_civicrm_managed(&$entities) {
189 $mgdFiles = _wci_civix_find_files(__DIR__
, '*.mgd.php');
190 foreach ($mgdFiles as $file) {
192 foreach ($es as $e) {
193 if (empty($e['module'])) {
194 $e['module'] = 'org.civicrm.wci';
202 * (Delegated) Implementation of hook_civicrm_caseTypes
204 * Find any and return any files matching "xml/case/*.xml"
206 * Note: This hook only runs in CiviCRM 4.4+.
208 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_caseTypes
210 function _wci_civix_civicrm_caseTypes(&$caseTypes) {
211 if (!is_dir(__DIR__
. '/xml/case')) {
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);
222 $caseTypes[$name] = array(
223 'module' => 'org.civicrm.wci',
231 * Glob wrapper which is guaranteed to return an array.
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.
238 * @link http://php.net/glob
239 * @param string $pattern
240 * @return array, possibly empty
242 function _wci_civix_glob($pattern) {
243 $result = glob($pattern);
244 return is_array($result) ?
$result : array();
248 * Inserts a navigation menu item at a given place in the hierarchy
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
255 function _wci_civix_insert_navigation_menu(&$menu, $path, $item, $parentId = NULL) {
258 // If we are done going down the path, insert menu
260 if (!$navId) $navId = CRM_Core_DAO
::singleValueQuery("SELECT max(id) FROM civicrm_navigation");
262 $menu[$navId] = array (
263 'attributes' => array_merge($item, array(
264 'label' => CRM_Utils_Array
::value('name', $item),
266 'parentID' => $parentId,
272 // Find an recurse into the next level down
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);
287 * (Delegated) Implementation of hook_civicrm_alterSettingsFolders
289 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_alterSettingsFolders
291 function _wci_civix_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
292 static $configured = FALSE;
293 if ($configured) return;
296 $settingsDir = __DIR__
. DIRECTORY_SEPARATOR
. 'settings';
297 if(is_dir($settingsDir) && !in_array($settingsDir, $metaDataFolders)) {
298 $metaDataFolders[] = $settingsDir;