Merge pull request #20185 from civicrm/5.37
[civicrm-core.git] / ext / oauth-client / oauth_client.php
1 <?php
2
3 require_once 'oauth_client.civix.php';
4 // phpcs:disable
5 use CRM_OauthClient_ExtensionUtil as E;
6 // phpcs:enable
7
8 /**
9 * Implements hook_civicrm_config().
10 *
11 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config/
12 */
13 function oauth_client_civicrm_config(&$config) {
14 _oauth_client_civix_civicrm_config($config);
15 }
16
17 /**
18 * Implements hook_civicrm_xmlMenu().
19 *
20 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_xmlMenu
21 */
22 function oauth_client_civicrm_xmlMenu(&$files) {
23 _oauth_client_civix_civicrm_xmlMenu($files);
24 }
25
26 /**
27 * Implements hook_civicrm_managed().
28 *
29 * Generate a list of entities to create/deactivate/delete when this module
30 * is installed, disabled, uninstalled.
31 *
32 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_managed
33 */
34 function oauth_client_civicrm_managed(&$entities) {
35 _oauth_client_civix_civicrm_managed($entities);
36 }
37
38 /**
39 * Implements hook_civicrm_permission().
40 *
41 * @see CRM_Utils_Hook::permission()
42 * @see CRM_Core_Permission::getCorePermissions()
43 */
44 function oauth_client_civicrm_permission(&$permissions) {
45 $prefix = ts('CiviCRM') . ': ';
46 $permissions['manage OAuth client'] = [
47 $prefix . ts('manage OAuth client'),
48 ts('Create and delete OAuth client connections'),
49 ];
50 $permissions['manage OAuth client secrets'] = [
51 $prefix . ts('manage OAuth client secrets'),
52 ts('Access OAuth secrets'),
53 ];
54 }
55
56 /**
57 * Implements hook_civicrm_caseTypes().
58 *
59 * Generate a list of case-types.
60 *
61 * Note: This hook only runs in CiviCRM 4.4+.
62 *
63 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_caseTypes
64 */
65 function oauth_client_civicrm_caseTypes(&$caseTypes) {
66 _oauth_client_civix_civicrm_caseTypes($caseTypes);
67 }
68
69 /**
70 * Implements hook_civicrm_angularModules().
71 *
72 * Generate a list of Angular modules.
73 *
74 * Note: This hook only runs in CiviCRM 4.5+. It may
75 * use features only available in v4.6+.
76 *
77 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_angularModules
78 */
79 function oauth_client_civicrm_angularModules(&$angularModules) {
80 _oauth_client_civix_civicrm_angularModules($angularModules);
81 }
82
83 /**
84 * Implements hook_civicrm_alterSettingsFolders().
85 *
86 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterSettingsFolders
87 */
88 function oauth_client_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
89 _oauth_client_civix_civicrm_alterSettingsFolders($metaDataFolders);
90 }
91
92 /**
93 * Implements hook_civicrm_entityTypes().
94 *
95 * Declare entity types provided by this module.
96 *
97 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes
98 */
99 function oauth_client_civicrm_entityTypes(&$entityTypes) {
100 _oauth_client_civix_civicrm_entityTypes($entityTypes);
101 }
102
103 /**
104 * Implements hook_civicrm_thems().
105 */
106 function oauth_client_civicrm_themes(&$themes) {
107 _oauth_client_civix_civicrm_themes($themes);
108 }
109
110 // --- Functions below this ship commented out. Uncomment as required. ---
111
112 /**
113 * Implements hook_civicrm_preProcess().
114 *
115 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_preProcess
116 */
117 //function oauth_client_civicrm_preProcess($formName, &$form) {
118 //
119 //}
120
121 /**
122 * Implements hook_civicrm_navigationMenu().
123 *
124 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_navigationMenu
125 */
126 //function oauth_client_civicrm_navigationMenu(&$menu) {
127 // _oauth_client_civix_insert_navigation_menu($menu, 'Mailings', array(
128 // 'label' => E::ts('New subliminal message'),
129 // 'name' => 'mailing_subliminal_message',
130 // 'url' => 'civicrm/mailing/subliminal',
131 // 'permission' => 'access CiviMail',
132 // 'operator' => 'OR',
133 // 'separator' => 0,
134 // ));
135 // _oauth_client_civix_navigationMenu($menu);
136 //}
137
138 /**
139 * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
140 */
141 function oauth_client_civicrm_container($container) {
142 $container->addResource(new \Symfony\Component\Config\Resource\FileResource(__FILE__));
143 $container->setDefinition('oauth2.league', new \Symfony\Component\DependencyInjection\Definition(
144 \Civi\OAuth\OAuthLeagueFacade::class, []))->setPublic(TRUE);
145 $container->setDefinition('oauth2.token', new \Symfony\Component\DependencyInjection\Definition(
146 \Civi\OAuth\OAuthTokenFacade::class, []))->setPublic(TRUE);
147 }
148
149 /**
150 * Implements hook_civicrm_oauthProviders().
151 */
152 function oauth_client_civicrm_oauthProviders(&$providers) {
153 $ingest = function($pat) use (&$providers) {
154 $files = (array) glob($pat);
155 foreach ($files as $file) {
156 if (!defined('CIVICRM_TEST') && preg_match(';\.test\.json$;', $file)) {
157 continue;
158 }
159 $name = preg_replace(';\.(dist\.|test\.|)json$;', '', basename($file));
160 $provider = json_decode(file_get_contents($file), 1);
161 $provider['name'] = $name;
162 $providers[$name] = $provider;
163 }
164 };
165
166 $ingest(__DIR__ . '/providers/*.json');
167 $localDir = Civi::paths()->getPath('[civicrm.private]/oauth-providers');
168 if (file_exists($localDir)) {
169 $ingest($localDir . '/*.json');
170 }
171 }
172
173 /**
174 * Implements hook_civicrm_mailSetupActions().
175 *
176 * @see CRM_Utils_Hook::mailSetupActions()
177 */
178 function oauth_client_civicrm_mailSetupActions(&$setupActions) {
179 $setupActions = array_merge($setupActions, CRM_OAuth_MailSetup::buildSetupLinks());
180 }
181
182 /**
183 * Implements hook_civicrm_oauthReturn().
184 */
185 function oauth_client_civicrm_oauthReturn($token, &$nextUrl) {
186 CRM_OAuth_MailSetup::onReturn($token, $nextUrl);
187 }
188
189 /**
190 * Implements hook_civicrm_alterMailStore().
191 *
192 * @see CRM_Utils_Hook::alterMailStore()
193 */
194 function oauth_client_civicrm_alterMailStore(&$mailSettings) {
195 CRM_OAuth_MailSetup::alterMailStore($mailSettings);
196 }