/** * Load needed JS, CSS and settings for the backend Volunteer Management UI */ public static function addResources($entity_id, $entity_table) { static $loaded = FALSE; if ($loaded) { return; } $loaded = TRUE; $config = CRM_Core_Config::singleton(); $ccr = CRM_Core_Resources::singleton(); // Vendor libraries $ccr->addScriptFile('civicrm', 'packages/backbone/json2.js', 100, 'html-header', FALSE); $ccr->addScriptFile('civicrm', 'packages/backbone/backbone-min.js', 120, 'html-header'); $ccr->addScriptFile('civicrm', 'packages/backbone/backbone.marionette.min.js', 125, 'html-header', FALSE); // Our stylesheet $ccr->addStyleFile('org.civicrm.volunteer', 'css/volunteer_app.css'); // Add all scripts for our js app $weight = 0; $baseDir = CRM_Extension_System::singleton()->getMapper()->keyToBasePath('org.civicrm.volunteer') . '/'; // This glob pattern will recurse the js directory up to 4 levels deep foreach (glob($baseDir . 'js/{*,*/*,*/*/*,*/*/*/*}.js', GLOB_BRACE) as $file) { $fileName = substr($file, strlen($baseDir)); $ccr->addScriptFile('org.civicrm.volunteer', $fileName, $weight++); } // Add our template CRM_Core_Smarty::singleton()->assign('isModulePermissionSupported', CRM_Core_Config::singleton()->userPermissionClass->isModulePermissionSupported()); CRM_Core_Region::instance('page-header')->add(array('template' => 'CRM/Volunteer/Form/Manage.tpl')); // Fetch event so we can set the default start time for needs // FIXME: Not the greatest for supporting non-events $entity = civicrm_api3(str_replace('civicrm_', '', $entity_table), 'getsingle', array('id' => $entity_id)); // Static variables $ccr->addSetting(array('pseudoConstant' => array('volunteer_need_visibility' => array_flip(CRM_Volunteer_BAO_Need::buildOptions('visibility_id', 'validate')), 'volunteer_role' => CRM_Volunteer_BAO_Need::buildOptions('role_id', 'get'), 'volunteer_status' => CRM_Activity_BAO_Activity::buildOptions('status_id', 'validate')), 'volunteer' => array('default_date' => CRM_Utils_Array::value('start_date', $entity)), 'config' => array('timeInputFormat' => $config->timeInputFormat))); // Check for problems _volunteer_civicrm_check_resource_url(); }
/** * run this page (figure out the action needed and perform it). * * @return void */ function run() { if (!CRM_Core_Permission::check('administer Reports')) { return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/report/list', 'reset=1')); } $optionVal = CRM_Report_Utils_Report::getValueFromUrl(); $templateInfo = CRM_Core_OptionGroup::getRowValues('report_template', "{$optionVal}", 'value', 'String', FALSE); $extKey = strpos(CRM_Utils_Array::value('name', $templateInfo), '.'); $reportClass = NULL; if ($extKey !== FALSE) { $ext = CRM_Extension_System::singleton()->getMapper(); $reportClass = $ext->keyToClass($templateInfo['name'], 'report'); $templateInfo['name'] = $reportClass; } if (strstr(CRM_Utils_Array::value('name', $templateInfo), '_Form') || !is_null($reportClass)) { CRM_Utils_System::setTitle($templateInfo['label'] . ' - Template'); $this->assign('reportTitle', $templateInfo['label']); $session = CRM_Core_Session::singleton(); $session->set('reportDescription', $templateInfo['description']); $wrapper = new CRM_Utils_Wrapper(); return $wrapper->run($templateInfo['name'], NULL, NULL); } if ($optionVal) { CRM_Core_Session::setStatus(ts('Could not find the report template. Make sure the report template is registered and / or url is correct.'), ts('Template Not Found'), 'error'); } return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/report/list', 'reset=1')); }
function run() { list($ext, $suite) = $this->getRequestExtAndSuite(); if (empty($ext) || empty($suite)) { throw new CRM_Core_Exception("FIXME: Not implemented: QUnit browser"); } if (!preg_match('/^[a-zA-Z0-9_\\-\\.]+$/', $suite) || strpos($suite, '..') !== FALSE) { throw new CRM_Core_Exception("Malformed suite name"); } $path = CRM_Extension_System::singleton()->getMapper()->keyToBasePath($ext); if (!is_dir("{$path}/tests/qunit/{$suite}")) { throw new CRM_Core_Exception("Failed to locate test suite"); } // Load the test suite -- including any PHP, TPL, or JS content if (file_exists("{$path}/tests/qunit/{$suite}/test.php")) { // e.g. load resources require_once "{$path}/tests/qunit/{$suite}/test.php"; } if (file_exists("{$path}/tests/qunit/{$suite}/test.tpl")) { // e.g. setup markup and/or load resources CRM_Core_Smarty::singleton()->addTemplateDir("{$path}/tests"); $this->assign('qunitTpl', "qunit/{$suite}/test.tpl"); } if (file_exists("{$path}/tests/qunit/{$suite}/test.js")) { CRM_Core_Resources::singleton()->addScriptFile($ext, "tests/qunit/{$suite}/test.js", 1000); } CRM_Utils_System::setTitle(ts('QUnit: %2 (%1)', array(1 => $ext, 2 => $suite))); CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'packages/qunit/qunit.js')->addStyleFile('civicrm', 'packages/qunit/qunit.css'); parent::run(); }
/** * Starting from the processor as an array retrieve the processor as an object. * * If there is no valid configuration it will not be retrieved. * * @param array $processor * @param bool $force * Override the config check. This is required in uninstall as no valid instances exist * but will deliberately not work with any valid processors. * * @return CRM_Core_Payment|NULL * * @throws \CRM_Core_Exception */ public function getByProcessor($processor, $force = FALSE) { $id = $force ? 0 : $processor['id']; if (!isset($this->cache[$id]) || $force) { $ext = \CRM_Extension_System::singleton()->getMapper(); if ($ext->isExtensionKey($processor['class_name'])) { $paymentClass = $ext->keyToClass($processor['class_name'], 'payment'); require_once $ext->classToPath($paymentClass); } else { $paymentClass = 'CRM_Core_' . $processor['class_name']; if (empty($paymentClass)) { throw new \CRM_Core_Exception('no class provided'); } require_once str_replace('_', DIRECTORY_SEPARATOR, $paymentClass) . '.php'; } $processorObject = new $paymentClass(!empty($processor['is_test']) ? 'test' : 'live', $processor); if (!$force && $processorObject->checkConfig()) { $processorObject = NULL; } else { $processorObject->setPaymentProcessor($processor); } $this->cache[$id] = $processorObject; } return $this->cache[$id]; }
/** * Singleton function used to manage this object. * * @param array $providerParams * @param bool $force * * @return object */ public static function &singleton($providerParams = array(), $force = FALSE) { $mailingID = CRM_Utils_Array::value('mailing_id', $providerParams); $providerID = CRM_Utils_Array::value('provider_id', $providerParams); $providerName = CRM_Utils_Array::value('provider', $providerParams); if (!$providerID && $mailingID) { $providerID = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing', $mailingID, 'sms_provider_id', 'id'); $providerParams['provider_id'] = $providerID; } if ($providerID) { $providerName = CRM_SMS_BAO_Provider::getProviderInfo($providerID, 'name'); } if (!$providerName) { CRM_Core_Error::fatal('Provider not known or not provided.'); } $providerName = CRM_Utils_Type::escape($providerName, 'String'); $cacheKey = "{$providerName}_" . (int) $providerID . "_" . (int) $mailingID; if (!isset(self::$_singleton[$cacheKey]) || $force) { $ext = CRM_Extension_System::singleton()->getMapper(); if ($ext->isExtensionKey($providerName)) { $paymentClass = $ext->keyToClass($providerName); require_once "{$paymentClass}.php"; } else { CRM_Core_Error::fatal("Could not locate extension for {$providerName}."); } self::$_singleton[$cacheKey] = $paymentClass::singleton($providerParams, $force); } return self::$_singleton[$cacheKey]; }
/** * Load needed JS, CSS and settings for the backend Volunteer Management UI */ public static function addResources($entity_id, $entity_table) { static $loaded = FALSE; $ccr = CRM_Core_Resources::singleton(); if ($loaded || $ccr->isAjaxMode()) { return; } $loaded = TRUE; $config = CRM_Core_Config::singleton(); // Vendor libraries $ccr->addScriptFile('civicrm', 'packages/backbone/json2.js', 100, 'html-header', FALSE); $ccr->addScriptFile('civicrm', 'packages/backbone/backbone-min.js', 120, 'html-header', FALSE); $ccr->addScriptFile('civicrm', 'packages/backbone/backbone.marionette.min.js', 125, 'html-header', FALSE); // Our stylesheet $ccr->addStyleFile('org.civicrm.volunteer', 'css/volunteer_app.css'); // Add all scripts for our js app $weight = 0; $baseDir = CRM_Extension_System::singleton()->getMapper()->keyToBasePath('org.civicrm.volunteer') . '/'; // This glob pattern will recurse the js directory up to 4 levels deep foreach (glob($baseDir . 'js/backbone/{*,*/*,*/*/*,*/*/*/*}.js', GLOB_BRACE) as $file) { $fileName = substr($file, strlen($baseDir)); $ccr->addScriptFile('org.civicrm.volunteer', $fileName, $weight++); } // Add our template CRM_Core_Smarty::singleton()->assign('isModulePermissionSupported', CRM_Core_Config::singleton()->userPermissionClass->isModulePermissionSupported()); CRM_Core_Region::instance('page-header')->add(array('template' => 'CRM/Volunteer/Form/Manage.tpl')); // Fetch event so we can set the default start time for needs // FIXME: Not the greatest for supporting non-events $entity = civicrm_api3(str_replace('civicrm_', '', $entity_table), 'getsingle', array('id' => $entity_id)); // Static variables $ccr->addSetting(array('pseudoConstant' => array('volunteer_need_visibility' => array_flip(CRM_Volunteer_BAO_Need::buildOptions('visibility_id', 'validate')), 'volunteer_role' => CRM_Volunteer_BAO_Need::buildOptions('role_id', 'get'), 'volunteer_status' => CRM_Activity_BAO_Activity::buildOptions('status_id', 'validate')), 'volunteer' => array('default_date' => CRM_Utils_Array::value('start_date', $entity)), 'config' => array('timeInputFormat' => $config->timeInputFormat), 'constants' => array('CRM_Core_Action' => array('NONE' => 0, 'ADD' => 1, 'UPDATE' => 2, 'VIEW' => 4, 'DELETE' => 8, 'BROWSE' => 16, 'ENABLE' => 32, 'DISABLE' => 64, 'EXPORT' => 128, 'BASIC' => 256, 'ADVANCED' => 512, 'PREVIEW' => 1024, 'FOLLOWUP' => 2048, 'MAP' => 4096, 'PROFILE' => 8192, 'COPY' => 16384, 'RENEW' => 32768, 'DETACH' => 65536, 'REVERT' => 131072, 'CLOSE' => 262144, 'REOPEN' => 524288, 'MAX_ACTION' => 1048575)))); // Check for problems _volunteer_checkResourceUrl(); }
function getTemplateFileName() { $ext = CRM_Extension_System::singleton()->getMapper(); if ($ext->isExtensionClass(CRM_Utils_System::getClassName($this->_customClass))) { $fileName = $ext->getTemplatePath(CRM_Utils_System::getClassName($this->_customClass)) . '/' . $ext->getTemplateName(CRM_Utils_System::getClassName($this->_customClass)); } else { $fileName = $this->_customClass->templateFile(); } return $fileName ? $fileName : parent::getTemplateFileName(); }
/** * Run this page (figure out the action needed and perform it). */ public function run() { $instanceId = CRM_Report_Utils_Report::getInstanceID(); if (!$instanceId) { $instanceId = CRM_Report_Utils_Report::getInstanceIDForPath(); } if (is_numeric($instanceId)) { $instanceURL = CRM_Utils_System::url("civicrm/report/instance/{$instanceId}", 'reset=1'); CRM_Core_Session::singleton()->replaceUserContext($instanceURL); } $action = CRM_Utils_Request::retrieve('action', 'String', $this); $optionVal = CRM_Report_Utils_Report::getValueFromUrl($instanceId); $reportUrl = CRM_Utils_System::url('civicrm/report/list', "reset=1"); if ($action & CRM_Core_Action::DELETE) { if (!CRM_Core_Permission::check('administer Reports')) { $statusMessage = ts('You do not have permission to Delete Report.'); CRM_Core_Error::statusBounce($statusMessage, $reportUrl); } $navId = CRM_Core_DAO::getFieldValue('CRM_Report_DAO_ReportInstance', $instanceId, 'navigation_id', 'id'); CRM_Report_BAO_ReportInstance::del($instanceId); //delete navigation if exists if ($navId) { CRM_Core_BAO_Navigation::processDelete($navId); CRM_Core_BAO_Navigation::resetNavigation(); } CRM_Core_Session::setStatus(ts('Selected report has been deleted.'), ts('Deleted'), 'success'); } else { $templateInfo = CRM_Core_OptionGroup::getRowValues('report_template', "{$optionVal}", 'value'); if (empty($templateInfo)) { CRM_Core_Error::statusBounce('You have tried to access a report that does not exist.'); } $extKey = strpos($templateInfo['name'], '.'); $reportClass = NULL; if ($extKey !== FALSE) { $ext = CRM_Extension_System::singleton()->getMapper(); $reportClass = $ext->keyToClass($templateInfo['name'], 'report'); $templateInfo['name'] = $reportClass; } if (strstr($templateInfo['name'], '_Form') || !is_null($reportClass)) { $instanceInfo = array(); CRM_Report_BAO_ReportInstance::retrieve(array('id' => $instanceId), $instanceInfo); if (!empty($instanceInfo['title'])) { CRM_Utils_System::setTitle($instanceInfo['title']); $this->assign('reportTitle', $instanceInfo['title']); } else { CRM_Utils_System::setTitle($templateInfo['label']); $this->assign('reportTitle', $templateInfo['label']); } $wrapper = new CRM_Utils_Wrapper(); return $wrapper->run($templateInfo['name'], NULL, NULL); } CRM_Core_Session::setStatus(ts('Could not find template for the instance.'), ts('Template Not Found'), 'error'); } return CRM_Utils_System::redirect($reportUrl); }
/** * Get a list of all known modules */ public static function getAll($fresh = FALSE) { static $result; if ($fresh || !is_array($result)) { $result = CRM_Extension_System::singleton()->getMapper()->getModules(); $config = CRM_Core_Config::singleton(); if (is_callable(array($config->userSystem, 'getModules'))) { $result = array_merge($result, $config->userSystem->getModules()); } } return $result; }
/** * Get a list of all known modules. * * @param bool $fresh * Force new results? * * @return array */ public static function getAll($fresh = FALSE) { static $result; if ($fresh || !is_array($result)) { $result = CRM_Extension_System::singleton()->getMapper()->getModules(); $result[] = new CRM_Core_Module('civicrm', TRUE); // pseudo-module for core $config = CRM_Core_Config::singleton(); $result = array_merge($result, $config->userSystem->getModules()); } return $result; }
/** * Register resources required by Angular. */ public function registerResources($region = 'html-header', $includeExtras = true) { $modules = $this->angular->getModules(); $page = $this; // PHP 5.3 does not propagate $this to inner functions. $page->res->addSettingsFactory(function () use(&$modules, $page) { // TODO optimization; client-side caching return array_merge($page->angular->getResources(array_keys($modules), 'settings', 'settings'), array('resourceUrls' => \CRM_Extension_System::singleton()->getMapper()->getActiveModuleUrls(), 'angular' => array('modules' => array_merge(array('ngRoute'), array_keys($modules)), 'cacheCode' => $page->res->getCacheCode()))); }); $page->res->addScriptFile('civicrm', 'bower_components/angular/angular.min.js', -100, $region, FALSE); if ($includeExtras) { //Civi vs 4.7 and above has reworked how wysiwyg works and we don't //have to side load ckeditor anymore $version = substr(CRM_Utils_System::version(), 0, 3); if ($version <= 4.6) { //crmUi depends on loading ckeditor, but ckeditor doesn't work properly with aggregation. //Add a basepath so that CKEditor works when Drupal (or other extension/cms) does the aggregation $basePath = $page->res->getUrl("civicrm") . "packages/ckeditor/"; $page->res->addScript("window.CKEDITOR_BASEPATH = '{$basePath}';", 119, $region, FALSE); $page->res->addScriptFile('civicrm', 'packages/ckeditor/ckeditor.js', 120, $region, FALSE); } //Add jquery Notify $page->res->addScriptFile('civicrm', 'packages/jquery/plugins/jquery.notify.min.js', 10, $region, FALSE); $page->assign("includeNotificationTemplate", true); } $headOffset = 1; $config = \CRM_Core_Config::singleton(); if ($config->debug) { foreach ($modules as $moduleName => $module) { foreach ($page->angular->getResources($moduleName, 'css', 'cacheUrl') as $url) { $page->res->addStyleUrl($url, self::DEFAULT_MODULE_WEIGHT + ++$headOffset, $region); } foreach ($page->angular->getResources($moduleName, 'js', 'cacheUrl') as $url) { $page->res->addScriptUrl($url, self::DEFAULT_MODULE_WEIGHT + ++$headOffset, $region); // addScriptUrl() bypasses the normal string-localization of addScriptFile(), // but that's OK because all Angular strings (JS+HTML) will load via crmResource. } } } else { // Note: addScriptUrl() bypasses the normal string-localization of addScriptFile(), // but that's OK because all Angular strings (JS+HTML) will load via crmResource. $aggScriptUrl = \CRM_Utils_System::url('civicrm/ajax/volunteer-angular-modules', 'format=js&r=' . $page->res->getCacheCode(), FALSE, NULL, FALSE); $page->res->addScriptUrl($aggScriptUrl, 1, $region); // FIXME: The following CSS aggregator doesn't currently handle path-adjustments - which can break icons. //$aggStyleUrl = \CRM_Utils_System::url('civicrm/ajax/angular-modules', 'format=css&r=' . $page->res->getCacheCode(), FALSE, NULL, FALSE); //$page->res->addStyleUrl($aggStyleUrl, 1, $region); foreach ($page->angular->getResources(array_keys($modules), 'css', 'cacheUrl') as $url) { $page->res->addStyleUrl($url, self::DEFAULT_MODULE_WEIGHT + ++$headOffset, $region); } } }
public function run($ctx) { $allKeys = \CRM_Extension_System::singleton()->getFullContainer()->getKeys(); $names = \CRM_Utils_String::filterByWildcards($this->names, $allKeys, TRUE); $manager = \CRM_Extension_System::singleton()->getManager(); switch ($this->action) { case 'install': $manager->install($names); break; case 'uninstall': $manager->disable($names); $manager->uninstall($names); break; } }
/** * This function will return the needed pieces to load up the backbone/ * marionette project backend from within an angular page. * * @param array $params * Not presently used. * @return array * Keyed with "css," "templates," "scripts," and "settings," this array * contains the dependencies of the backbone-based volunteer app. * */ function civicrm_api3_volunteer_util_loadbackbone($params) { $results = array("css" => array(), "templates" => array(), "scripts" => array(), "settings" => array()); $ccr = CRM_Core_Resources::singleton(); $config = CRM_Core_Config::singleton(); $results['css'][] = $ccr->getUrl('org.civicrm.volunteer', 'css/volunteer_app.css'); $baseDir = CRM_Extension_System::singleton()->getMapper()->keyToBasePath('org.civicrm.volunteer') . '/'; // This glob pattern will recurse the js directory up to 4 levels deep foreach (glob($baseDir . 'js/{*,*/*,*/*/*,*/*/*/*}.js', GLOB_BRACE) as $file) { $fileName = substr($file, strlen($baseDir)); $results['scripts'][] = $ccr->getUrl('org.civicrm.volunteer', $fileName); } $results['templates'][] = 'civicrm/volunteer/backbonetemplates'; $results['settings'] = array('pseudoConstant' => array('volunteer_need_visibility' => array_flip(CRM_Volunteer_BAO_Need::buildOptions('visibility_id', 'validate')), 'volunteer_role' => CRM_Volunteer_BAO_Need::buildOptions('role_id', 'get'), 'volunteer_status' => CRM_Activity_BAO_Activity::buildOptions('status_id', 'validate')), 'volunteer' => array('default_date' => date("Y-m-d H:i:s", strtotime('tomorrow noon'))), 'config' => array('timeInputFormat' => $config->timeInputFormat), 'constants' => array('CRM_Core_Action' => array('NONE' => 0, 'ADD' => 1, 'UPDATE' => 2, 'VIEW' => 4, 'DELETE' => 8, 'BROWSE' => 16, 'ENABLE' => 32, 'DISABLE' => 64, 'EXPORT' => 128, 'BASIC' => 256, 'ADVANCED' => 512, 'PREVIEW' => 1024, 'FOLLOWUP' => 2048, 'MAP' => 4096, 'PROFILE' => 8192, 'COPY' => 16384, 'RENEW' => 32768, 'DETACH' => 65536, 'REVERT' => 131072, 'CLOSE' => 262144, 'REOPEN' => 524288, 'MAX_ACTION' => 1048575))); return civicrm_api3_create_success($results, "VolunteerUtil", "loadbackbone", $params); }
/** * @param CRM_Core_Resources $res */ public function registerResources(CRM_Core_Resources $res) { $weight = self::DEFAULT_MODULE_WEIGHT; $res->addSettingsFactory(function () { // inorder to use ext resource url in JS - e.g CRM.resourceUrls $jsvar = array('resourceUrls' => CRM_Extension_System::singleton()->getMapper()->getActiveModuleUrls()); return $jsvar; }); $res->addStyleFile('uk.co.vedaconsulting.mosaico', 'packages/mosaico/dist/mosaico-material.min.css', $weight++, 'html-header', TRUE); $res->addStyleFile('uk.co.vedaconsulting.mosaico', 'packages/mosaico/dist/vendor/notoregular/stylesheet.css', $weight++, 'html-header', TRUE); $res->addScriptFile('uk.co.vedaconsulting.mosaico', 'packages/mosaico/dist/vendor/knockout.js', $weight++, 'html-header', TRUE); // civi already has jquery.min //$res->addScriptFile('uk.co.vedaconsulting.mosaico', 'packages/mosaico/dist/vendor/jquery.min.js', $weight++, 'html-header', TRUE); $res->addScriptFile('uk.co.vedaconsulting.mosaico', 'js/index.js', $weight++, 'html-header', FALSE); $res->addStyleFile('uk.co.vedaconsulting.mosaico', 'css/index.css', $weight++, 'html-header', TRUE); $res->addScriptFile('uk.co.vedaconsulting.mosaico', 'js/index2.js', $weight++, 'html-header', TRUE); }
/** * Register resources required by Angular. */ public function registerResources() { $modules = $this->angular->getModules(); $page = $this; // PHP 5.3 does not propagate $this to inner functions. $this->res->addSettingsFactory(function () use(&$modules, $page) { // TODO optimization; client-side caching return array_merge($page->angular->getResources(array_keys($modules), 'settings', 'settings'), array('resourceUrls' => \CRM_Extension_System::singleton()->getMapper()->getActiveModuleUrls(), 'angular' => array('modules' => array_merge(array('ngRoute'), array_keys($modules)), 'cacheCode' => $page->res->getCacheCode()))); }); $this->res->addScriptFile('civicrm', 'bower_components/angular/angular.min.js', 100, $this->region, FALSE); $headOffset = 0; $config = \CRM_Core_Config::singleton(); if ($config->debug) { foreach ($modules as $moduleName => $module) { foreach ($this->angular->getResources($moduleName, 'css', 'cacheUrl') as $url) { $this->res->addStyleUrl($url, self::DEFAULT_MODULE_WEIGHT + ++$headOffset, $this->region); } foreach ($this->angular->getResources($moduleName, 'js', 'cacheUrl') as $url) { $this->res->addScriptUrl($url, self::DEFAULT_MODULE_WEIGHT + ++$headOffset, $this->region); // addScriptUrl() bypasses the normal string-localization of addScriptFile(), // but that's OK because all Angular strings (JS+HTML) will load via crmResource. } } } else { // Note: addScriptUrl() bypasses the normal string-localization of addScriptFile(), // but that's OK because all Angular strings (JS+HTML) will load via crmResource. $aggScriptUrl = \CRM_Utils_System::url('civicrm/ajax/angular-modules', 'format=js&r=' . $page->res->getCacheCode(), FALSE, NULL, FALSE); $this->res->addScriptUrl($aggScriptUrl, 120, $this->region); // FIXME: The following CSS aggregator doesn't currently handle path-adjustments - which can break icons. //$aggStyleUrl = \CRM_Utils_System::url('civicrm/ajax/angular-modules', 'format=css&r=' . $page->res->getCacheCode(), FALSE, NULL, FALSE); //$this->res->addStyleUrl($aggStyleUrl, 120, $this->region); foreach ($this->angular->getResources(array_keys($modules), 'css', 'cacheUrl') as $url) { $this->res->addStyleUrl($url, self::DEFAULT_MODULE_WEIGHT + ++$headOffset, $this->region); } } // If trying to load an Angular page via AJAX, the route must be passed as a // URL parameter, since the server doesn't receive information about // URL fragments (i.e, what comes after the #). \CRM_Core_Resources::singleton()->addSetting(array('angularRoute' => \CRM_Utils_Request::retrieve('route', 'String'))); }
/** * Register resources required by Angular. */ public function registerResources() { $modules = $this->angular->getModules(); $page = $this; // PHP 5.3 does not propagate $this to inner functions. $this->res->addSettingsFactory(function () use(&$modules, $page) { // TODO optimization; client-side caching return array_merge($page->angular->getResources(array_keys($modules), 'settings', 'settings'), array('resourceUrls' => \CRM_Extension_System::singleton()->getMapper()->getActiveModuleUrls(), 'angular' => array('modules' => array_merge(array('ngRoute'), array_keys($modules)), 'cacheCode' => $page->res->getCacheCode()))); }); $this->res->addScriptFile('civicrm', 'bower_components/angular/angular.min.js', 100, 'html-header', FALSE); // FIXME: crmUi depends on loading ckeditor, but ckeditor doesn't work with this aggregation. $this->res->addScriptFile('civicrm', 'packages/ckeditor/ckeditor.js', 100, 'page-header', FALSE); //Add jquery Notify $this->res->addScriptFile('civicrm', 'packages/jquery/plugins/jquery.notify.min.js', -9990, 'html-header', FALSE); $headOffset = 0; $config = \CRM_Core_Config::singleton(); if ($config->debug) { foreach ($modules as $moduleName => $module) { foreach ($this->angular->getResources($moduleName, 'css', 'cacheUrl') as $url) { $this->res->addStyleUrl($url, self::DEFAULT_MODULE_WEIGHT + ++$headOffset, 'html-header'); } foreach ($this->angular->getResources($moduleName, 'js', 'cacheUrl') as $url) { $this->res->addScriptUrl($url, self::DEFAULT_MODULE_WEIGHT + ++$headOffset, 'html-header'); // addScriptUrl() bypasses the normal string-localization of addScriptFile(), // but that's OK because all Angular strings (JS+HTML) will load via crmResource. } } } else { // Note: addScriptUrl() bypasses the normal string-localization of addScriptFile(), // but that's OK because all Angular strings (JS+HTML) will load via crmResource. $aggScriptUrl = \CRM_Utils_System::url('civicrm/ajax/volunteer-angular-modules', 'format=js&r=' . $page->res->getCacheCode(), FALSE, NULL, FALSE); $this->res->addScriptUrl($aggScriptUrl, 120, 'html-header'); // FIXME: The following CSS aggregator doesn't currently handle path-adjustments - which can break icons. //$aggStyleUrl = \CRM_Utils_System::url('civicrm/ajax/angular-modules', 'format=css&r=' . $page->res->getCacheCode(), FALSE, NULL, FALSE); //$this->res->addStyleUrl($aggStyleUrl, 120, 'html-header'); foreach ($this->angular->getResources(array_keys($modules), 'css', 'cacheUrl') as $url) { $this->res->addStyleUrl($url, self::DEFAULT_MODULE_WEIGHT + ++$headOffset, 'html-header'); } } }
function hrui_civicrm_buildForm($formName, &$form) { CRM_Core_Resources::singleton()->addStyleFile('org.civicrm.hrui', 'css/hrui.css')->addScriptFile('org.civicrm.hrui', 'js/hrui.js'); if ($form instanceof CRM_Contact_Form_Contact) { CRM_Core_Resources::singleton()->addSetting(array('formName' => 'contactForm')); //HR-358 - Set default values //set default value to phone location and type $locationId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_LocationType', 'Main', 'id', 'name'); $result = civicrm_api3('LocationType', 'create', array('id' => $locationId, 'is_default' => 1, 'is_active' => 1)); if ($form->elementExists('phone[2][phone_type_id]') && $form->elementExists('phone[2][phone_type_id]')) { $phoneType = $form->getElement('phone[2][phone_type_id]'); $phoneValue = CRM_Core_OptionGroup::values('phone_type'); $phoneKey = CRM_Utils_Array::key('Mobile', $phoneValue); $phoneType->setSelected($phoneKey); $phoneLocation = $form->getElement('phone[2][location_type_id]'); $phoneLocation->setSelected($locationId); } } $ogID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'type_20130502144049', 'id', 'name'); //HR-355 -- Add Government ID if ($formName == 'CRM_Contact_Form_Contact' && $ogID && $form->_contactType == 'Individual') { //add government fields $contactID = CRM_Utils_Request::retrieve('cid', 'Integer', $form); $templatePath = CRM_Extension_System::singleton()->getMapper()->keyToBasePath('org.civicrm.hrui') . '/templates'; $form->add('text', 'GovernmentId', ts('Government ID')); $form->addElement('select', "govTypeOptions", '', CRM_Core_BAO_OptionValue::getOptionValuesAssocArray($ogID)); CRM_Core_Region::instance('page-body')->add(array('template' => "{$templatePath}/CRM/HRUI/Form/contactField.tpl")); $action = CRM_Utils_Request::retrieve('action', 'String', $form); $govVal = CRM_HRIdent_Page_HRIdent::retreiveContactFieldValue($contactID); //set default to government type option $default = array(); $default['govTypeOptions'] = CRM_Core_BAO_CustomField::getOptionGroupDefault($ogID, 'select'); if ($action == CRM_Core_Action::UPDATE && !empty($govVal)) { //set key for updating specific record of contact id in custom value table $default['govTypeOptions'] = CRM_Utils_Array::value('type', $govVal); $default['GovernmentId'] = CRM_Utils_Array::value('typeNumber', $govVal); } $form->setDefaults($default); } }
protected static function _populateDB($perClass = FALSE, &$object = NULL) { if (!parent::_populateDB($perClass, $object)) { return FALSE; } //populate vacancy_status of type Application $result = civicrm_api3('OptionGroup', 'create', array('name' => 'vacancy_status', 'title' => ts('Vacancy Status'), 'is_reserved' => 1, 'is_active' => 1)); $vacancyStatus = array('Draft' => ts('Draft'), 'Open' => ts('Open'), 'Closed' => ts('Closed'), 'Cancelled' => ts('Cancelled'), 'Rejected' => ts('Rejected')); $weight = 1; foreach ($vacancyStatus as $name => $label) { $statusParam = array('option_group_id' => $result['id'], 'label' => $label, 'name' => $name, 'value' => $weight++, 'is_active' => 1); if ($name == 'Draft') { $statusParam['is_default'] = 1; } elseif ($name == 'Open') { $statusParam['is_reserved'] = 1; } civicrm_api3('OptionValue', 'create', $statusParam); } $import = new CRM_Utils_Migrate_Import(); $import->run(CRM_Extension_System::singleton()->getMapper()->keyToBasePath('org.civicrm.hrrecruitment') . '/xml/auto_install.xml'); return TRUE; }
function run() { CRM_Utils_System::setTitle(ts('Extension File Overrides')); $system = CRM_Extension_System::singleton(); $manager = $system->getManager(); $container = $system->getDefaultContainer(); $keys = $container->getKeys(); foreach ($keys as $key) { $base_path = $container->getPath($key); $this->find_overrides($key, $base_path, '/api'); $this->find_overrides($key, $base_path, '/Civi'); $this->find_overrides($key, $base_path, '/CRM'); $this->find_overrides($key, $base_path, '/templates'); } $snapshot = $_SESSION['CiviCRM']['qfPrivateKey']; $this->look_for_changes(!empty($_POST['snapshot']) && $_POST['snapshot'] == $snapshot); $multiple = false; foreach ($this->core as &$core) { if (count($core['extensions']) > 1) { $core['multiple'] = $multiple = true; } } $extensions = $statuses = $friendly = array(); foreach ($this->extensions as $name => $files) { if (count($files) > 0) { $extensions[$name] = $files; $statuses[$name] = $manager->getStatus($name); $friendly[$name] = CRM_Core_DAO::singleValueQuery("SELECT name FROM civicrm_extension WHERE full_name=%1", array(1 => array($name, 'String'))) ?: $name; } } $this->assign('multiple', $multiple); $this->assign('extensions', $extensions); $this->assign('statuses', $statuses); $this->assign('friendly', $friendly); $this->assign('core', $this->core); $this->assign('snapshot', $snapshot); $this->assign('last_snapshot', CRM_Core_BAO_Setting::getItem('com.klangsoft_overrides', 'last_snapshot')); parent::run(); }
static function registerScripts() { static $loaded = FALSE; if ($loaded) { return; } $loaded = TRUE; CRM_Core_Resources::singleton()->addSettingsFactory(function () { $config = CRM_Core_Config::singleton(); return array('PseudoConstant' => array('locationType' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'), 'job_hours_time' => CRM_HRJob_Page_JobsTab::getJobHoursTime(), 'working_days' => CRM_HRJob_Page_JobsTab::getDaysPerTime()), 'FieldOptions' => CRM_HRJob_Page_JobsTab::getFieldOptions(), 'jobTabApp' => array('contact_id' => CRM_Utils_Request::retrieve('cid', 'Integer'), 'domain_id' => CRM_Core_Config::domainID(), 'isLogEnabled' => (bool) $config->logging, 'loggingReportId' => CRM_Report_Utils_Report::getInstanceIDForValue('logging/contact/summary'), 'currencies' => CRM_HRJob_Page_JobsTab::getCurrencyFormats(), 'defaultCurrency' => $config->defaultCurrency)); })->addScriptFile('civicrm', 'packages/backbone/json2.js', 100, 'html-header', FALSE)->addScriptFile('civicrm', 'packages/backbone/backbone.js', 120, 'html-header')->addScriptFile('civicrm', 'packages/backbone/backbone.marionette.js', 125, 'html-header', FALSE)->addScriptFile('civicrm', 'packages/backbone/backbone.modelbinder.js', 125, 'html-header', FALSE)->addScriptFile('civicrm', 'js/jquery/jquery.crmRevisionLink.js', 125, 'html-header', FALSE)->addScriptFile('org.civicrm.hrjob', 'js/jquery/jquery.hrContactLink.js', 125, 'html-header', FALSE)->addScriptFile('org.civicrm.hrjob', 'js/jquery/jquery.hrFileLink.js', 125, 'html-header', FALSE)->addScriptFile('org.civicrm.hrjob', 'js/jquery/jquery.lockButton.js', 125, 'html-header', FALSE)->addScriptFile('civicrm', 'js/crm.backbone.js', 130, 'html-header', FALSE)->addStyleFile('org.civicrm.hrjob', 'css/hrjob.css', 140, 'html-header')->addScriptFile('org.civicrm.hrjob', 'js/hrapp.js', 150, 'html-header')->addScriptFile('org.civicrm.hrjob', 'js/renderutil.js', 155, 'html-header')->addScriptFile('org.civicrm.hrjob', 'js/entities/hrjob.js', 155, 'html-header')->addScriptFile('org.civicrm.hrjob', 'js/common/navigation.js', 155, 'html-header')->addScriptFile('org.civicrm.hrjob', 'js/common/mbind.js', 155, 'html-header')->addScriptFile('org.civicrm.hrjob', 'js/common/views.js', 155, 'html-header')->addScriptFile('org.civicrm.hrjob', 'js/jobtabapp.js', 160, 'html-header')->addScriptFile('org.civicrm.hrjob', 'js/jobtabapp/intro/show_controller.js', 160, 'html-header')->addScriptFile('org.civicrm.hrjob', 'js/jobtabapp/intro/show_views.js', 160, 'html-header')->addScriptFile('org.civicrm.hrjob', 'js/jobtabapp/tree/tree_controller.js', 160, 'html-header')->addScriptFile('org.civicrm.hrjob', 'js/jobtabapp/tree/tree_views.js', 160, 'html-header')->addScriptFile('org.civicrm.hrjob', 'js/jobtabapp/summary/summary_controller.js', 160, 'html-header')->addScriptFile('org.civicrm.hrjob', 'js/jobtabapp/summary/summary_views.js', 160, 'html-header'); foreach (array('general', 'funding', 'health', 'hour', 'leave', 'pay', 'pension', 'role') as $module) { CRM_Core_Resources::singleton()->addScriptFile('org.civicrm.hrjob', "js/jobtabapp/{$module}/edit_controller.js", 160, 'html-header')->addScriptFile('org.civicrm.hrjob', "js/jobtabapp/{$module}/edit_views.js", 160, 'html-header')->addScriptFile('org.civicrm.hrjob', "js/jobtabapp/{$module}/summary_views.js", 160, 'html-header'); } $templateDir = CRM_Extension_System::singleton()->getMapper()->keyToBasePath('org.civicrm.hrjob') . '/templates/'; $region = CRM_Core_Region::instance('page-header'); foreach (glob($templateDir . 'CRM/HRJob/Underscore/*.tpl') as $file) { $fileName = substr($file, strlen($templateDir)); $region->add(array('template' => $fileName)); } $region->add(array('template' => 'CRM/Form/validate.tpl')); }
/** * @param CRM_Core_Resources $res */ public function registerResources(CRM_Core_Resources $res) { $modules = self::getAngularModules(); $res->addSettingsFactory(function () use(&$modules) { // TODO optimization; client-side caching return array('resourceUrls' => CRM_Extension_System::singleton()->getMapper()->getActiveModuleUrls(), 'angular' => array('modules' => array_merge(array('ngRoute'), array_keys($modules)))); }); $res->addScriptFile('civicrm', 'packages/bower_components/angular/angular.min.js', 100, 'html-header', FALSE); $res->addScriptFile('civicrm', 'packages/bower_components/angular-route/angular-route.min.js', 110, 'html-header', FALSE); foreach ($modules as $module) { if (!empty($module['css'])) { foreach ($module['css'] as $file) { $res->addStyleFile($module['ext'], $file, self::DEFAULT_MODULE_WEIGHT, 'html-header', TRUE); } } if (!empty($module['js'])) { foreach ($module['js'] as $file) { $res->addScriptFile($module['ext'], $file, self::DEFAULT_MODULE_WEIGHT, 'html-header', TRUE); } } } }
/** * @param array $processor * @throws \CRM_Core_Exception */ public function getByProcessor($processor) { $id = $processor['id']; if (!isset($this->cache[$id])) { if (!isset($this->cache[$id])) { //does this config need to be called? $config = \CRM_Core_Config::singleton(); $ext = \CRM_Extension_System::singleton()->getMapper(); if ($ext->isExtensionKey($processor['class_name'])) { $paymentClass = $ext->keyToClass($processor['class_name'], 'payment'); require_once $ext->classToPath($paymentClass); } else { $paymentClass = 'CRM_Core_' . $processor['class_name']; if (empty($paymentClass)) { throw new \CRM_Core_Exception('no class provided'); } require_once str_replace('_', DIRECTORY_SEPARATOR, $paymentClass) . '.php'; } $this->cache[$id] = new $paymentClass($processor['is_test'] ? 'test' : 'live', $processor); } } return $this->cache[$id]; }
/** * @param int $csID * @param int $ssID * @param int $gID * * @return array * @throws Exception */ public static function details($csID, $ssID = NULL, $gID = NULL) { $error = array(NULL, NULL, NULL); if (!$csID && !$ssID && !$gID) { return $error; } $customSearchID = $csID; $formValues = array(); if ($ssID || $gID) { if ($gID) { $ssID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $gID, 'saved_search_id'); } $formValues = CRM_Contact_BAO_SavedSearch::getFormValues($ssID); $customSearchID = CRM_Utils_Array::value('customSearchID', $formValues); } if (!$customSearchID) { return $error; } // check that the csid exists in the db along with the right file // and implements the right interface $customSearchClass = CRM_Core_OptionGroup::getLabel('custom_search', $customSearchID); if (!$customSearchClass) { return $error; } $ext = CRM_Extension_System::singleton()->getMapper(); if (!$ext->isExtensionKey($customSearchClass)) { $customSearchFile = str_replace('_', DIRECTORY_SEPARATOR, $customSearchClass) . '.php'; } else { $customSearchFile = $ext->keyToPath($customSearchClass); $customSearchClass = $ext->keyToClass($customSearchClass); } $error = (include_once $customSearchFile); if ($error == FALSE) { CRM_Core_Error::fatal('Custom search file: ' . $customSearchFile . ' does not exist. Please verify your custom search settings in CiviCRM administrative panel.'); } return array($customSearchID, $customSearchClass, $formValues); }
/** * @param $customSearchClass * @param $formValues * @param $order */ public static function exportCustom($customSearchClass, $formValues, $order) { $ext = CRM_Extension_System::singleton()->getMapper(); if (!$ext->isExtensionClass($customSearchClass)) { require_once str_replace('_', DIRECTORY_SEPARATOR, $customSearchClass) . '.php'; } else { require_once $ext->classToPath($customSearchClass); } $search = new $customSearchClass($formValues); $includeContactIDs = FALSE; if ($formValues['radio_ts'] == 'ts_sel') { $includeContactIDs = TRUE; } $sql = $search->all(0, 0, $order, $includeContactIDs); $columns = $search->columns(); $header = array_keys($columns); $fields = array_values($columns); $rows = array(); $dao = CRM_Core_DAO::executeQuery($sql); $alterRow = FALSE; if (method_exists($search, 'alterRow')) { $alterRow = TRUE; } while ($dao->fetch()) { $row = array(); foreach ($fields as $field) { $row[$field] = $dao->{$field}; } if ($alterRow) { $search->alterRow($row); } $rows[] = $row; } CRM_Core_Report_Excel::writeCSVFile(self::getExportFileName(), $header, $rows); CRM_Utils_System::civiExit(); }
/** * Use the form name to create the tpl file name. * * @return string */ public function getTemplateFileName() { $ext = CRM_Extension_System::singleton()->getMapper(); if ($ext->isExtensionClass(CRM_Utils_System::getClassName($this))) { $filename = $ext->getTemplateName(CRM_Utils_System::getClassName($this)); $tplname = $ext->getTemplatePath(CRM_Utils_System::getClassName($this)) . DIRECTORY_SEPARATOR . $filename; } else { $tplname = strtr(CRM_Utils_System::getClassName($this), array('_' => DIRECTORY_SEPARATOR, '\\' => DIRECTORY_SEPARATOR)) . '.tpl'; } return $tplname; }
/** * add pages to the controller. Note that the controller does not really care * the order in which the pages are added * * @param object $stateMachine the state machine object * @param int $action the mode in which the state machine is operating * typicaly this will be add/view/edit * * @return void * @access public * */ function addPages(&$stateMachine, $action = CRM_Core_Action::NONE) { $pages = $stateMachine->getPages(); foreach ($pages as $name => $value) { $className = CRM_Utils_Array::value('className', $value, $name); $title = CRM_Utils_Array::value('title', $value); $options = CRM_Utils_Array::value('options', $value); $stateName = CRM_Utils_String::getClassName($className); if (CRM_Utils_Array::value('className', $value)) { $formName = $name; } else { $formName = CRM_Utils_String::getClassName($name); } $ext = CRM_Extension_System::singleton()->getMapper(); if ($ext->isExtensionClass($className)) { require_once $ext->classToPath($className); } else { require_once str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; } ${$stateName} = new $className($stateMachine->find($className), $action, 'post', $formName); if ($title) { ${$stateName}->setTitle($title); } if ($options) { ${$stateName}->setOptions($options); } $this->addPage(${$stateName}); $this->addAction($stateName, new HTML_QuickForm_Action_Direct()); //CRM-6342 -we need kill the reference here, //as we have deprecated reference object creation. unset(${$stateName}); } }
/** * Flush information about loaded modules. */ public function clearModuleList() { CRM_Extension_System::singleton()->getCache()->flush(); CRM_Utils_Hook::singleton(TRUE); CRM_Core_PseudoConstant::getModuleExtensions(TRUE); CRM_Core_Module::getAll(TRUE); }
/** * Class constructor. * * @param $customSearchClass * @param array $formValues * Array of form values imported. * @param array $params * Array of parameters for query. * @param null $returnProperties * @param \const|int $action - action of search basic or advanced. * * @param bool $includeContactIds * @param bool $searchChildGroups * @param string $searchContext * @param null $contextMenu * * @return \CRM_Contact_Selector_Custom */ public function __construct($customSearchClass, $formValues = NULL, $params = NULL, $returnProperties = NULL, $action = CRM_Core_Action::NONE, $includeContactIds = FALSE, $searchChildGroups = TRUE, $searchContext = 'search', $contextMenu = NULL) { $this->_customSearchClass = $customSearchClass; $this->_formValues = $formValues; $this->_includeContactIds = $includeContactIds; $ext = CRM_Extension_System::singleton()->getMapper(); if (!$ext->isExtensionKey($customSearchClass)) { if ($ext->isExtensionClass($customSearchClass)) { $customSearchFile = $ext->classToPath($customSearchClass); require_once $customSearchFile; } else { require_once str_replace('_', DIRECTORY_SEPARATOR, $customSearchClass) . '.php'; } $this->_search = new $customSearchClass($formValues); } else { $fnName = $ext->keyToPath; $customSearchFile = $fnName($customSearchClass, 'search'); $className = $ext->keyToClass($customSearchClass, 'search'); $this->_search = new $className($formValues); } }
/** * Get or set the single instance of CRM_Core_Resources. * * @param CRM_Core_Resources $instance * New copy of the manager. * @return CRM_Core_Resources */ public static function singleton(CRM_Core_Resources $instance = NULL) { if ($instance !== NULL) { self::$_singleton = $instance; } if (self::$_singleton === NULL) { $sys = CRM_Extension_System::singleton(); $cache = new CRM_Utils_Cache_SqlGroup(array('group' => 'js-strings', 'prefetch' => FALSE)); self::$_singleton = new CRM_Core_Resources($sys->getMapper(), $cache, CRM_Core_Config::isUpgradeMode() ? NULL : 'resCacheCode'); } return self::$_singleton; }
/** * Process the form submission. * * * @return void */ public function postProcess() { CRM_Utils_System::flushCache(); if ($this->_action & CRM_Core_Action::DELETE) { try { CRM_Extension_System::singleton()->getManager()->uninstall(array($this->_key)); CRM_Core_Session::setStatus("", ts('Extension Uninstalled'), "success"); } catch (CRM_Extension_Exception_DependencyException $e) { // currently only thrown for payment-processor dependencies CRM_Core_Session::setStatus(ts('Cannot uninstall this extension - there is at least one payment processor using the payment processor type provided by it.'), ts('Uninstall Error'), 'error'); } } if ($this->_action & CRM_Core_Action::ADD) { CRM_Extension_System::singleton()->getManager()->install(array($this->_key)); CRM_Core_Session::setStatus("", ts('Extension Installed'), "success"); } if ($this->_action & CRM_Core_Action::ENABLE) { CRM_Extension_System::singleton()->getManager()->enable(array($this->_key)); CRM_Core_Session::setStatus("", ts('Extension Enabled'), "success"); } if ($this->_action & CRM_Core_Action::DISABLE) { CRM_Extension_System::singleton()->getManager()->disable(array($this->_key)); CRM_Core_Session::setStatus("", ts('Extension Disabled'), "success"); } if ($this->_action & CRM_Core_Action::UPDATE) { $result = civicrm_api('Extension', 'download', array('version' => 3, 'key' => $this->_key)); if (!CRM_Utils_Array::value('is_error', $result, FALSE)) { CRM_Core_Session::setStatus("", ts('Extension Upgraded'), "success"); } else { CRM_Core_Session::setStatus($result['error_message'], ts('Extension Upgrade Failed'), "error"); } } CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1&action=browse')); }