Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Twilio
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container registry
Model registry
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Extensions
Twilio
Commits
cbedb504
Unverified
Commit
cbedb504
authored
1 year ago
by
JonGold
Browse files
Options
Downloads
Patches
Plain Diff
CiviCRM 23.02.1
parent
1c8237f7
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!1
CiviCRM 23.02.1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
info.xml
+10
-3
10 additions, 3 deletions
info.xml
mixin/polyfill.php
+101
-0
101 additions, 0 deletions
mixin/polyfill.php
twilio.civix.php
+157
-102
157 additions, 102 deletions
twilio.civix.php
twilio.php
+2
-34
2 additions, 34 deletions
twilio.php
with
270 additions
and
139 deletions
info.xml
+
10
−
3
View file @
cbedb504
...
...
@@ -15,11 +15,18 @@
<author>
Community Contributed
</author>
<email>
info@civicrm.org
</email>
</maintainer>
<releaseDate>
20
17-10
-0
9
</releaseDate>
<version>
1.2.
1
</version>
<releaseDate>
20
24-02
-0
5
</releaseDate>
<version>
1.2.
2
</version>
<develStage>
stable
</develStage>
<compatibility>
<ver>
5.0
</ver>
</compatibility>
<comments></comments>
<comments/>
<civix>
<namespace>
Crm/Twilio
</namespace>
<format>
23.02.1
</format>
</civix>
<classloader>
<psr4
prefix=
"Civi\"
path=
"Civi"
/>
</classloader>
</extension>
This diff is collapsed.
Click to expand it.
mixin/polyfill.php
0 → 100644
+
101
−
0
View file @
cbedb504
<?php
/**
* When deploying on systems that lack mixin support, fake it.
*
* @mixinFile polyfill.php
*
* This polyfill does some (persnickity) deduplication, but it doesn't allow upgrades or shipping replacements in core.
*
* Note: The polyfill.php is designed to be copied into extensions for interoperability. Consequently, this file is
* not used 'live' by `civicrm-core`. However, the file does need a canonical home, and it's convenient to keep it
* adjacent to the actual mixin files.
*
* @param string $longName
* @param string $shortName
* @param string $basePath
*/
return
function
(
$longName
,
$shortName
,
$basePath
)
{
// Construct imitations of the mixin services. These cannot work as well (e.g. with respect to
// number of file-reads, deduping, upgrading)... but they should be OK for a few months while
// the mixin services become available.
// List of active mixins; deduped by version
$mixinVers
=
[];
foreach
((
array
)
glob
(
$basePath
.
'/mixin/*.mixin.php'
)
as
$f
)
{
[
$name
,
$ver
]
=
explode
(
'@'
,
substr
(
basename
(
$f
),
0
,
-
10
));
if
(
!
isset
(
$mixinVers
[
$name
])
||
version_compare
(
$ver
,
$mixinVers
[
$name
],
'>'
))
{
$mixinVers
[
$name
]
=
$ver
;
}
}
$mixins
=
[];
foreach
(
$mixinVers
as
$name
=>
$ver
)
{
$mixins
[]
=
"
$name
@
$ver
"
;
}
// Imitate CRM_Extension_MixInfo.
$mixInfo
=
new
class
()
{
/**
* @var string
*/
public
$longName
;
/**
* @var string
*/
public
$shortName
;
public
$_basePath
;
public
function
getPath
(
$file
=
NULL
)
{
return
$this
->
_basePath
.
(
$file
===
NULL
?
''
:
(
DIRECTORY_SEPARATOR
.
$file
));
}
public
function
isActive
()
{
return
\CRM_Extension_System
::
singleton
()
->
getMapper
()
->
isActiveModule
(
$this
->
shortName
);
}
};
$mixInfo
->
longName
=
$longName
;
$mixInfo
->
shortName
=
$shortName
;
$mixInfo
->
_basePath
=
$basePath
;
// Imitate CRM_Extension_BootCache.
$bootCache
=
new
class
()
{
public
function
define
(
$name
,
$callback
)
{
$envId
=
\CRM_Core_Config_Runtime
::
getId
();
$oldExtCachePath
=
\Civi
::
paths
()
->
getPath
(
"[civicrm.compile]/CachedExtLoader.
{
$envId
}
.php"
);
$stat
=
stat
(
$oldExtCachePath
);
$file
=
Civi
::
paths
()
->
getPath
(
'[civicrm.compile]/CachedMixin.'
.
md5
(
$name
.
(
$stat
[
'mtime'
]
??
0
))
.
'.php'
);
if
(
file_exists
(
$file
))
{
return
include
$file
;
}
else
{
$data
=
$callback
();
file_put_contents
(
$file
,
'<'
.
"?php
\n
return "
.
var_export
(
$data
,
1
)
.
';'
);
return
$data
;
}
}
};
// Imitate CRM_Extension_MixinLoader::run()
// Parse all live mixins before trying to scan any classes.
global
$_CIVIX_MIXIN_POLYFILL
;
foreach
(
$mixins
as
$mixin
)
{
// If the exact same mixin is defined by multiple exts, just use the first one.
if
(
!
isset
(
$_CIVIX_MIXIN_POLYFILL
[
$mixin
]))
{
$_CIVIX_MIXIN_POLYFILL
[
$mixin
]
=
include_once
$basePath
.
'/mixin/'
.
$mixin
.
'.mixin.php'
;
}
}
foreach
(
$mixins
as
$mixin
)
{
// If there's trickery about installs/uninstalls/resets, then we may need to register a second time.
if
(
!
isset
(
\Civi
::
$statics
[
$longName
][
$mixin
]))
{
\Civi
::
$statics
[
$longName
][
$mixin
]
=
1
;
$func
=
$_CIVIX_MIXIN_POLYFILL
[
$mixin
];
$func
(
$mixInfo
,
$bootCache
);
}
}
};
This diff is collapsed.
Click to expand it.
twilio.civix.php
+
157
−
102
View file @
cbedb504
...
...
@@ -3,150 +3,205 @@
// AUTO-GENERATED FILE -- Civix may overwrite any changes made to this file
/**
* (Delegated) Implementation of hook_civicrm_config
* The ExtensionUtil class provides small stubs for accessing resources of this
* extension.
*/
function
_twilio_civix_civicrm_config
(
&
$config
=
NULL
)
{
static
$configured
=
FALSE
;
if
(
$configured
)
return
;
$configured
=
TRUE
;
class
Crm_Twilio_ExtensionUtil
{
const
SHORT_NAME
=
'twilio'
;
const
LONG_NAME
=
'org.civicrm.sms.twilio'
;
const
CLASS_PREFIX
=
'Crm_Twilio'
;
/**
* Translate a string using the extension's domain.
*
* If the extension doesn't have a specific translation
* for the string, fallback to the default translations.
*
* @param string $text
* Canonical message text (generally en_US).
* @param array $params
* @return string
* Translated text.
* @see ts
*/
public
static
function
ts
(
$text
,
$params
=
[]):
string
{
if
(
!
array_key_exists
(
'domain'
,
$params
))
{
$params
[
'domain'
]
=
[
self
::
LONG_NAME
,
NULL
];
}
return
ts
(
$text
,
$params
);
}
$template
=&
CRM_Core_Smarty
::
singleton
();
/**
* Get the URL of a resource file (in this extension).
*
* @param string|NULL $file
* Ex: NULL.
* Ex: 'css/foo.css'.
* @return string
* Ex: 'http://example.org/sites/default/ext/org.example.foo'.
* Ex: 'http://example.org/sites/default/ext/org.example.foo/css/foo.css'.
*/
public
static
function
url
(
$file
=
NULL
):
string
{
if
(
$file
===
NULL
)
{
return
rtrim
(
CRM_Core_Resources
::
singleton
()
->
getUrl
(
self
::
LONG_NAME
),
'/'
);
}
return
CRM_Core_Resources
::
singleton
()
->
getUrl
(
self
::
LONG_NAME
,
$file
);
}
$extRoot
=
dirname
(
__FILE__
)
.
DIRECTORY_SEPARATOR
;
$extDir
=
$extRoot
.
'templates'
;
/**
* Get the path of a resource file (in this extension).
*
* @param string|NULL $file
* Ex: NULL.
* Ex: 'css/foo.css'.
* @return string
* Ex: '/var/www/example.org/sites/default/ext/org.example.foo'.
* Ex: '/var/www/example.org/sites/default/ext/org.example.foo/css/foo.css'.
*/
public
static
function
path
(
$file
=
NULL
)
{
// return CRM_Core_Resources::singleton()->getPath(self::LONG_NAME, $file);
return
__DIR__
.
(
$file
===
NULL
?
''
:
(
DIRECTORY_SEPARATOR
.
$file
));
}
if
(
is_array
(
$template
->
template_dir
)
)
{
array_unshift
(
$template
->
template_dir
,
$extDir
);
}
else
{
$template
->
template_dir
=
array
(
$extDir
,
$template
->
template_dir
);
/**
* Get the name of a class within this extension.
*
* @param string $suffix
* Ex: 'Page_HelloWorld' or 'Page\\HelloWorld'.
* @return string
* Ex: 'CRM_Foo_Page_HelloWorld'.
*/
public
static
function
findClass
(
$suffix
)
{
return
self
::
CLASS_PREFIX
.
'_'
.
str_replace
(
'\\'
,
'_'
,
$suffix
);
}
$include_path
=
$extRoot
.
PATH_SEPARATOR
.
get_include_path
(
);
set_include_path
(
$include_path
);
}
use
Crm_Twilio_ExtensionUtil
as
E
;
function
_twilio_civix_mixin_polyfill
()
{
if
(
!
class_exists
(
'CRM_Extension_MixInfo'
))
{
$polyfill
=
__DIR__
.
'/mixin/polyfill.php'
;
(
require
$polyfill
)(
E
::
LONG_NAME
,
E
::
SHORT_NAME
,
E
::
path
());
}
}
/**
* (Delegated) Implement
ation of
hook_civicrm_
xmlMenu
* (Delegated) Implement
s
hook_civicrm_
config().
*
* @
param $files array(string)
* @
link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config
*/
function
_twilio_civix_civicrm_xmlMenu
(
&
$files
)
{
foreach
(
glob
(
__DIR__
.
'/xml/Menu/*.xml'
)
as
$file
)
{
$files
[]
=
$file
;
function
_twilio_civix_civicrm_config
(
$config
=
NULL
)
{
static
$configured
=
FALSE
;
if
(
$configured
)
{
return
;
}
$configured
=
TRUE
;
$extRoot
=
__DIR__
.
DIRECTORY_SEPARATOR
;
$include_path
=
$extRoot
.
PATH_SEPARATOR
.
get_include_path
();
set_include_path
(
$include_path
);
_twilio_civix_mixin_polyfill
();
}
/**
* Implementation of hook_civicrm_install
* Implements hook_civicrm_install().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_install
*/
function
_twilio_civix_civicrm_install
()
{
_twilio_civix_civicrm_config
();
if
(
$upgrader
=
_twilio_civix_upgrader
())
{
return
$upgrader
->
onInstall
();
}
_twilio_civix_mixin_polyfill
();
}
/**
* Implementation of hook_civicrm_uninstall
* (Delegated) Implements hook_civicrm_enable().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_enable
*/
function
_twilio_civix_civicrm_
uninstall
()
{
function
_twilio_civix_civicrm_
enable
():
void
{
_twilio_civix_civicrm_config
();
if
(
$upgrader
=
_twilio_civix_upgrader
())
{
return
$upgrader
->
onUninstall
();
}
_twilio_civix_mixin_polyfill
();
}
/**
* (Delegated) Implementation of hook_civicrm_enable
* Inserts a navigation menu item at a given place in the hierarchy.
*
* @param array $menu - menu hierarchy
* @param string $path - path to parent of this item, e.g. 'my_extension/submenu'
* 'Mailing', or 'Administer/System Settings'
* @param array $item - the item to insert (parent/child attributes will be
* filled for you)
*
* @return bool
*/
function
_twilio_civix_civicrm_enable
()
{
_twilio_civix_civicrm_config
();
if
(
$upgrader
=
_twilio_civix_upgrader
())
{
if
(
is_callable
(
array
(
$upgrader
,
'onEnable'
)))
{
return
$upgrader
->
onEnable
();
function
_twilio_civix_insert_navigation_menu
(
&
$menu
,
$path
,
$item
)
{
// If we are done going down the path, insert menu
if
(
empty
(
$path
))
{
$menu
[]
=
[
'attributes'
=>
array_merge
([
'label'
=>
$item
[
'name'
]
??
NULL
,
'active'
=>
1
,
],
$item
),
];
return
TRUE
;
}
else
{
// Find an recurse into the next level down
$found
=
FALSE
;
$path
=
explode
(
'/'
,
$path
);
$first
=
array_shift
(
$path
);
foreach
(
$menu
as
$key
=>
&
$entry
)
{
if
(
$entry
[
'attributes'
][
'name'
]
==
$first
)
{
if
(
!
isset
(
$entry
[
'child'
]))
{
$entry
[
'child'
]
=
[];
}
$found
=
_twilio_civix_insert_navigation_menu
(
$entry
[
'child'
],
implode
(
'/'
,
$path
),
$item
);
}
}
return
$found
;
}
}
/**
* (Delegated) Implement
ation of
hook_civicrm_
disable
* (Delegated) Implement
s
hook_civicrm_
navigationMenu().
*/
function
_twilio_civix_civicrm_disable
()
{
_twilio_civix_civicrm_config
();
if
(
$upgrader
=
_twilio_civix_upgrader
())
{
if
(
is_callable
(
array
(
$upgrader
,
'onDisable'
)))
{
return
$upgrader
->
onDisable
();
}
function
_twilio_civix_navigationMenu
(
&
$nodes
)
{
if
(
!
is_callable
([
'CRM_Core_BAO_Navigation'
,
'fixNavigationMenu'
]))
{
_twilio_civix_fixNavigationMenu
(
$nodes
);
}
}
/**
* (Delegated) Implementation of hook_civicrm_upgrade
*
* @param $op string, the type of operation being performed; 'check' or 'enqueue'
* @param $queue CRM_Queue_Queue, (for 'enqueue') the modifiable list of pending up upgrade tasks
*
* @return mixed based on op. for 'check', returns array(boolean) (TRUE if upgrades are pending)
* for 'enqueue', returns void
* Given a navigation menu, generate navIDs for any items which are
* missing them.
*/
function
_twilio_civix_civicrm_upgrade
(
$op
,
CRM_Queue_Queue
$queue
=
NULL
)
{
if
(
$upgrader
=
_twilio_civix_upgrader
())
{
return
$upgrader
->
onUpgrade
(
$op
,
$queue
);
}
}
function
_twilio_civix_upgrader
()
{
if
(
!
file_exists
(
__DIR__
.
'/CRM/Twilio/Upgrader.php'
))
{
return
NULL
;
}
else
{
return
CRM_Twilio_Upgrader_Base
::
instance
();
}
function
_twilio_civix_fixNavigationMenu
(
&
$nodes
)
{
$maxNavID
=
1
;
array_walk_recursive
(
$nodes
,
function
(
$item
,
$key
)
use
(
&
$maxNavID
)
{
if
(
$key
===
'navID'
)
{
$maxNavID
=
max
(
$maxNavID
,
$item
);
}
});
_twilio_civix_fixNavigationMenuItems
(
$nodes
,
$maxNavID
,
NULL
);
}
/**
* Search directory tree for files which match a glob pattern
*
* @param $dir string, base dir
* @param $pattern string, glob pattern, eg "*.txt"
* @return array(string)
*/
function
_twilio_civix_find_files
(
$dir
,
$pattern
)
{
$todos
=
array
(
$dir
);
$result
=
array
();
while
(
!
empty
(
$todos
))
{
$subdir
=
array_shift
(
$todos
);
foreach
(
glob
(
"
$subdir
/
$pattern
"
)
as
$match
)
{
if
(
!
is_dir
(
$match
))
{
$result
[]
=
$match
;
}
function
_twilio_civix_fixNavigationMenuItems
(
&
$nodes
,
&
$maxNavID
,
$parentID
)
{
$origKeys
=
array_keys
(
$nodes
);
foreach
(
$origKeys
as
$origKey
)
{
if
(
!
isset
(
$nodes
[
$origKey
][
'attributes'
][
'parentID'
])
&&
$parentID
!==
NULL
)
{
$nodes
[
$origKey
][
'attributes'
][
'parentID'
]
=
$parentID
;
}
if
(
$dh
=
opendir
(
$subdir
))
{
while
(
FALSE
!==
(
$entry
=
readdir
(
$dh
)))
{
$path
=
$subdir
.
DIRECTORY_SEPARATOR
.
$entry
;
if
(
$entry
==
'.'
||
$entry
==
'..'
)
{
}
elseif
(
is_dir
(
$path
))
{
$todos
[]
=
$path
;
}
}
closedir
(
$dh
);
// If no navID, then assign navID and fix key.
if
(
!
isset
(
$nodes
[
$origKey
][
'attributes'
][
'navID'
]))
{
$newKey
=
++
$maxNavID
;
$nodes
[
$origKey
][
'attributes'
][
'navID'
]
=
$newKey
;
$nodes
[
$newKey
]
=
$nodes
[
$origKey
];
unset
(
$nodes
[
$origKey
]);
$origKey
=
$newKey
;
}
}
return
$result
;
}
/**
* (Delegated) Implementation of hook_civicrm_managed
*
* Find any *.mgd.php files, merge their content, and return.
*/
function
_twilio_civix_civicrm_managed
(
&
$entities
)
{
$mgdFiles
=
_twilio_civix_find_files
(
__DIR__
,
'*.mgd.php'
);
foreach
(
$mgdFiles
as
$file
)
{
$es
=
include
$file
;
foreach
(
$es
as
$e
)
{
if
(
empty
(
$e
[
'module'
]))
{
$e
[
'module'
]
=
'org.civicrm.sms.twilio'
;
}
$entities
[]
=
$e
;
if
(
isset
(
$nodes
[
$origKey
][
'child'
])
&&
is_array
(
$nodes
[
$origKey
][
'child'
]))
{
_twilio_civix_fixNavigationMenuItems
(
$nodes
[
$origKey
][
'child'
],
$maxNavID
,
$nodes
[
$origKey
][
'attributes'
][
'navID'
]);
}
}
}
This diff is collapsed.
Click to expand it.
twilio.php
+
2
−
34
View file @
cbedb504
...
...
@@ -9,15 +9,6 @@ function twilio_civicrm_config(&$config) {
_twilio_civix_civicrm_config
(
$config
);
}
/**
* Implementation of hook_civicrm_xmlMenu
*
* @param $files array(string)
*/
function
twilio_civicrm_xmlMenu
(
&
$files
)
{
_twilio_civix_civicrm_xmlMenu
(
$files
);
}
/**
* Implementation of hook_civicrm_install
*/
...
...
@@ -53,7 +44,7 @@ function twilio_civicrm_uninstall() {
CRM_SMS_BAO_Provider
::
del
(
$value
[
'id'
]);
}
}
return
_twilio_civix_civicrm_uninstall
()
;
return
;
}
/**
...
...
@@ -93,28 +84,5 @@ function twilio_civicrm_disable() {
CRM_SMS_BAO_Provider
::
setIsActive
(
$value
[
'id'
],
FALSE
);
}
}
return
_twilio_civix_civicrm_disable
();
}
/**
* Implementation of hook_civicrm_upgrade
*
* @param $op string, the type of operation being performed; 'check' or 'enqueue'
* @param $queue CRM_Queue_Queue, (for 'enqueue') the modifiable list of pending up upgrade tasks
*
* @return mixed based on op. for 'check', returns array(boolean) (TRUE if upgrades are pending)
* for 'enqueue', returns void
*/
function
twilio_civicrm_upgrade
(
$op
,
CRM_Queue_Queue
$queue
=
NULL
)
{
return
_twilio_civix_civicrm_upgrade
(
$op
,
$queue
);
}
/**
* Implementation of hook_civicrm_managed
*
* Generate a list of entities to create/deactivate/delete when this module
* is installed, disabled, uninstalled.
*/
function
twilio_civicrm_managed
(
&
$entities
)
{
return
_twilio_civix_civicrm_managed
(
$entities
);
return
;
}
This diff is collapsed.
Click to expand it.
wil_SRQ
@wil_SRQ
·
1 year ago
Thanks for this Jon. As you know, UnidosNow relies on it heavily. - Wil
Thanks for this Jon. As you know, UnidosNow relies on it heavily. - Wil
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment