本文整理汇总了PHP中Civi类的典型用法代码示例。如果您正苦于以下问题:PHP Civi类的具体用法?PHP Civi怎么用?PHP Civi使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Civi类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Run upgrade.
*
* @throws \Exception
*/
public function run()
{
// lets get around the time limit issue if possible for upgrades
if (!ini_get('safe_mode')) {
set_time_limit(0);
}
Civi::resources()->addStyleFile('civicrm', 'css/admin.css');
$upgrade = new CRM_Upgrade_Form();
list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
CRM_Utils_System::setTitle(ts('Upgrade CiviCRM to Version %1', array(1 => $latestVer)));
$template = CRM_Core_Smarty::singleton();
$template->assign('pageTitle', ts('Upgrade CiviCRM to Version %1', array(1 => $latestVer)));
$template->assign('cancelURL', CRM_Utils_System::url('civicrm/dashboard', 'reset=1'));
$action = CRM_Utils_Array::value('action', $_REQUEST, 'intro');
switch ($action) {
case 'intro':
$this->runIntro();
break;
case 'begin':
$this->runBegin();
break;
case 'finish':
$this->runFinish();
break;
default:
CRM_Core_Error::fatal(ts('Unrecognized upgrade action'));
}
}
示例2: setPreUpgradeMessage
/**
* Compute any messages which should be displayed before upgrade.
*
* @param string $preUpgradeMessage
* alterable.
* @param $currentVer
* @param $latestVer
*/
public static function setPreUpgradeMessage(&$preUpgradeMessage, $currentVer, $latestVer)
{
if (version_compare(phpversion(), self::MIN_RECOMMENDED_PHP_VER) < 0) {
$preUpgradeMessage .= '<p>' . ts('This webserver is running an outdated version of PHP (%1). It is strongly recommended to upgrade to PHP %2 or later, as older versions can present a security risk.', array(1 => phpversion(), 2 => self::MIN_RECOMMENDED_PHP_VER)) . '</p>';
}
// http://issues.civicrm.org/jira/browse/CRM-13572
// Depending on how the code was upgraded, some sites may still have copies of old
// source files left behind. This is often a forgivable offense, but it's quite
// dangerous for CIVI-SA-2013-001.
global $civicrm_root;
$ofcFile = "{$civicrm_root}/packages/OpenFlashChart/php-ofc-library/ofc_upload_image.php";
if (file_exists($ofcFile)) {
if (@unlink($ofcFile)) {
$preUpgradeMessage .= '<br />' . ts('This system included an outdated, insecure script (%1). The file was automatically deleted.', array(1 => $ofcFile));
} else {
$preUpgradeMessage .= '<br />' . ts('This system includes an outdated, insecure script (%1). Please delete it.', array(1 => $ofcFile));
}
}
if (Civi::settings()->get('enable_innodb_fts')) {
// The FTS indexing feature dynamically manipulates the schema which could
// cause conflicts with other layers that manipulate the schema. The
// simplest thing is to turn it off and back on.
// It may not always be necessary to do this -- but I doubt we're going to test
// systematically in future releases. When it is necessary, one could probably
// ignore the matter and simply run CRM_Core_InnoDBIndexer::fixSchemaDifferences
// after the upgrade. But that's speculative. For now, we'll leave this
// advanced feature in the hands of the sysadmin.
$preUpgradeMessage .= '<br />' . ts('This database uses InnoDB Full Text Search for optimized searching. The upgrade procedure has not been tested with this feature. You should disable (and later re-enable) the feature by navigating to "Administer => System Settings => Miscellaneous".');
}
}
示例3: addAttachment
/**
* Add an ics attachment to the input array.
*
* @param array $attachments
* Reference to array in same format returned from CRM_Core_BAO_File::getEntityFile().
* @param array $contacts
* Array of contacts (attendees).
*
* @return string|null
* Array index of the added attachment in the $attachments array, else NULL.
*/
public function addAttachment(&$attachments, $contacts)
{
// Check preferences setting
if (Civi::settings()->get('activity_assignee_notification_ics')) {
$config =& CRM_Core_Config::singleton();
$this->icsfile = tempnam($config->customFileUploadDir, 'ics');
if ($this->icsfile !== FALSE) {
rename($this->icsfile, $this->icsfile . '.ics');
$this->icsfile .= '.ics';
$icsFileName = basename($this->icsfile);
// get logged in user's primary email
// TODO: Is there a better way to do this?
$organizer = $this->getPrimaryEmail();
$template = CRM_Core_Smarty::singleton();
$template->assign('activity', $this->activity);
$template->assign('organizer', $organizer);
$template->assign('contacts', $contacts);
$template->assign('timezone', date_default_timezone_get());
$calendar = $template->fetch('CRM/Activity/Calendar/ICal.tpl');
if (file_put_contents($this->icsfile, $calendar) !== FALSE) {
if (empty($attachments)) {
$attachments = array();
}
$attachments['activity_ics'] = array('mime_type' => 'text/calendar', 'fileName' => $icsFileName, 'cleanName' => $icsFileName, 'fullPath' => $this->icsfile);
return 'activity_ics';
}
}
}
return NULL;
}
示例4: getMetadata
/**
* WARNING: This interface may change.
*
* This provides information about the setting - similar to the fields concept for DAO information.
* As the setting is serialized code creating validation setting input needs to know the data type
* This also helps move information out of the form layer into the data layer where people can interact with
* it via the API or other mechanisms. In order to keep this consistent it is important the form layer
* also leverages it.
*
* Note that this function should never be called when using the runtime getvalue function. Caching works
* around the expectation it will be called during setting administration
*
* Function is intended for configuration rather than runtime access to settings
*
* The following params will filter the result. If none are passed all settings will be returns
*
* @param array $filters
* @param int $domainID
*
* @return array
* the following information as appropriate for each setting
* - name
* - type
* - default
* - add (CiviCRM version added)
* - is_domain
* - is_contact
* - description
* - help_text
*/
public static function getMetadata($filters = array(), $domainID = NULL)
{
if ($domainID === NULL) {
$domainID = \CRM_Core_Config::domainID();
}
$cache = \Civi::cache('settings');
$cacheString = 'settingsMetadata_' . $domainID . '_';
// the caching into 'All' seems to be a duplicate of caching to
// settingsMetadata__ - I think the reason was to cache all settings as defined & then those altered by a hook
$settingsMetadata = $cache->get($cacheString);
$cached = is_array($settingsMetadata);
if (!$cached) {
$settingsMetadata = $cache->get(self::ALL);
if (empty($settingsMetadata)) {
global $civicrm_root;
$metaDataFolders = array($civicrm_root . '/settings');
\CRM_Utils_Hook::alterSettingsFolders($metaDataFolders);
$settingsMetadata = self::loadSettingsMetaDataFolders($metaDataFolders);
$cache->set(self::ALL, $settingsMetadata);
}
}
\CRM_Utils_Hook::alterSettingsMetaData($settingsMetadata, $domainID, NULL);
if (!$cached) {
$cache->set($cacheString, $settingsMetadata);
}
self::_filterSettingsSpecification($filters, $settingsMetadata);
return $settingsMetadata;
}
示例5: route
/**
* @param array $cxn
* @param string $entity
* @param string $action
* @param array $params
* @return mixed
*/
public static function route($cxn, $entity, $action, $params)
{
$SUPER_PERM = array('administer CiviCRM');
require_once 'api/v3/utils.php';
// FIXME: Shouldn't the X-Forwarded-Proto check be part of CRM_Utils_System::isSSL()?
if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enableSSL') && !CRM_Utils_System::isSSL() && strtolower(CRM_Utils_Array::value('X_FORWARDED_PROTO', CRM_Utils_System::getRequestHeaders())) != 'https') {
return civicrm_api3_create_error('System policy requires HTTPS.');
}
// Note: $cxn and cxnId are authenticated before router is called.
$dao = new CRM_Cxn_DAO_Cxn();
$dao->cxn_id = $cxn['cxnId'];
if (empty($cxn['cxnId']) || !$dao->find(TRUE) || !$dao->cxn_id) {
return civicrm_api3_create_error('Failed to lookup connection authorizations.');
}
if (!$dao->is_active) {
return civicrm_api3_create_error('Connection is inactive.');
}
if (!is_string($entity) || !is_string($action) || !is_array($params)) {
return civicrm_api3_create_error('API parameters are malformed.');
}
if (empty($cxn['perm']['api']) || !is_array($cxn['perm']['api']) || empty($cxn['perm']['grant']) || !(is_array($cxn['perm']['grant']) || is_string($cxn['perm']['grant']))) {
return civicrm_api3_create_error('Connection has no permissions.');
}
$whitelist = \Civi\API\WhitelistRule::createAll($cxn['perm']['api']);
\Civi::service('dispatcher')->addSubscriber(new \Civi\API\Subscriber\WhitelistSubscriber($whitelist));
CRM_Core_Config::singleton()->userPermissionTemp = new CRM_Core_Permission_Temp();
if ($cxn['perm']['grant'] === '*') {
CRM_Core_Config::singleton()->userPermissionTemp->grant($SUPER_PERM);
} else {
CRM_Core_Config::singleton()->userPermissionTemp->grant($cxn['perm']['grant']);
}
$params['check_permissions'] = 'whitelist';
return civicrm_api($entity, $action, $params);
}
示例6: __construct
/**
* @param string $title
* Title of the page.
* @param int $mode
* Mode of the page.
* @param \CRM_Core_Resources|null $res
* Resource manager.
*/
public function __construct($title = NULL, $mode = NULL, $res = NULL)
{
parent::__construct($title, $mode);
$this->res = \CRM_Core_Resources::singleton();
$this->angular = \Civi::service('angular');
$this->region = \CRM_Utils_Request::retrieve('snippet', 'String') ? 'ajax-snippet' : 'html-header';
}
示例7: civicrm_api3_generic_getActions
/**
* Get available api actions.
*
* @param array $apiRequest
*
* @return array
* @throws API_Exception
*/
function civicrm_api3_generic_getActions($apiRequest)
{
civicrm_api3_verify_mandatory($apiRequest, NULL, array('entity'));
$mfp = \Civi::service('magic_function_provider');
$actions = $mfp->getActionNames($apiRequest['version'], $apiRequest['entity']);
return civicrm_api3_create_success($actions, $apiRequest['params'], $apiRequest['entity'], 'getactions');
}
示例8: preProcess
public function preProcess()
{
$this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE);
$this->_system = CRM_Utils_Request::retrieve('system', 'Boolean', $this, FALSE, TRUE);
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'update');
if (isset($action)) {
$this->assign('action', $action);
}
$session = CRM_Core_Session::singleton();
$this->_config = new CRM_Core_DAO();
if ($this->_system) {
if (CRM_Core_Permission::check('administer CiviCRM')) {
$this->_contactID = NULL;
} else {
CRM_Utils_System::fatal('You do not have permission to edit preferences');
}
$this->_config->contact_id = NULL;
} else {
if (!$this->_contactID) {
$this->_contactID = $session->get('userID');
if (!$this->_contactID) {
CRM_Utils_System::fatal('Could not retrieve contact id');
}
$this->set('cid', $this->_contactID);
}
$this->_config->contact_id = $this->_contactID;
}
$settings = Civi::settings();
foreach ($this->_varNames as $groupName => $settingNames) {
foreach ($settingNames as $settingName => $options) {
$this->_config->{$settingName} = $settings->get($settingName);
}
}
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1'));
}
示例9: check
/**
* Check whether the install has run before.
*
* Circa v4.7.betaX, we introduced a new mechanism for tracking installation
* and firing a post-install event. However, it's fairly difficult to test the
* edge-cases directly, so this canary should fire if there are any problems
* in the design/implementation of the installation-tracker.
*
* This should not exist. It should be removed in a future version.
*
* @param \Civi\Core\Event\SystemInstallEvent $event
* @throws \CRM_Core_Exception
*/
public static function check(SystemInstallEvent $event)
{
if (\CRM_Core_DAO::checkTableExists('civicrm_install_canary')) {
throw new \CRM_Core_Exception("Found installation canary. This suggests that something went wrong with tracking installation process. Please post to forum or JIRA.");
}
\Civi::log()->info('Creating canary table');
\CRM_Core_DAO::executeQuery('CREATE TABLE civicrm_install_canary (id int(10) unsigned NOT NULL)');
}
示例10: preProcess
/**
* Obtains the group name from url and sets the title.
*/
public function preProcess()
{
Civi::resources()->addStyleFile('civicrm', 'css/admin.css');
CRM_Utils_System::setTitle(ts('CiviCRM Extensions'));
$destination = CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1');
$destination = urlencode($destination);
$this->assign('destination', $destination);
}
示例11: singleton
/**
* @param bool $fresh
* @return CRM_Utils_QueryFormatter
*/
public static function singleton($fresh = FALSE)
{
if ($fresh || self::$singleton === NULL) {
$mode = Civi::settings()->get('fts_query_mode');
self::$singleton = new CRM_Utils_QueryFormatter($mode);
}
return self::$singleton;
}
示例12: singleton
/**
* @param bool $fresh
* @return CRM_Cxn_CiviCxnHttp
*/
public static function singleton($fresh = FALSE)
{
if (self::$singleton === NULL || $fresh) {
$cache = CRM_Utils_Cache::create(array('name' => 'CiviCxnHttp', 'type' => Civi::settings()->get('debug_enabled') ? 'ArrayCache' : array('SqlGroup', 'ArrayCache'), 'prefetch' => FALSE));
self::$singleton = new CRM_Cxn_CiviCxnHttp($cache);
}
return self::$singleton;
}
示例13: preProcess
/**
* Build all the data structures needed to build the form.
*/
public function preProcess()
{
$cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE);
$this->_searchKey = CRM_Utils_Request::retrieve('key', 'String', $this);
// sort out whether it’s a delete-to-trash, delete-into-oblivion or restore (and let the template know)
$values = $this->controller->exportValues();
$this->_skipUndelete = (CRM_Core_Permission::check('access deleted contacts') and (CRM_Utils_Request::retrieve('skip_undelete', 'Boolean', $this) or CRM_Utils_Array::value('task', $values) == CRM_Contact_Task::DELETE_PERMANENTLY));
$this->_restore = (CRM_Utils_Request::retrieve('restore', 'Boolean', $this) or CRM_Utils_Array::value('task', $values) == CRM_Contact_Task::RESTORE);
if ($this->_restore && !CRM_Core_Permission::check('access deleted contacts')) {
CRM_Core_Error::fatal(ts('You do not have permission to access this contact.'));
} elseif (!CRM_Core_Permission::check('delete contacts')) {
CRM_Core_Error::fatal(ts('You do not have permission to delete this contact.'));
}
$this->assign('trash', Civi::settings()->get('contact_undelete') and !$this->_skipUndelete);
$this->assign('restore', $this->_restore);
if ($this->_restore) {
CRM_Utils_System::setTitle(ts('Restore Contact'));
}
if ($cid) {
if (!CRM_Contact_BAO_Contact_Permission::allow($cid, CRM_Core_Permission::EDIT)) {
CRM_Core_Error::fatal(ts('You do not have permission to delete this contact. Note: you can delete contacts if you can edit them.'));
} elseif (CRM_Contact_BAO_Contact::checkDomainContact($cid)) {
CRM_Core_Error::fatal(ts('This contact is a special one for the contact information associated with the CiviCRM installation for this domain. No one is allowed to delete it because the information is used for special system purposes.'));
}
$this->_contactIds = array($cid);
$this->_single = TRUE;
$this->assign('totalSelectedContacts', 1);
} else {
parent::preProcess();
}
$this->_sharedAddressMessage = $this->get('sharedAddressMessage');
if (!$this->_restore && !$this->_sharedAddressMessage) {
// we check for each contact for shared contact address
$sharedContactList = array();
$sharedAddressCount = 0;
foreach ($this->_contactIds as $contactId) {
// check if a contact that is being deleted has any shared addresses
$sharedAddressMessage = CRM_Core_BAO_Address::setSharedAddressDeleteStatus(NULL, $contactId, TRUE);
if ($sharedAddressMessage['count'] > 0) {
$sharedAddressCount += $sharedAddressMessage['count'];
$sharedContactList = array_merge($sharedContactList, $sharedAddressMessage['contactList']);
}
}
$this->_sharedAddressMessage = array('count' => $sharedAddressCount, 'contactList' => $sharedContactList);
if ($sharedAddressCount > 0) {
if (count($this->_contactIds) > 1) {
// more than one contact deleted
$message = ts('One of the selected contacts has an address record that is shared with 1 other contact.', array('plural' => 'One or more selected contacts have address records which are shared with %count other contacts.', 'count' => $sharedAddressCount));
} else {
// only one contact deleted
$message = ts('This contact has an address record which is shared with 1 other contact.', array('plural' => 'This contact has an address record which is shared with %count other contacts.', 'count' => $sharedAddressCount));
}
CRM_Core_Session::setStatus($message . ' ' . ts('Shared addresses will not be removed or altered but will no longer be shared.'), ts('Shared Addesses Owner'));
}
// set in form controller so that queries are not fired again
$this->set('sharedAddressMessage', $this->_sharedAddressMessage);
}
}
示例14: readActiveConfig
/**
* @return array
*/
public function readActiveConfig()
{
if (!defined('CIVICRM_SETTINGS_PATH') || CIVICRM_SETTINGS_PATH !== $this->settingsFile) {
return array();
}
$paths = is_callable(array('Civi', 'paths')) ? \Civi::paths() : NULL;
$data = array('CMS_DB_DSN' => CIVICRM_UF_DSN, 'CMS_VERSION' => \CRM_Core_Config::singleton()->userSystem->getVersion(), 'CIVI_DB_DSN' => CIVICRM_DSN, 'CIVI_SITE_KEY' => CIVICRM_SITE_KEY, 'CIVI_VERSION' => \CRM_Utils_System::version(), 'CIVI_SETTINGS' => CIVICRM_SETTINGS_PATH, 'CIVI_TEMPLATEC' => \CRM_Core_Config::singleton()->templateCompileDir, 'CIVI_UF' => \CRM_Core_Config::singleton()->userFramework, 'IS_INSTALLED' => '1', 'SITE_TYPE' => 'cv-auto', 'CMS_URL' => $paths ? \Civi::paths()->getUrl('[cms.root]/', 'absolute') : \CRM_Utils_System::languageNegotiationURL(\CRM_Utils_System::baseCMSURL(), FALSE, TRUE), 'CMS_ROOT' => $paths ? \Civi::paths()->getPath('[cms.root]/.') : \CRM_Core_Config::singleton()->userSystem->cmsRootPath(), 'CIVI_CORE' => $paths ? \Civi::paths()->getPath('[civicrm.root]/.') : $GLOBALS['civicrm_root'], 'CIVI_URL' => $paths ? \Civi::paths()->getUrl('[civicrm.root]/', 'absolute') : '', 'CIVI_FILES' => $paths ? \Civi::paths()->getPath('[civicrm.root]/.') : dirname(\CRM_Core_Config::singleton()->templateCompileDir));
return $data;
}
示例15: singleton
/**
* @param bool $fresh
* @return CRM_Core_InnoDBIndexer
*/
public static function singleton($fresh = FALSE)
{
if ($fresh || self::$singleton === NULL) {
$indices = array('civicrm_address' => array(array('street_address', 'city', 'postal_code')), 'civicrm_activity' => array(array('subject', 'details')), 'civicrm_contact' => array(array('sort_name', 'nick_name', 'display_name')), 'civicrm_contribution' => array(array('source', 'amount_level', 'trxn_Id', 'invoice_id')), 'civicrm_email' => array(array('email')), 'civicrm_membership' => array(array('source')), 'civicrm_note' => array(array('subject', 'note')), 'civicrm_participant' => array(array('source', 'fee_level')), 'civicrm_phone' => array(array('phone')), 'civicrm_tag' => array(array('name')));
$active = Civi::settings()->get('enable_innodb_fts');
self::$singleton = new self($active, $indices);
}
return self::$singleton;
}