/**
* Gather functions from tokens in tokens folder
*/
function civitoken_initialize()
{
    static $civitoken_init = null;
    static $tokens = array();
    if ($civitoken_init) {
        return $tokens;
    }
    static $tokenFiles = null;
    $config = CRM_Core_Config::singleton();
    if (!is_array($tokenFiles)) {
        $directories = array(__DIR__ . '/tokens');
        if (!empty($config->customPHPPathDir)) {
            if (file_exists($config->customPHPPathDir . '/tokens')) {
                $directories[] = $config->customPHPPathDir . '/tokens';
            }
        }
        foreach ($directories as $directory) {
            $tokenFiles = _civitoken_civix_find_files($directory, '*.inc');
            foreach ($tokenFiles as $file) {
                require_once $file;
                $re = "/.*\\/([a-z]*).inc/";
                preg_match($re, $file, $matches);
                $tokens[] = $matches[1];
            }
        }
    }
    $civitoken_init = 1;
    return $tokens;
}
/**
 * (Delegated) Implementation of hook_civicrm_managed
 *
 * Find any *.mgd.php files, merge their content, and return.
 *
 * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_managed
 */
function _civitoken_civix_civicrm_managed(&$entities)
{
    $mgdFiles = _civitoken_civix_find_files(__DIR__, '*.mgd.php');
    foreach ($mgdFiles as $file) {
        $es = (include $file);
        foreach ($es as $e) {
            if (empty($e['module'])) {
                $e['module'] = 'nz.co.fuzion.civitoken';
            }
            $entities[] = $e;
        }
    }
}