本文整理汇总了PHP中CRM_Utils_File类的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_File类的具体用法?PHP CRM_Utils_File怎么用?PHP CRM_Utils_File使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CRM_Utils_File类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
/**
* @var \Civi\Angular\Manager $angular
*/
//Use our manager instead of the one provided by core
$angular = new Civi\Angular\VolunteerManager(\CRM_Core_Resources::singleton());
$moduleNames = $this->parseModuleNames(\CRM_Utils_Request::retrieve('modules', 'String'), $angular);
switch (\CRM_Utils_Request::retrieve('format', 'String')) {
case 'json':
case '':
$this->send('application/javascript', json_encode($this->getMetadata($moduleNames, $angular)));
break;
case 'js':
$digest = $this->digestJs($angular->getResources($moduleNames, 'js', 'path'));
//Tell crmResource to use our ajax end-point
$digest = str_replace("ajax/angular-modules", "ajax/volunteer-angular-modules", $digest);
$this->send('application/javascript', $digest);
break;
case 'css':
$this->send('text/css', \CRM_Utils_File::concat($angular->getResources($moduleNames, 'css', 'path'), "\n"));
break;
default:
\CRM_Core_Error::fatal("Unrecognized format");
}
\CRM_Utils_System::civiExit();
}
示例2: offlinerecurringcontributions_civicrm_install
/**
* Implements hook_civicrm_install().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install
*/
function offlinerecurringcontributions_civicrm_install()
{
$extensionDir = dirname(__FILE__) . DIRECTORY_SEPARATOR;
$sqlName = $extensionDir . 'sql' . DIRECTORY_SEPARATOR . 'update.sql';
CRM_Utils_File::sourceSQLFile(CIVICRM_DSN, $sqlName);
_offlinerecurringcontributions_civix_civicrm_install();
}
示例3: run
function run()
{
require_once 'CRM/Utils/Request.php';
require_once 'CRM/Core/DAO.php';
$eid = CRM_Utils_Request::retrieve('eid', 'Positive', $this, true);
$fid = CRM_Utils_Request::retrieve('fid', 'Positive', $this, false);
$id = CRM_Utils_Request::retrieve('id', 'Positive', $this, true);
$quest = CRM_Utils_Request::retrieve('quest', 'String', $this);
$action = CRM_Utils_Request::retrieve('action', 'String', $this);
require_once 'CRM/Core/BAO/File.php';
list($path, $mimeType) = CRM_Core_BAO_File::path($id, $eid, null, $quest);
if (!$path) {
CRM_Core_Error::statusBounce('Could not retrieve the file');
}
$buffer = file_get_contents($path);
if (!$buffer) {
CRM_Core_Error::statusBounce('The file is either empty or you do not have permission to retrieve the file');
}
if ($action & CRM_Core_Action::DELETE) {
if (CRM_Utils_Request::retrieve('confirmed', 'Boolean', CRM_Core_DAO::$_nullObject)) {
CRM_Core_BAO_File::delete($id, $eid, $fid);
CRM_Core_Session::setStatus(ts('The attached file has been deleted.'));
$session = CRM_Core_Session::singleton();
$toUrl = $session->popUserContext();
CRM_Utils_System::redirect($toUrl);
} else {
$wrapper = new CRM_Utils_Wrapper();
return $wrapper->run('CRM_Custom_Form_DeleteFile', ts('Domain Information Page'), null);
}
} else {
require_once 'CRM/Utils/File.php';
CRM_Utils_System::download(CRM_Utils_File::cleanFileName(basename($path)), $mimeType, $buffer);
}
}
示例4: run
public function run()
{
$eid = CRM_Utils_Request::retrieve('eid', 'Positive', $this, TRUE);
$fid = CRM_Utils_Request::retrieve('fid', 'Positive', $this, FALSE);
$id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
$quest = CRM_Utils_Request::retrieve('quest', 'String', $this);
$action = CRM_Utils_Request::retrieve('action', 'String', $this);
list($path, $mimeType) = CRM_Core_BAO_File::path($id, $eid, NULL, $quest);
if (!$path) {
CRM_Core_Error::statusBounce('Could not retrieve the file');
}
$buffer = file_get_contents($path);
if (!$buffer) {
CRM_Core_Error::statusBounce('The file is either empty or you do not have permission to retrieve the file');
}
if ($action & CRM_Core_Action::DELETE) {
if (CRM_Utils_Request::retrieve('confirmed', 'Boolean', CRM_Core_DAO::$_nullObject)) {
CRM_Core_BAO_File::deleteFileReferences($id, $eid, $fid);
CRM_Core_Session::setStatus(ts('The attached file has been deleted.'), ts('Complete'), 'success');
$session = CRM_Core_Session::singleton();
$toUrl = $session->popUserContext();
CRM_Utils_System::redirect($toUrl);
}
} else {
CRM_Utils_System::download(CRM_Utils_File::cleanFileName(basename($path)), $mimeType, $buffer);
}
}
示例5: loadSavedSearches
/**
* Load saved search sql files into the DB.
*/
public function loadSavedSearches()
{
$dsn = CRM_Core_Config::singleton()->dsn;
foreach (glob(dirname(__FILE__) . "/SavedSearchDataSets/*.sql") as $file) {
CRM_Utils_File::sourceSQLFile($dsn, $file);
}
}
示例6: civicrm_api3_speakcivi_update_stats
function civicrm_api3_speakcivi_update_stats($params)
{
$config = CRM_Core_Config::singleton();
$sql = file_get_contents(dirname(__FILE__) . '/../../sql/update.sql', true);
CRM_Utils_File::sourceSQLFile($config->dsn, $sql, NULL, true);
return civicrm_api3_create_success(array("query" => $sql), $params);
}
示例7: upload
public static function upload($params)
{
if (!$_FILES) {
throw new CRM_Extension_Exception('Sorry, the file you uploaded was too large or invalid. Code 1', 500);
}
if (empty($_FILES['file']['size'])) {
throw new CRM_Extension_Exception('Sorry, the file you uploaded was too large or invalid. Code 2', 500);
}
$tempFile = $_FILES['file']['tmp_name'];
$originalFilename = CRM_Simplemail_BAO_SimpleMailHelper::cleanFilename($_FILES['file']['name']);
$fileName = CRM_Utils_File::makeFileName(CRM_Simplemail_BAO_SimpleMailHelper::cleanFilename($_FILES['file']['name']));
$dirName = CRM_Simplemail_BAO_SimpleMailHelper::getUploadDirPath(static::DIRECTORY);
// Create the upload directory, if it doesn't already exist
CRM_Utils_File::createDir($dirName);
$file = $dirName . $fileName;
// Move the uploaded file to the upload directory
if (move_uploaded_file($tempFile, $file)) {
$url = CRM_Simplemail_BAO_SimpleMailHelper::getUploadUrl($fileName, static::DIRECTORY);
$databaseId = static::saveToDatabase($params['simplemail_id'], $originalFilename, $url);
$result['values'] = array(array('url' => $url, 'filename' => $originalFilename, 'databaseId' => $databaseId));
return $result;
} else {
throw new CRM_Extension_Exception('Failed to move the uploaded file', 500);
}
}
开发者ID:jaapjansma,项目名称:uk.co.compucorp.civicrm.simplemail,代码行数:25,代码来源:SimpleMailInlineAttachment.php
示例8: 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));
}
示例9: processUpload
/**
* handler for upload requests
*/
static function processUpload()
{
$config = self::getConfig();
global $http_return_code;
$files = array();
if ($_SERVER["REQUEST_METHOD"] == "GET") {
$dir = scandir($config['BASE_DIR']);
foreach ($dir as $file_name) {
//issue - https://github.com/veda-consulting/uk.co.vedaconsulting.mosaico/issues/28
//Change file name to unique by adding hash so every time uploading same image it will create new image name
$file_name = CRM_Utils_File::makeFileName($file_name);
$file_path = $config['BASE_DIR'] . $file_name;
if (is_file($file_path)) {
$size = filesize($file_path);
$file = ["name" => $file_name, "url" => $config['BASE_URL'] . $file_name, "size" => $size];
if (file_exists($config['BASE_DIR'] . $config[THUMBNAILS_DIR] . $file_name)) {
$file["thumbnailUrl"] = $config['BASE_URL'] . $config[THUMBNAILS_URL] . $file_name;
}
$files[] = $file;
}
}
} else {
if (!empty($_FILES)) {
foreach ($_FILES["files"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["files"]["tmp_name"][$key];
$file_name = $_FILES["files"]["name"][$key];
//issue - https://github.com/veda-consulting/uk.co.vedaconsulting.mosaico/issues/28
//Change file name to unique by adding hash so every time uploading same image it will create new image name
$file_name = CRM_Utils_File::makeFileName($file_name);
$file_path = $config['BASE_DIR'] . $file_name;
if (move_uploaded_file($tmp_name, $file_path) === TRUE) {
$size = filesize($file_path);
$image = new Imagick($file_path);
$image->resizeImage($config[THUMBNAIL_WIDTH], $config[THUMBNAIL_HEIGHT], Imagick::FILTER_LANCZOS, 1.0, TRUE);
// $image->writeImage( $config['BASE_DIR'] . $config[ THUMBNAILS_DIR ] . $file_name );
if ($f = fopen($config['BASE_DIR'] . $config[THUMBNAILS_DIR] . $file_name, "w")) {
$image->writeImageFile($f);
}
$image->destroy();
$file = array("name" => $file_name, "url" => $config['BASE_URL'] . $file_name, "size" => $size, "thumbnailUrl" => $config['BASE_URL'] . $config[THUMBNAILS_URL] . $file_name);
$files[] = $file;
} else {
$http_return_code = 500;
return;
}
} else {
$http_return_code = 400;
return;
}
}
}
}
header("Content-Type: application/json; charset=utf-8");
header("Connection: close");
echo json_encode(array("files" => $files));
CRM_Utils_System::civiExit();
}
示例10: eventcalendar_civicrm_uninstall
/**
* Implementation of hook_civicrm_uninstall
*/
function eventcalendar_civicrm_uninstall()
{
$cividiscountRoot = dirname(__FILE__) . DIRECTORY_SEPARATOR;
$cividiscountSQL = $cividiscountRoot . DIRECTORY_SEPARATOR . 'uninstall.sql';
CRM_Utils_File::sourceSQLFile(CIVICRM_DSN, $cividiscountSQL);
// rebuild the menu so our path is picked up
CRM_Core_Invoke::rebuildMenuAndCaches();
//return _eventcalendar_civix_civicrm_uninstall();
}
示例11: __construct
/**
* @param string $repoUrl
* URL of the remote repository.
* @param string $indexPath
* Relative path of the 'index' file within the repository.
* @param string $cacheDir
* Local path in which to cache files.
*/
public function __construct($repoUrl, $indexPath, $cacheDir)
{
$this->repoUrl = $repoUrl;
$this->cacheDir = $cacheDir;
$this->indexPath = empty($indexPath) ? self::SINGLE_FILE_PATH : $indexPath;
if ($cacheDir && !file_exists($cacheDir) && is_dir(dirname($cacheDir)) && is_writable(dirname($cacheDir))) {
CRM_Utils_File::createDir($cacheDir, FALSE);
}
}
示例12: findManyFiles
/**
* Find files in several directories using several filename patterns
*
* @param array $pairs each item is an array(0 => $searchBaseDir, 1 => $filePattern)
* @return array of file paths
*/
static function findManyFiles($pairs)
{
$files = array();
foreach ($pairs as $pair) {
list($dir, $pattern) = $pair;
$files = array_merge($files, CRM_Utils_File::findFiles($dir, $pattern));
}
return $files;
}
示例13: testReportOutput
/**
* @dataProvider dataProvider
*/
public function testReportOutput($reportClass, $inputParams, $dataSet, $expectedOutputCsvFile)
{
$config = CRM_Core_Config::singleton();
CRM_Utils_File::sourceSQLFile($config->dsn, dirname(__FILE__) . "/{$dataSet}");
$reportCsvFile = $this->getReportOutputAsCsv($reportClass, $inputParams);
$reportCsvArray = $this->getArrayFromCsv($reportCsvFile);
$expectedOutputCsvArray = $this->getArrayFromCsv(dirname(__FILE__) . "/{$expectedOutputCsvFile}");
$this->assertCsvArraysEqual($expectedOutputCsvArray, $reportCsvArray);
}
示例14: banking_civicrm_enable
/**
* Implementation of hook_civicrm_enable
*/
function banking_civicrm_enable()
{
//add the required option groups
banking_civicrm_install_options(_banking_options());
// run the update script
$config = CRM_Core_Config::singleton();
$sql = file_get_contents(dirname(__FILE__) . '/sql/upgrade.sql', true);
CRM_Utils_File::sourceSQLFile($config->dsn, $sql, NULL, true);
return _banking_civix_civicrm_enable();
}
示例15: postProcess
function postProcess()
{
$config = CRM_Core_Config::singleton();
$extenDr = $config->extensionsDir;
$sDbScriptsDir = $extenDr . DIRECTORY_SEPARATOR . 'uk.co.vedaconsulting.recurdatafix' . DIRECTORY_SEPARATOR . 'sql' . DIRECTORY_SEPARATOR;
CRM_Utils_File::sourceSQLFile(CIVICRM_DSN, sprintf("%supdate.sql", $sDbScriptsDir));
//CRM_Core_Session::setStatus('Updated table civicrm_recur table with membership id', 'Success', 'info');
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/recurdatafix/create', 'reset=1'));
CRM_Utils_System::civiExit();
}