本文整理汇总了PHP中CRM_Utils_String类的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_String类的具体用法?PHP CRM_Utils_String怎么用?PHP CRM_Utils_String使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CRM_Utils_String类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Perform an upgrade without using the web-frontend
*
* @param bool $enablePrint
*
* @throws Exception
* @return array, with keys:
* - message: string, HTML-ish blob
*/
public function run($enablePrint = TRUE)
{
// lets get around the time limit issue if possible for upgrades
if (!ini_get('safe_mode')) {
set_time_limit(0);
}
$upgrade = new CRM_Upgrade_Form();
list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
if ($error = $upgrade->checkUpgradeableVersion($currentVer, $latestVer)) {
throw new Exception($error);
}
// Disable our SQL triggers
CRM_Core_DAO::dropTriggers();
// CRM-11156
$preUpgradeMessage = NULL;
$upgrade->setPreUpgradeMessage($preUpgradeMessage, $currentVer, $latestVer);
$postUpgradeMessageFile = CRM_Utils_File::tempnam('civicrm-post-upgrade');
$queueRunner = new CRM_Queue_Runner(array('title' => ts('CiviCRM Upgrade Tasks'), 'queue' => CRM_Upgrade_Form::buildQueue($currentVer, $latestVer, $postUpgradeMessageFile)));
$queueResult = $queueRunner->runAll();
if ($queueResult !== TRUE) {
$errorMessage = CRM_Core_Error::formatTextException($queueResult['exception']);
CRM_Core_Error::debug_log_message($errorMessage);
if ($enablePrint) {
print $errorMessage;
}
throw $queueResult['exception'];
// FIXME test
}
CRM_Upgrade_Form::doFinish();
$message = file_get_contents($postUpgradeMessageFile);
return array('latestVer' => $latestVer, 'message' => $message, 'text' => CRM_Utils_String::htmlToText($message));
}
示例2: isTransactional
/**
* Determine if an API request should be treated as transactional
*
* @param \Civi\API\Provider\ProviderInterface $apiProvider
* @param array $apiRequest
* @return bool
*/
public function isTransactional($apiProvider, $apiRequest)
{
if (isset($apiRequest['params']['is_transactional'])) {
return \CRM_Utils_String::strtobool($apiRequest['params']['is_transactional']);
}
return strtolower($apiRequest['action']) == 'create' || strtolower($apiRequest['action']) == 'delete' || strtolower($apiRequest['action']) == 'submit';
}
示例3: mungeCaseType
public static function mungeCaseType($caseType)
{
// trim all spaces from $caseType
$caseType = str_replace('_', ' ', $caseType);
$caseType = CRM_Utils_String::munge(ucwords($caseType), '', 0);
return $caseType;
}
示例4: create
/**
* Takes an associative array and creates a price set object.
*
* @param array $params
* (reference) an assoc array of name/value pairs.
*
* @return CRM_Price_DAO_PriceSet
*/
public static function create(&$params)
{
if (empty($params['id']) && empty($params['name'])) {
$params['name'] = CRM_Utils_String::munge($params['title'], '_', 242);
}
$priceSetID = NULL;
$validatePriceSet = TRUE;
if (!empty($params['extends']) && is_array($params['extends'])) {
if (!array_key_exists(CRM_Core_Component::getComponentID('CiviEvent'), $params['extends']) || !array_key_exists(CRM_Core_Component::getComponentID('CiviMember'), $params['extends'])) {
$validatePriceSet = FALSE;
}
$params['extends'] = CRM_Utils_Array::implodePadded($params['extends']);
} else {
$priceSetID = CRM_Utils_Array::value('id', $params);
}
// CRM-16189
if ($validatePriceSet && !empty($params['financial_type_id'])) {
CRM_Financial_BAO_FinancialAccount::validateFinancialType($params['financial_type_id'], $priceSetID);
}
$priceSetBAO = new CRM_Price_BAO_PriceSet();
$priceSetBAO->copyValues($params);
if (self::eventPriceSetDomainID()) {
$priceSetBAO->domain_id = CRM_Core_Config::domainID();
}
return $priceSetBAO->save();
}
示例5: process
/**
* @param CRM_Core_Form $form
*
* @return array
*/
public static function process(&$form)
{
if ($form->getVar('_surveyId') <= 0) {
return NULL;
}
$tabs = array('main' => array('title' => ts('Main Information'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'questions' => array('title' => ts('Questions'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE), 'results' => array('title' => ts('Results'), 'link' => NULL, 'valid' => FALSE, 'active' => FALSE, 'current' => FALSE));
$surveyID = $form->getVar('_surveyId');
$class = $form->getVar('_name');
$class = CRM_Utils_String::getClassName($class);
$class = strtolower($class);
if (array_key_exists($class, $tabs)) {
$tabs[$class]['current'] = TRUE;
$qfKey = $form->get('qfKey');
if ($qfKey) {
$tabs[$class]['qfKey'] = "&qfKey={$qfKey}";
}
}
if ($surveyID) {
$reset = !empty($_GET['reset']) ? 'reset=1&' : '';
foreach ($tabs as $key => $value) {
if (!isset($tabs[$key]['qfKey'])) {
$tabs[$key]['qfKey'] = NULL;
}
$tabs[$key]['link'] = CRM_Utils_System::url("civicrm/survey/configure/{$key}", "{$reset}action=update&id={$surveyID}{$tabs[$key]['qfKey']}");
$tabs[$key]['active'] = $tabs[$key]['valid'] = TRUE;
}
}
return $tabs;
}
示例6: check
/**
* given a permission string, check for access requirements
*
* @param string $str the permission to check
*
* @return boolean true if yes, else false
* @access public
*/
function check($str)
{
// Generic cms 'administer users' role tranlates to 'administrator' WordPress role
$str = $this->translatePermission($str, 'WordPress', array('administer users' => 'administrator'));
if ($str == CRM_Core_Permission::ALWAYS_DENY_PERMISSION) {
return FALSE;
}
if ($str == CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION) {
return TRUE;
}
// for administrators give them all permissions
if (!function_exists('current_user_can')) {
return TRUE;
}
if (current_user_can('super admin') || current_user_can('administrator')) {
return TRUE;
}
// Make string lowercase and convert spaces into underscore
$str = CRM_Utils_String::munge(strtolower($str));
if (is_user_logged_in()) {
// Check whether the logged in user has the capabilitity
if (current_user_can($str)) {
return TRUE;
}
} else {
//check the capabilities of Anonymous user)
$roleObj = new WP_Roles();
if ($roleObj->get_role('anonymous_user') != NULL && array_key_exists($str, $roleObj->get_role('anonymous_user')->capabilities)) {
return TRUE;
}
}
return FALSE;
}
示例7: getFilePrefix
/**
* @return string
*/
public static function getFilePrefix()
{
if (!self::$filePrefix) {
self::$filePrefix = "test_" . CRM_Utils_String::createRandom(5, CRM_Utils_String::ALPHANUMERIC) . '_';
}
return self::$filePrefix;
}
示例8: id
/**
* Get a unique ID for the request.
*
* This unique ID is assigned to mysql when the connection is opened and is
* available in PHP.
*
* The intent is that it is available for logging purposes and for triggers.
*
* The resulting string is 17 characters long. This consists of 13 characters of uniqid
* and 4 more random characters.
*
* Uniqid is unique to the microsecond - to make it more unique we add 4 more characters
* but stop short of the full 23 character string that a prefix would generate.
*
* It is intended that this string will be saved to log tables so striking a balance between
* uniqueness and length is important. Note that I did check & lining up with byte values
* (e.g 16 characters) does not confer any benefits. Using a CHAR field rather than VARCHAR
* may improve speed, if indexed.
*
* @return string
*/
public static function id()
{
if (!isset(\Civi::$statics[__CLASS__]['id'])) {
\Civi::$statics[__CLASS__]['id'] = uniqid() . CRM_Utils_String::createRandom(CRM_Utils_String::ALPHANUMERIC, 4);
}
return \Civi::$statics[__CLASS__]['id'];
}
示例9: formRule
static function formRule($fields)
{
$errors = array();
require_once 'api/api.php';
$apiRequest = array();
$apiRequest['entity'] = CRM_Utils_String::munge($fields['api_entity']);
$apiRequest['action'] = CRM_Utils_String::munge($fields['api_action']);
$apiRequest['version'] = substr($fields['api_prefix'], -1);
// ie. civicrm_api3
$apiRequest += _civicrm_api_resolve($apiRequest);
// look up function, file, is_generic
if (!$apiRequest['function']) {
$errors['api_action'] = ts('Given API command is not defined.');
}
// CRM-9868- don't allow Enabled (is_active) for jobs that should never be run automatically via execute action or runjobs url
if (($fields['api_action'] == 'process_membership_reminder_date' || $fields['api_action'] == 'update_greeting') && CRM_Utils_Array::value('is_active', $fields) == 1) {
// pass "wiki" as 6th param to docURL2 if you are linking to a page in wiki.civicrm.org
$docLink = CRM_Utils_System::docURL2("Managing Scheduled Jobs", NULL, NULL, NULL, NULL, "wiki");
$errors['is_active'] = ts('You can not save this Scheduled Job as Active with the specified api action (%2). That action should not be run regularly - it should only be run manually for special conditions. %1', array(1 => $docLink, 2 => $fields['api_action']));
}
if (!empty($errors)) {
return $errors;
}
return empty($errors) ? TRUE : $errors;
}
示例10: hrjobcontract_civicrm_uninstall
/**
* Implementation of hook_civicrm_uninstall
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_uninstall
*/
function hrjobcontract_civicrm_uninstall()
{
$subTypeInfo = CRM_Contact_BAO_ContactType::subTypeInfo('Organization');
$sub_type_name = array('Health Insurance Provider', 'Life Insurance Provider');
foreach ($sub_type_name as $sub_type_name) {
$subTypeName = ucfirst(CRM_Utils_String::munge($sub_type_name));
$orid = array_key_exists($subTypeName, $subTypeInfo);
if ($orid) {
$id = $subTypeInfo[$subTypeName]['id'];
CRM_Contact_BAO_ContactType::del($id);
}
}
$jobContractMenu = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'job_contracts', 'id', 'name');
if (!empty($jobContractMenu)) {
CRM_Core_BAO_Navigation::processDelete($jobContractMenu);
}
CRM_Core_DAO::executeQuery("DELETE FROM civicrm_navigation WHERE name IN ('job_contracts', 'import_export_job_contracts', 'jobImport', 'hoursType', 'pay_scale','hours_location', 'hrjc_contact_type', 'hrjc_location', 'hrjc_pay_cycle', 'hrjc_benefit_name', 'hrjc_benefit_type', 'hrjc_deduction_name', 'hrjc_deduction_type', 'hrjc_health_provider', 'hrjc_life_provider', 'hrjc_pension_type', 'hrjc_revision_change_reason')");
CRM_Core_BAO_Navigation::resetNavigation();
//delete custom groups and field
$customGroup = civicrm_api3('CustomGroup', 'get', array('name' => "HRJobContract_Summary"));
$customGroupData = CRM_Utils_Array::first($customGroup['values']);
if (!empty($customGroupData['id'])) {
civicrm_api3('CustomGroup', 'delete', array('id' => $customGroupData['id']));
}
$customGroup = civicrm_api3('CustomGroup', 'get', array('name' => "HRJobContract_Summary"));
$customGroupData = CRM_Utils_Array::first($customGroup['values']);
if (!empty($customGroupData['id'])) {
civicrm_api3('CustomGroup', 'delete', array('id' => $customGroupData['id']));
}
//delete all option group and values
CRM_Core_DAO::executeQuery("DELETE FROM civicrm_option_group WHERE name IN ('job_contracts', 'hoursType', 'pay_scale','hours_location', 'hrjc_contact_type', 'hrjc_location', 'hrjc_pay_cycle', 'hrjc_benefit_name', 'hrjc_benefit_type', 'hrjc_deduction_name', 'hrjc_deduction_type', 'hrjc_health_provider', 'hrjc_life_provider', 'hrjc_pension_type', 'hrjc_revision_change_reason', 'hrjc_contract_type', 'hrjc_level_type', 'hrjc_department', 'hrjc_hours_type', 'hrjc_pay_grade', 'hrjc_health_provider', 'hrjc_life_provider', 'hrjc_location', 'hrjc_pension_type', 'hrjc_region', 'hrjc_pay_scale')");
//delete job contract files to entities relations
CRM_Core_DAO::executeQuery("DELETE FROM civicrm_entity_file WHERE entity_table LIKE 'civicrm_hrjobcontract_%'");
return _hrjobcontract_civix_civicrm_uninstall();
}
示例11: testHtmlToText
function testHtmlToText()
{
foreach ($this->_testInput as $html => $text) {
$output = CRM_Utils_String::htmlToText($html);
$this->assertEquals(trim($output), trim($text), "Text Output did not match for {$html}");
}
}
示例12: postProcess
public function postProcess()
{
$values = $this->exportValues();
// check if EmailTyped matches Email address
$result = CRM_Utils_String::compareStr($this->_email, $values['email_confirm'], TRUE);
$job_id = $this->_job_id;
$queue_id = $this->_queue_id;
$hash = $this->_hash;
$confirmURL = CRM_Utils_System::url("civicrm/mailing/{$this->_type}", "reset=1&jid={$job_id}&qid={$queue_id}&h={$hash}&confirm=1");
$this->assign('confirmURL', $confirmURL);
$session = CRM_Core_Session::singleton();
$session->pushUserContext($confirmURL);
if ($result == TRUE) {
// Email address verified
if (CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_domain($job_id, $queue_id, $hash)) {
CRM_Mailing_Event_BAO_Unsubscribe::send_unsub_response($queue_id, NULL, TRUE, $job_id);
}
$statusMsg = ts('Email: %1 has been successfully opted out', array(1 => $values['email_confirm']));
CRM_Core_Session::setStatus($statusMsg, '', 'success');
} elseif ($result == FALSE) {
// Email address not verified
$statusMsg = ts('The email address: %1 you have entered does not match the email associated with this opt out request.', array(1 => $values['email_confirm']));
CRM_Core_Session::setStatus($statusMsg, '', 'fail');
}
}
示例13: retrieve
function retrieve($caseType)
{
require_once 'CRM/Utils/String.php';
require_once 'CRM/Utils/Array.php';
// trim all spaces from $caseType
$caseType = str_replace('_', ' ', $caseType);
$caseType = CRM_Utils_String::munge(ucwords($caseType), '', 0);
if (!CRM_Utils_Array::value($caseType, self::$_xml)) {
if (!self::$_xml) {
self::$_xml = array();
}
// first check custom templates directory
$fileName = null;
$config = CRM_Core_Config::singleton();
if (isset($config->customTemplateDir) && $config->customTemplateDir) {
// check if the file exists in the custom templates directory
$fileName = implode(DIRECTORY_SEPARATOR, array($config->customTemplateDir, 'CRM', 'Case', 'xml', 'configuration', "{$caseType}.xml"));
}
if (!$fileName || !file_exists($fileName)) {
// check if file exists locally
$fileName = implode(DIRECTORY_SEPARATOR, array(dirname(__FILE__), 'xml', 'configuration', "{$caseType}.xml"));
if (!file_exists($fileName)) {
return false;
}
}
// read xml file
$dom = DomDocument::load($fileName);
$dom->xinclude();
self::$_xml[$caseType] = simplexml_import_dom($dom);
}
return self::$_xml[$caseType];
}
示例14: civicrm_api3_generic_setValue
/**
* params must contain at least id=xx & {one of the fields from getfields}=value
*/
function civicrm_api3_generic_setValue($apiRequest)
{
$entity = $apiRequest['entity'];
$params = $apiRequest['params'];
// we can't use _spec, doesn't work with generic
civicrm_api3_verify_mandatory($params, NULL, array('id', 'field', 'value'));
$id = $params['id'];
if (!is_numeric($id)) {
return civicrm_api3_create_error(ts('Please enter a number'), array('error_code' => 'NaN', 'field' => "id"));
}
$field = CRM_Utils_String::munge($params['field']);
$value = $params['value'];
$fields = civicrm_api($entity, 'getFields', array("version" => 3, "sequential"));
// getfields error, shouldn't happen.
if ($fields['is_error']) {
return $fields;
}
$fields = $fields['values'];
if (!array_key_exists($field, $fields)) {
return civicrm_api3_create_error("Param 'field' ({$field}) is invalid. must be an existing field", array("error_code" => "invalid_field", "fields" => array_keys($fields)));
}
$def = $fields[$field];
if (array_key_exists('required', $def) && empty($value)) {
return civicrm_api3_create_error(ts("This can't be empty, please provide a value"), array("error_code" => "required", "field" => $field));
}
switch ($def['type']) {
case 1:
//int
if (!is_numeric($value)) {
return civicrm_api3_create_error("Param '{$field}' must be a number", array('error_code' => 'NaN'));
}
case 2:
//string
require_once "CRM/Utils/Rule.php";
if (!CRM_Utils_Rule::xssString($value)) {
return civicrm_api3_create_error(ts('Illegal characters in input (potential scripting attack)'), array('error_code' => 'XSS'));
}
if (array_key_exists('maxlength', $def)) {
$value = substr($value, 0, $def['maxlength']);
}
break;
case 16:
//boolean
$value = (bool) $value;
break;
case 4:
//date
//date
default:
return civicrm_api3_create_error("Param '{$field}' is of a type not managed yet. Join the API team and help us implement it", array('error_code' => 'NOT_IMPLEMENTED'));
}
if (CRM_Core_DAO::setFieldValue(_civicrm_api3_get_DAO($entity), $id, $field, $value)) {
$entity = array('id' => $id, $field => $value);
CRM_Utils_Hook::post('edit', $entity, $id, $entity);
return civicrm_api3_create_success($entity);
} else {
return civicrm_api3_create_error("error assigning {$field}={$value} for {$entity} (id={$id})");
}
}
示例15: civicrm_api3_action_schedule_create
/**
* Create a new ActionSchedule.
*
* @param array $params
*
* @return array
*/
function civicrm_api3_action_schedule_create($params)
{
civicrm_api3_verify_one_mandatory($params, NULL, array('start_action_date', 'absolute_date'));
if (!array_key_exists('name', $params) && !array_key_exists('id', $params)) {
$params['name'] = CRM_Utils_String::munge($params['title']);
}
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'ActionSchedule');
}