Merge pull request #22191 from eileenmcnaughton/smarty16
[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 $permissions['create OAuth tokens via auth code flow'] = [
55 $prefix . ts('create OAuth tokens via auth code flow'),
56 ts('Create OAuth tokens via the authorization code flow'),
57 ];
58 $permissions['manage my OAuth contact tokens'] = [
59 $prefix . ts('manage my OAuth contact tokens'),
60 ts("Manage user's own OAuth tokens"),
61 ];
62 $permissions['manage all OAuth contact tokens'] = [
63 $prefix . ts('manage all OAuth contact tokens'),
64 ts("Manage OAuth tokens for all contacts"),
65 ];
66 }
67
68 /**
69 * Implements hook_civicrm_caseTypes().
70 *
71 * Generate a list of case-types.
72 *
73 * Note: This hook only runs in CiviCRM 4.4+.
74 *
75 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_caseTypes
76 */
77 function oauth_client_civicrm_caseTypes(&$caseTypes) {
78 _oauth_client_civix_civicrm_caseTypes($caseTypes);
79 }
80
81 /**
82 * Implements hook_civicrm_angularModules().
83 *
84 * Generate a list of Angular modules.
85 *
86 * Note: This hook only runs in CiviCRM 4.5+. It may
87 * use features only available in v4.6+.
88 *
89 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_angularModules
90 */
91 function oauth_client_civicrm_angularModules(&$angularModules) {
92 _oauth_client_civix_civicrm_angularModules($angularModules);
93 }
94
95 /**
96 * Implements hook_civicrm_entityTypes().
97 *
98 * Declare entity types provided by this module.
99 *
100 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes
101 */
102 function oauth_client_civicrm_entityTypes(&$entityTypes) {
103 _oauth_client_civix_civicrm_entityTypes($entityTypes);
104 }
105
106 /**
107 * Implements hook_civicrm_thems().
108 */
109 function oauth_client_civicrm_themes(&$themes) {
110 _oauth_client_civix_civicrm_themes($themes);
111 }
112
113 // --- Functions below this ship commented out. Uncomment as required. ---
114
115 /**
116 * Implements hook_civicrm_preProcess().
117 *
118 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_preProcess
119 */
120 //function oauth_client_civicrm_preProcess($formName, &$form) {
121 //
122 //}
123
124 /**
125 * Implements hook_civicrm_navigationMenu().
126 *
127 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_navigationMenu
128 */
129 //function oauth_client_civicrm_navigationMenu(&$menu) {
130 // _oauth_client_civix_insert_navigation_menu($menu, 'Mailings', array(
131 // 'label' => E::ts('New subliminal message'),
132 // 'name' => 'mailing_subliminal_message',
133 // 'url' => 'civicrm/mailing/subliminal',
134 // 'permission' => 'access CiviMail',
135 // 'operator' => 'OR',
136 // 'separator' => 0,
137 // ));
138 // _oauth_client_civix_navigationMenu($menu);
139 //}
140
141 /**
142 * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
143 */
144 function oauth_client_civicrm_container($container) {
145 $container->addResource(new \Symfony\Component\Config\Resource\FileResource(__FILE__));
146 $container->setDefinition('oauth2.league', new \Symfony\Component\DependencyInjection\Definition(
147 \Civi\OAuth\OAuthLeagueFacade::class, []))->setPublic(TRUE);
148 $container->setDefinition('oauth2.token', new \Symfony\Component\DependencyInjection\Definition(
149 \Civi\OAuth\OAuthTokenFacade::class, []))->setPublic(TRUE);
150 }
151
152 /**
153 * Implements hook_civicrm_oauthProviders().
154 */
155 function oauth_client_civicrm_oauthProviders(&$providers) {
156 $ingest = function($pat) use (&$providers) {
157 $files = (array) glob($pat);
158 foreach ($files as $file) {
159 if (!defined('CIVICRM_TEST') && preg_match(';\.test\.json$;', $file)) {
160 continue;
161 }
162 $name = preg_replace(';\.(dist\.|test\.|)json$;', '', basename($file));
163 $provider = json_decode(file_get_contents($file), 1);
164 $provider['name'] = $name;
165 $providers[$name] = $provider;
166 }
167 };
168
169 $ingest(__DIR__ . '/providers/*.json');
170 $localDir = Civi::paths()->getPath('[civicrm.private]/oauth-providers');
171 if (file_exists($localDir)) {
172 $ingest($localDir . '/*.json');
173 }
174 }
175
176 /**
177 * Implements hook_civicrm_mailSetupActions().
178 *
179 * @see CRM_Utils_Hook::mailSetupActions()
180 */
181 function oauth_client_civicrm_mailSetupActions(&$setupActions) {
182 $setupActions = array_merge($setupActions, CRM_OAuth_MailSetup::buildSetupLinks());
183 }
184
185 /**
186 * Implements hook_civicrm_oauthReturn().
187 */
188 function oauth_client_civicrm_oauthReturn($token, &$nextUrl) {
189 CRM_OAuth_MailSetup::onReturn($token, $nextUrl);
190 }
191
192 /**
193 * Implements hook_civicrm_alterMailStore().
194 *
195 * @see CRM_Utils_Hook::alterMailStore()
196 */
197 function oauth_client_civicrm_alterMailStore(&$mailSettings) {
198 CRM_OAuth_MailSetup::alterMailStore($mailSettings);
199 }