本文整理汇总了PHP中Tinebase_Core::getTempDir方法的典型用法代码示例。如果您正苦于以下问题:PHP Tinebase_Core::getTempDir方法的具体用法?PHP Tinebase_Core::getTempDir怎么用?PHP Tinebase_Core::getTempDir使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tinebase_Core
的用法示例。
在下文中一共展示了Tinebase_Core::getTempDir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCreateTempFileWithNonUTF8Filename
/**
* testCreateTempFileWithNonUTF8Filename
*
* @see 0008184: files with umlauts in filename cannot be attached with safari
*/
public function testCreateTempFileWithNonUTF8Filename()
{
$filename = file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . 'brokenname.txt');
$path = tempnam(Tinebase_Core::getTempDir(), 'tine_tempfile_test_');
$tempFile = $this->_instance->createTempFile($path, $filename);
$this->assertEquals("_tüt", $tempFile->name);
}
示例2: triggerAsyncEvents
/**
* run multiple async jobs parallel
*/
public static function triggerAsyncEvents($numOfParallels = 5)
{
$cmd = realpath(__DIR__ . "/../../../tine20/tine20.php") . ' --method Tinebase.triggerAsyncEvents';
$cmd = TestServer::assembleCliCommand($cmd);
// start multiple cronruns at the same time
// NOTE: we don't use pnctl as we don't need it here and it's not always available
for ($i = 0; $i < 5; $i++) {
$tempNames[] = $fileName = tempnam(Tinebase_Core::getTempDir(), 'asynctest');
Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Starting async job: ' . $cmd);
$result = exec("{$cmd} > {$fileName} 2> /dev/null &");
}
// wait for processes to complete
for ($i = 0; $i < count($tempNames) * 5; $i++) {
sleep(1);
$allJobsDone = TRUE;
foreach ($tempNames as $fileName) {
$output = file_get_contents($fileName);
$allJobsDone &= (bool) preg_match('/complete.$/m', $output);
}
if ($allJobsDone) {
break;
}
}
// cleanup
foreach ($tempNames as $fileName) {
//echo 'removing ' . $fileName . "\n";
unlink($fileName);
}
if (!$allJobsDone) {
throw new Exception('jobs did not complete');
}
}
示例3: testExportLetter
public function testExportLetter()
{
$filter = new Addressbook_Model_ContactFilter(array(array('field' => 'n_given', 'operator' => 'equals', 'value' => 'Robert')));
$doc = new Addressbook_Export_Doc($filter);
$doc->generate();
$tempfile = tempnam(Tinebase_Core::getTempDir(), __METHOD__ . '_') . '.docx';
$doc->save($tempfile);
$this->assertGreaterThan(0, filesize($tempfile));
}
示例4: _testReadWriteCycleSucks
public function _testReadWriteCycleSucks()
{
PhpWord\Settings::setTempDir(Tinebase_Core::getTempDir());
$source = str_replace('tests/tine20', 'tine20', __DIR__) . '/templates/addressbook_contact_letter.docx';
$phpWord = PhpWord\IOFactory::load($source);
$tempfile = tempnam(Tinebase_Core::getTempDir(), __METHOD__ . '_') . '.docx';
$writer = $phpWord->save($tempfile);
`open {$tempfile}`;
}
示例5: _outputMessagePart
/**
* download message part
*
* @param string $_messageId
* @param string $_partId
* @param string $disposition
* @param boolean $validateImage
*/
protected function _outputMessagePart($_messageId, $_partId = NULL, $disposition = 'attachment', $validateImage = FALSE)
{
$oldMaxExcecutionTime = Tinebase_Core::setExecutionLifeTime(0);
try {
// fetch extracted winmail dat contents
if (strstr($_partId, 'winmail-')) {
$partIndex = explode('winmail-', $_partId);
$partIndex = intval($partIndex[1]);
$files = Felamimail_Controller_Message::getInstance()->extractWinMailDat($_messageId);
$file = $files[$partIndex];
$part = NULL;
$path = Tinebase_Core::getTempDir() . '/winmail/';
$path = $path . $_messageId . '/';
$contentType = mime_content_type($path . $file);
$this->_prepareHeader($file, $contentType);
$stream = fopen($path . $file, 'r');
} else {
// fetch normal attachment
$part = Felamimail_Controller_Message::getInstance()->getMessagePart($_messageId, $_partId);
$contentType = $_partId === NULL ? Felamimail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822 : $part->type;
$filename = $this->_getDownloadFilename($part, $_messageId, $contentType);
if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . ' filename: ' . $filename . ' content type ' . $contentType);
}
if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($part, TRUE));
}
$this->_prepareHeader($filename, $contentType);
$stream = $_partId === NULL ? $part->getRawStream() : $part->getDecodedStream();
}
if ($validateImage) {
$tmpPath = tempnam(Tinebase_Core::getTempDir(), 'tine20_tmp_imgdata');
$tmpFile = fopen($tmpPath, 'w');
stream_copy_to_stream($stream, $tmpFile);
fclose($tmpFile);
// @todo check given mimetype or all images types?
if (!Tinebase_ImageHelper::isImageFile($tmpPath)) {
if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) {
Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Resource is no image file: ' . $filename);
}
} else {
if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Verified ' . $contentType . ' image.');
}
readfile($tmpPath);
}
} else {
fpassthru($stream);
}
fclose($stream);
} catch (Exception $e) {
Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Failed to get message part: ' . $e->getMessage());
}
Tinebase_Core::setExecutionLifeTime($oldMaxExcecutionTime);
exit;
}
示例6: _setupCliConfig
/**
* initializes the config
* - overwrite session_save_path
*/
public function _setupCliConfig()
{
$configData = @(include 'config.inc.php');
if ($configData === false) {
echo 'UNKNOWN STATUS / CONFIG FILE NOT FOUND (include path: ' . get_include_path() . ")\n";
exit(3);
}
$configData['sessiondir'] = Tinebase_Core::getTempDir();
$config = new Zend_Config($configData);
Tinebase_Core::set(Tinebase_Core::CONFIG, $config);
}
示例7: handle
public function handle()
{
try {
Tinebase_Core::initFramework();
} catch (Zend_Session_Exception $exception) {
if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) {
Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' invalid session. Delete session cookie.');
}
Zend_Session::expireSessionCookie();
header('WWW-Authenticate: Basic realm="WebDAV for Tine 2.0"');
header('HTTP/1.1 401 Unauthorized');
return;
}
if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' is CalDav, CardDAV or WebDAV request.');
}
if (empty($_SERVER['PHP_AUTH_USER']) && empty($_SERVER['REMOTE_USER']) && empty($_SERVER['REDIRECT_REMOTE_USER'])) {
header('WWW-Authenticate: Basic realm="WebDav for Tine 2.0"');
header('HTTP/1.1 401 Unauthorized');
return;
}
// when used with (f)cgi no PHP_AUTH variables are available without defining a special rewrite rule
if (!isset($_SERVER['PHP_AUTH_USER'])) {
// $_SERVER["REMOTE_USER"] == "Basic didhfiefdhfu4fjfjdsa34drsdfterrde..."
$basicAuthData = base64_decode(substr(isset($_SERVER["REMOTE_USER"]) ? $_SERVER["REMOTE_USER"] : $_SERVER['REDIRECT_REMOTE_USER'], 6));
list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(":", $basicAuthData);
}
if (Tinebase_Controller::getInstance()->login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'], $_SERVER['REMOTE_ADDR'], 'TineWebDav') !== true) {
header('WWW-Authenticate: Basic realm="CardDav for Tine 2.0"');
header('HTTP/1.1 401 Unauthorized');
return;
}
self::$_server = new Sabre_DAV_Server(new Tinebase_WebDav_Root());
// compute base uri
$request = new Zend_Controller_Request_Http();
self::$_server->setBaseUri($request->getBaseUrl() . '/');
$tempDir = Tinebase_Core::getTempDir();
if (!empty($tempDir)) {
$lockBackend = new Sabre_DAV_Locks_Backend_File($tempDir . '/webdav.lock');
$lockPlugin = new Sabre_DAV_Locks_Plugin($lockBackend);
self::$_server->addPlugin($lockPlugin);
}
$authPlugin = new Sabre_DAV_Auth_Plugin(new Tinebase_WebDav_Auth(), null);
self::$_server->addPlugin($authPlugin);
$aclPlugin = new Sabre_DAVACL_Plugin();
$aclPlugin->defaultUsernamePath = 'principals/users';
$aclPlugin->principalCollectionSet = array($aclPlugin->defaultUsernamePath);
self::$_server->addPlugin($aclPlugin);
self::$_server->addPlugin(new Sabre_CardDAV_Plugin());
self::$_server->addPlugin(new Sabre_CalDAV_Plugin());
self::$_server->addPlugin(new Sabre_CalDAV_Schedule_Plugin());
self::$_server->addPlugin(new Sabre_DAV_Browser_Plugin());
self::$_server->exec();
}
示例8: testExportXls
public function testExportXls()
{
$filter = new Addressbook_Model_ContactFilter(array(array('field' => 'n_given', 'operator' => 'equals', 'value' => 'Robert')));
$export = new Addressbook_Export_Xls($filter);
$xls = $export->generate();
$tempfile = tempnam(Tinebase_Core::getTempDir(), __METHOD__ . '_') . '.xlsx';
// TODO add a save() fn to Tinebase_Export_Spreadsheet_Xls
$xlswriter = PHPExcel_IOFactory::createWriter($xls, 'Excel5');
$xlswriter->setPreCalculateFormulas(FALSE);
$xlswriter->save($tempfile);
$this->assertGreaterThan(0, filesize($tempfile));
}
示例9: downloadConfig
/**
* download config as config file
*
* @param array $data
*/
public function downloadConfig($data)
{
if (!Setup_Core::configFileExists() || Setup_Core::isRegistered(Setup_Core::USER)) {
$data = Zend_Json::decode($data, Zend_Json::TYPE_ARRAY);
$tmpFile = tempnam(Tinebase_Core::getTempDir(), 'tine20_');
Setup_Controller::getInstance()->writeConfigToFile($data, TRUE, $tmpFile);
$configData = file_get_contents($tmpFile);
unlink($tmpFile);
header("Pragma: public");
header("Cache-Control: max-age=0");
header("Content-Disposition: attachment; filename=config.inc.php");
header("Content-Description: PHP File");
header("Content-type: text/plain");
die($configData);
}
}
示例10: getImageInfoFromBlob
/**
* returns image metadata
*
* @param blob $_blob
* @return array
* @throws Tinebase_Exception_UnexpectedValue
*/
public static function getImageInfoFromBlob($_blob)
{
$tmpPath = tempnam(Tinebase_Core::getTempDir(), 'tine20_tmp_gd');
if ($tmpPath === FALSE) {
throw new Tinebase_Exception('Could not generate temporary file.');
}
file_put_contents($tmpPath, $_blob);
$imgInfo = getimagesize($tmpPath);
unlink($tmpPath);
if (!in_array($imgInfo['mime'], array('image/png', 'image/jpeg', 'image/gif'))) {
throw new Tinebase_Exception_UnexpectedValue('given blob does not contain valid image data.');
}
if (!array_key_exists('channels', $imgInfo)) {
Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Uploaded ' . $imgInfo['mime'] . ' image had no channel information. Setting channels to 3.');
$imgInfo['channels'] = 3;
}
return array('width' => $imgInfo[0], 'height' => $imgInfo[1], 'bits' => $imgInfo['bits'], 'channels' => $imgInfo['channels'], 'mime' => $imgInfo['mime'], 'blob' => $_blob);
}
示例11: testExportSimpleDocSheet
public function testExportSimpleDocSheet()
{
// skip tests for php7
// ERROR: PHP Fatal error: Cannot use PhpOffice\PhpWord\Shared\String as String because 'String' is a special
// class name in /usr/local/share/tine20.git/tine20/vendor/phpoffice/phpword/src/PhpWord/TemplateProcessor.php
// on line 23
if (PHP_VERSION_ID >= 70000) {
$this->markTestSkipped('FIXME 0011730: fix doc export for php7');
}
// make sure definition is imported
$definitionFile = __DIR__ . '/../../../../tine20/Calendar/Export/definitions/cal_default_doc_sheet.xml';
$calendarApp = Tinebase_Application::getInstance()->getApplicationByName('Calendar');
Tinebase_ImportExportDefinition::getInstance()->updateOrCreateFromFilename($definitionFile, $calendarApp, 'cal_default_doc_sheet');
// Tinebase_TransactionManager::getInstance()->commitTransaction($this->_transactionId);
// @TODO have some demodata to export here
$filter = new Calendar_Model_EventFilter(array());
$doc = new Calendar_Export_DocSheet($filter);
$doc->generate();
$tempfile = tempnam(Tinebase_Core::getTempDir(), __METHOD__ . '_') . '.docx';
$doc->save($tempfile);
$this->assertGreaterThan(0, filesize($tempfile));
// `open $tempfile`;
}
示例12: testPWReplacements
/**
* test pw replacements
*/
public function testPWReplacements()
{
$config = Tinebase_Core::getConfig();
$logfile = tempnam(Tinebase_Core::getTempDir(), 'testlog');
$writer = new Zend_Log_Writer_Stream($logfile);
$formatter = new Tinebase_Log_Formatter();
$formatter->addReplacement($config->database->password);
$writer->setFormatter($formatter);
$this->_logger->addWriter($writer);
$filter = new Zend_Log_Filter_Priority(5);
$this->_logger->addFilter($filter);
$this->_logger->notice($config->database->password);
$loggerFile = file_get_contents($logfile);
$writer->shutdown();
unlink($logfile);
$this->assertFalse(strpos($loggerFile, $config->database->password), 'pw found!');
$this->assertContains('********', $loggerFile);
if ($config->logger->logruntime || $config->logger->logdifftime) {
$this->assertTrue(preg_match('/' . Tinebase_Core::getUser()->accountLoginName . ' \\d/', $loggerFile) === 1);
} else {
$this->assertContains(Tinebase_Core::getUser()->accountLoginName . ' - ', $loggerFile);
}
}
示例13: _downloadAllAtachements
/**
* download all attachments
*
* @param string $_messageId
*/
protected function _downloadAllAtachements($_messageId)
{
$oldMaxExcecutionTime = Tinebase_Core::setExecutionLifeTime(0);
$ZIPfile = new ZipArchive();
$tmpFile = tempnam(Tinebase_Core::getTempDir(), 'tine20_');
if (strpos($_messageId, '_') !== false) {
list($messageId, $partId) = explode('_', $_messageId);
} else {
$messageId = $_messageId;
$partId = null;
}
if ($ZIPfile->open($tmpFile) === TRUE) {
$attachments = Expressomail_Controller_Message::getInstance()->getAttachments($messageId, $partId);
foreach ($attachments as $attachment) {
$part = Expressomail_Controller_Message::getInstance()->getMessagePart($messageId, $attachment['partId']);
$filename = is_null($part->filename) ? $attachment['filename'] : $part->filename;
if ($part->encoding == Zend_Mime::ENCODING_BASE64) {
$ZIPfile->addFromString(iconv("UTF-8", "ASCII//TRANSLIT", $filename), base64_decode(stream_get_contents($part->getRawStream())));
} else {
$ZIPfile->addFromString(iconv("UTF-8", "ASCII//TRANSLIT", $filename), stream_get_contents($part->getRawStream()));
}
}
$ZIPfile->close();
}
$maxAge = 3600;
header('Cache-Control: private, max-age=' . $maxAge);
header("Expires: " . gmdate('D, d M Y H:i:s', Tinebase_DateTime::now()->addSecond($maxAge)->getTimestamp()) . " GMT");
// overwrite Pragma header from session
header("Pragma: cache");
header('Content-Disposition: attachment; filename="mensagens.zip"');
header("Content-Type: application/zip");
$stream = fopen($tmpFile, 'r');
fpassthru($stream);
fclose($stream);
unlink($tmpFile);
Tinebase_Core::setExecutionLifeTime($oldMaxExcecutionTime);
exit;
}
示例14: _setMailBody
/**
* set mail body
*
* @param Expressomail_mail $_mail
* @param Expressomail_Model_Message $_message
*/
protected function _setMailBody(Expressomail_mail $_mail, Expressomail_Model_Message $_message)
{
if ($_message->content_type == Expressomail_Model_Message::CONTENT_TYPE_HTML) {
// checking embedded images
$embeddedImages = $this->processEmbeddedImagesInHtmlBody($_message->body);
// now checking embedded signature base64 image
$base64Images = $this->processEmbeddedImageSignatureInHtmlBody($_message->body);
//now checking embed images for reply/forward
$embeddedImagesReply = $this->processEmbeddedImagesInHtmlBodyForReply($_message->body);
$cid = array();
if (count($embeddedImagesReply) > 0) {
foreach ($embeddedImagesReply as $index => $embeddedImage) {
$cid[$index] = $_mail->createCid($embeddedImage['messageId']);
$_message->body = str_replace($embeddedImage['match'], 'src="cid:' . $cid[$index] . '"', $_message->body);
}
}
if (count($embeddedImages) > 0) {
$_message->body = str_ireplace('src="index.php?method=Expressomail.showTempImage&tempImageId=', 'src="cid:', $_message->body);
}
if (count($base64Images) > 0) {
// there should be only one image in the signature
$signature_cid = $_mail->createCid($base64Images[0][1]);
$_message->body = preg_replace('/<img id="?user-signature-image-?[0-9]*"? alt="?[^\\"]+"? src="data:image\\/jpeg;base64,[^"]+">/', '<img id="user-signature-image" src="cid:' . $signature_cid . '"/>', $_message->body);
}
$_mail->setBodyHtml(Expressomail_Message::addHtmlMarkup($_message->body));
if (count($embeddedImages) > 0) {
foreach ($embeddedImages as $embeddedImage) {
$file = Tinebase_Core::getTempDir() . '/' . $embeddedImage[1];
$image = file_get_contents($file);
$_mail->createHtmlRelatedAttachment($image, $embeddedImage[1], 'image/jpg', Zend_Mime::DISPOSITION_INLINE, Zend_Mime::ENCODING_BASE64, $embeddedImage[0]);
}
}
if (count($base64Images) > 0) {
// again, there should be only one image in the signature
$image = base64_decode($base64Images[0][1]);
$_mail->createHtmlRelatedAttachment($image, $signature_cid, 'image/jpg', Zend_Mime::DISPOSITION_INLINE, Zend_Mime::ENCODING_BASE64, $base64Images[0][0]);
}
if (count($embeddedImagesReply) > 0) {
foreach ($embeddedImagesReply as $index => $embeddedImage) {
try {
$part = Expressomail_Controller_Message::getInstance()->getMessagePart($embeddedImage['messageId'], $embeddedImage['messagePart']);
$image = base64_decode(stream_get_contents($part->getRawStream()));
$_mail->createHtmlRelatedAttachment($image, $cid[$index], $part->type, Zend_Mime::DISPOSITION_INLINE, Zend_Mime::ENCODING_BASE64, $part->filename);
} catch (Exception $exc) {
}
}
}
if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . $_mail->getBodyHtml(TRUE));
}
}
$plainBodyText = $_message->getPlainTextBody();
$_mail->setBodyText($plainBodyText);
if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . $_mail->getBodyText(TRUE));
}
}
示例15: testSendMessageWithAttachmentWithoutExtension
/**
* testSendMessageWithAttachmentWithoutExtension
*
* @see 0008328: email attachment without file extension is not sent properly
*/
public function testSendMessageWithAttachmentWithoutExtension()
{
$subject = 'attachment test';
$messageToSend = $this->_getMessageData('unittestalias@' . $this->_mailDomain, $subject);
$tempfileName = 'jsontest' . Tinebase_Record_Abstract::generateUID(10);
$tempfilePath = Tinebase_Core::getTempDir() . DIRECTORY_SEPARATOR . $tempfileName;
file_put_contents($tempfilePath, 'some content');
$tempFile = Tinebase_TempFile::getInstance()->createTempFile($tempfilePath, $tempfileName);
$messageToSend['attachments'] = array(array('tempFile' => array('id' => $tempFile->getId())));
$this->_json->saveMessage($messageToSend);
$forwardMessage = $this->_searchForMessageBySubject($subject);
$this->_foldersToClear = array('INBOX', $this->_account->sent_folder);
$fullMessage = $this->_json->getMessage($forwardMessage['id']);
$this->assertTrue(count($fullMessage['attachments']) === 1);
$attachment = $fullMessage['attachments'][0];
$this->assertContains($tempfileName, $attachment['filename'], 'wrong attachment filename: ' . print_r($attachment, TRUE));
$this->assertEquals(16, $attachment['size'], 'wrong attachment size: ' . print_r($attachment, TRUE));
}