PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/sepa.civix.php

https://github.com/systopia/sepa_dd
PHP | 227 lines | 140 code | 20 blank | 67 comment | 28 complexity | 1f7b01cd7a9ff8595c625992acf3f2e6 MD5 | raw file
Possible License(s): LGPL-3.0
  1. <?php
  2. // AUTO-GENERATED FILE -- Civix may overwrite any changes made to this file
  3. /**
  4. * (Delegated) Implementation of hook_civicrm_config
  5. */
  6. function _sepa_civix_civicrm_config(&$config = NULL) {
  7. static $configured = FALSE;
  8. if ($configured) return;
  9. $configured = TRUE;
  10. $template =& CRM_Core_Smarty::singleton();
  11. $extRoot = dirname( __FILE__ ) . DIRECTORY_SEPARATOR;
  12. $extDir = $extRoot . 'templates';
  13. if ( is_array( $template->template_dir ) ) {
  14. array_unshift( $template->template_dir, $extDir );
  15. } else {
  16. $template->template_dir = array( $extDir, $template->template_dir );
  17. }
  18. $include_path = $extRoot . PATH_SEPARATOR . get_include_path( );
  19. set_include_path( $include_path );
  20. }
  21. /**
  22. * (Delegated) Implementation of hook_civicrm_xmlMenu
  23. *
  24. * @param $files array(string)
  25. */
  26. function _sepa_civix_civicrm_xmlMenu(&$files) {
  27. foreach (_sepa_civix_glob(__DIR__ . '/xml/Menu/*.xml') as $file) {
  28. $files[] = $file;
  29. }
  30. }
  31. /**
  32. * Implementation of hook_civicrm_install
  33. */
  34. function _sepa_civix_civicrm_install() {
  35. _sepa_civix_civicrm_config();
  36. if ($upgrader = _sepa_civix_upgrader()) {
  37. return $upgrader->onInstall();
  38. }
  39. }
  40. /**
  41. * Implementation of hook_civicrm_uninstall
  42. */
  43. function _sepa_civix_civicrm_uninstall() {
  44. _sepa_civix_civicrm_config();
  45. if ($upgrader = _sepa_civix_upgrader()) {
  46. return $upgrader->onUninstall();
  47. }
  48. }
  49. /**
  50. * (Delegated) Implementation of hook_civicrm_enable
  51. */
  52. function _sepa_civix_civicrm_enable() {
  53. _sepa_civix_civicrm_config();
  54. if ($upgrader = _sepa_civix_upgrader()) {
  55. if (is_callable(array($upgrader, 'onEnable'))) {
  56. return $upgrader->onEnable();
  57. }
  58. }
  59. }
  60. /**
  61. * (Delegated) Implementation of hook_civicrm_disable
  62. */
  63. function _sepa_civix_civicrm_disable() {
  64. _sepa_civix_civicrm_config();
  65. if ($upgrader = _sepa_civix_upgrader()) {
  66. if (is_callable(array($upgrader, 'onDisable'))) {
  67. return $upgrader->onDisable();
  68. }
  69. }
  70. }
  71. /**
  72. * (Delegated) Implementation of hook_civicrm_upgrade
  73. *
  74. * @param $op string, the type of operation being performed; 'check' or 'enqueue'
  75. * @param $queue CRM_Queue_Queue, (for 'enqueue') the modifiable list of pending up upgrade tasks
  76. *
  77. * @return mixed based on op. for 'check', returns array(boolean) (TRUE if upgrades are pending)
  78. * for 'enqueue', returns void
  79. */
  80. function _sepa_civix_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
  81. if ($upgrader = _sepa_civix_upgrader()) {
  82. return $upgrader->onUpgrade($op, $queue);
  83. }
  84. }
  85. function _sepa_civix_upgrader() {
  86. if (!file_exists(__DIR__.'/CRM/Sepa/Upgrader.php')) {
  87. return NULL;
  88. } else {
  89. return CRM_Sepa_Upgrader_Base::instance();
  90. }
  91. }
  92. /**
  93. * Search directory tree for files which match a glob pattern
  94. *
  95. * Note: Dot-directories (like "..", ".git", or ".svn") will be ignored.
  96. * Note: In Civi 4.3+, delegate to CRM_Utils_File::findFiles()
  97. *
  98. * @param $dir string, base dir
  99. * @param $pattern string, glob pattern, eg "*.txt"
  100. * @return array(string)
  101. */
  102. function _sepa_civix_find_files($dir, $pattern) {
  103. if (is_callable(array('CRM_Utils_File', 'findFiles'))) {
  104. return CRM_Utils_File::findFiles($dir, $pattern);
  105. }
  106. $todos = array($dir);
  107. $result = array();
  108. while (!empty($todos)) {
  109. $subdir = array_shift($todos);
  110. foreach (_sepa_civix_glob("$subdir/$pattern") as $match) {
  111. if (!is_dir($match)) {
  112. $result[] = $match;
  113. }
  114. }
  115. if ($dh = opendir($subdir)) {
  116. while (FALSE !== ($entry = readdir($dh))) {
  117. $path = $subdir . DIRECTORY_SEPARATOR . $entry;
  118. if ($entry{0} == '.') {
  119. } elseif (is_dir($path)) {
  120. $todos[] = $path;
  121. }
  122. }
  123. closedir($dh);
  124. }
  125. }
  126. return $result;
  127. }
  128. /**
  129. * (Delegated) Implementation of hook_civicrm_managed
  130. *
  131. * Find any *.mgd.php files, merge their content, and return.
  132. */
  133. function _sepa_civix_civicrm_managed(&$entities) {
  134. $mgdFiles = _sepa_civix_find_files(__DIR__, '*.mgd.php');
  135. foreach ($mgdFiles as $file) {
  136. $es = include $file;
  137. foreach ($es as $e) {
  138. if (empty($e['module'])) {
  139. $e['module'] = 'org.project60.sepa';
  140. }
  141. $entities[] = $e;
  142. }
  143. }
  144. }
  145. /**
  146. * Glob wrapper which is guaranteed to return an array.
  147. *
  148. * The documentation for glob() says, "On some systems it is impossible to
  149. * distinguish between empty match and an error." Anecdotally, the return
  150. * result for an empty match is sometimes array() and sometimes FALSE.
  151. * This wrapper provides consistency.
  152. *
  153. * @see http://php.net/glob
  154. * @param string $pattern
  155. * @return array, possibly empty
  156. */
  157. function _sepa_civix_glob($pattern) {
  158. $result = glob($pattern);
  159. return is_array($result) ? $result : array();
  160. }
  161. /**
  162. * Inserts a navigation menu item at a given place in the hierarchy
  163. *
  164. * $menu - menu hierarchy
  165. * $path - path where insertion should happen (ie. Administer/System Settings)
  166. * $item - menu you need to insert (parent/child attributes will be filled for you)
  167. * $parentId - used internally to recurse in the menu structure
  168. */
  169. function _sepa_civix_insert_navigation_menu(&$menu, $path, $item, $parentId = NULL) {
  170. static $navId;
  171. // If we are done going down the path, insert menu
  172. if (empty($path)) {
  173. if (!$navId) $navId = CRM_Core_DAO::singleValueQuery("SELECT max(id) FROM civicrm_navigation");
  174. $navId ++;
  175. $menu[$navId] = array (
  176. 'attributes' => array_merge($item, array(
  177. 'label' => CRM_Utils_Array::value('name', $item),
  178. 'active' => 1,
  179. 'parentID' => $parentId,
  180. 'navID' => $navId,
  181. ))
  182. );
  183. return true;
  184. } else {
  185. // Find an recurse into the next level down
  186. $found = false;
  187. $path = explode('/', $path);
  188. $first = array_shift($path);
  189. foreach ($menu as $key => &$entry) {
  190. if ($entry['attributes']['name'] == $first) {
  191. if (!$entry['child']) $entry['child'] = array();
  192. $found = _sepa_civix_insert_navigation_menu($entry['child'], implode('/', $path), $item, $key);
  193. }
  194. }
  195. return $found;
  196. }
  197. }
  198. function _sepa_civix_civicrm_alterSettingsFolders(&$metaDataFolders = NULL){
  199. static $configured = FALSE;
  200. if ($configured) return;
  201. $configured = TRUE;
  202. $extRoot = dirname( __FILE__ ) . DIRECTORY_SEPARATOR;
  203. $extDir = $extRoot . 'settings';
  204. if(!in_array($extDir, $metaDataFolders)){
  205. $metaDataFolders[] = $extDir;
  206. }
  207. }