/** * Returns the path to the WebDAV temporary directory. * * If the directory does not exist yet, it will be created first. * * @return string * @todo remove or replace with eZ Components functionality */ protected static function tempDirectory() { $tempDir = eZSys::varDirectory() . '/webdav/tmp'; if (!file_exists($tempDir)) { eZDir::mkdir($tempDir, eZDir::directoryPermission(), true); } return $tempDir; }
static function copy( $sourceDirectory, &$destinationDirectory, $asChild = true, $recursive = true, $includeHidden = false, $excludeItems = false ) { if ( !is_dir( $sourceDirectory ) ) { eZDebug::writeError( "Source $sourceDirectory is not a directory, cannot copy from it", __METHOD__ ); return false; } if ( !is_dir( $destinationDirectory ) ) { eZDebug::writeError( "Destination $destinationDirectory is not a directory, cannot copy to it", __METHOD__ ); return false; } if ( $asChild ) { if ( preg_match( "#^.+/([^/]+)$#", $sourceDirectory, $matches ) ) { eZDir::mkdir( $destinationDirectory . '/' . $matches[1], eZDir::directoryPermission(), false ); $destinationDirectory .= '/' . $matches[1]; } } $items = eZDir::findSubitems( $sourceDirectory, 'df', false, $includeHidden, $excludeItems ); $totalItems = $items; while ( count( $items ) > 0 ) { $currentItems = $items; $items = array(); foreach ( $currentItems as $item ) { $fullPath = $sourceDirectory . '/' . $item; if ( is_file( $fullPath ) ) eZFileHandler::copy( $fullPath, $destinationDirectory . '/' . $item ); else if ( is_dir( $fullPath ) ) { eZDir::mkdir( $destinationDirectory . '/' . $item, eZDir::directoryPermission(), false ); $newItems = eZDir::findSubitems( $fullPath, 'df', $item, $includeHidden, $excludeItems ); $items = array_merge( $items, $newItems ); $totalItems = array_merge( $totalItems, $newItems ); unset( $newItems ); } } } // eZDebugSetting::writeNotice( 'lib-ezfile-copy', // "Copied directory $sourceDirectory to destination $destinationDirectory", // 'eZDir::copy' ); return $totalItems; }
/** * Converts xhtml to pdf * * @param $xhtml * @return Binary pdf content or false if error */ public function generatePDF($xhtml) { //check if $tmpdir exists else try to create it if (!eZFileHandler::doExists($this->tmpDir)) { if (!eZDir::mkdir($this->tmpDir, eZDir::directoryPermission(), true)) { eZDebug::writeWarning("ParadoxPDF::generatePDF Error : could not create temporary directory {$this->tmpDir} ", 'ParadoxPDF::generatePDF'); eZLog::write("ParadoxPDF::generatePDF Error : could not create temporary directory {$this->tmpDir} ", 'paradoxpdf.log'); return false; } } elseif (!eZFileHandler::doIsWriteable($this->tmpDir)) { //check if $tmpdir is writable eZDebug::writeWarning("ParadoxPDF::generatePDF Error : please make {$this->tmpDir} writable ", 'ParadoxPDF::generatePDF'); eZLog::write("ParadoxPDF::generatePDF Error : please make {$this->tmpDir} writable ", 'paradoxpdf.log'); return false; } $rand = md5('paradoxpdf' . getmypid() . mt_rand()); $tmpXHTMLFile = eZDir::path(array($this->tmpDir, "{$rand}.xhtml")); $tmpPDFFile = eZDir::path(array($this->tmpDir, "{$rand}.pdf")); //fix relative urls to match ez root directory $xhtml = $this->fixURL($xhtml); eZFile::create($tmpXHTMLFile, false, $xhtml); $pdfContent = ''; //run jar in headless mode $command = $this->javaExec . " -Djava.awt.headless=true"; if ($this->debugEnabled && $this->debugVerbose) { $command .= " -Dxr.util-logging.loggingEnabled=true"; } $command .= " -jar " . $this->paradoxPDFExec . " {$tmpXHTMLFile} {$tmpPDFFile}"; //fix to get all command output $command .= " 2>&1"; //Enter the Matrix exec($command, $output, $returnCode); //Cant trust java return code so we test if a plain pdf file is genereated if (!(eZFileHandler::doExists($tmpPDFFile) && ($this->size = filesize($tmpPDFFile)))) { $this->writeCommandLog($command, $output, false); return false; } $this->writeCommandLog($command, $output, true); $pdfContent = file_get_contents($tmpPDFFile); //cleanup temporary files //if debug enabled preseves the temporary pdf file //else remove all temporary files if (!$this->debugEnabled) { eZFileHandler::unlink($tmpPDFFile); eZFileHandler::unlink($tmpXHTMLFile); } return $pdfContent; }
function unserializeContentObjectAttribute($package, $objectAttribute, $attributeNode) { $fileNode = $attributeNode->getElementsByTagName('binary-file')->item(0); if (!is_object($fileNode) or !$fileNode->hasAttributes()) { return; } $binaryFile = eZBinaryFile::create($objectAttribute->attribute('id'), $objectAttribute->attribute('version')); $sourcePath = $package->simpleFilePath($fileNode->getAttribute('filekey')); if (!file_exists($sourcePath)) { eZDebug::writeError("The file '{$sourcePath}' does not exist, cannot initialize file attribute with it", 'EnhancedeZBinaryFileType::unserializeContentObjectAttribute'); return false; } //include_once( 'lib/ezfile/classes/ezdir.php' ); $ini = eZINI::instance(); $mimeType = $fileNode->getAttribute('mime-type'); list($mimeTypeCategory, $mimeTypeName) = explode('/', $mimeType); $destinationPath = eZSys::storageDirectory() . '/original/' . $mimeTypeCategory . '/'; if (!file_exists($destinationPath)) { $oldumask = umask(0); if (!eZDir::mkdir($destinationPath, eZDir::directoryPermission(), true)) { umask($oldumask); return false; } umask($oldumask); } $basename = basename($fileNode->getAttribute('filename')); while (file_exists($destinationPath . $basename)) { $basename = substr(md5(mt_rand()), 0, 8) . '.' . eZFile::suffix($fileNode->getAttribute('filename')); } //include_once( 'lib/ezfile/classes/ezfilehandler.php' ); eZFileHandler::copy($sourcePath, $destinationPath . $basename); eZDebug::writeNotice('Copied: ' . $sourcePath . ' to: ' . $destinationPath . $basename, 'EnhancedeZBinaryFileType::unserializeContentObjectAttribute()'); $binaryFile->setAttribute('contentobject_attribute_id', $objectAttribute->attribute('id')); $binaryFile->setAttribute('filename', $basename); $binaryFile->setAttribute('original_filename', $fileNode->getAttribute('original-filename')); $binaryFile->setAttribute('mime_type', $fileNode->getAttribute('mime-type')); $binaryFile->store(); // VS-DBFILE + SP DBFile fix require_once 'kernel/classes/ezclusterfilehandler.php'; $fileHandler = eZClusterFileHandler::instance(); $fileHandler->fileStore($destinationPath . $basename, 'binaryfile', true); }
require 'autoload.php'; //require_once( 'extension/mytwitter/lib/oauth/twitterOAuth.php' ); $cli = eZCLI::instance(); $script = eZScript::instance(array('description' => "Twitter credentials registration / validation\n" . "Script to register and validate OAuth credentials for Twitter\n" . "\n" . "extension/mytwitter/lib/setup.php", 'use-session' => false, 'use-modules' => false, 'use-extensions' => true)); $script->startup(); // CLI parameters $options = $script->getOptions("[register][validate:]", "", array('register' => 'generate a registration URL', 'validate' => 'validate the PIN returned by the registration URL')); $script->initialize(); $myTwitterINI = eZINI::instance('mytwitter.ini'); $consumerKey = $myTwitterINI->variable('TwitterSettings', 'ConsumerKey'); $consumerSecret = $myTwitterINI->variable('TwitterSettings', 'ConsumerSecret'); $accessToken = $myTwitterINI->variable('TwitterSettings', 'AccessToken'); $varDir = eZSys::varDirectory(); $myTwitterTmpDir = $varDir . '/mytwitter'; if (!file_exists($myTwitterTmpDir)) { eZDir::mkdir($myTwitterTmpDir, eZDir::directoryPermission(), true); } $noAction = true; $register = isset($options['register']); $noAction = !$register; $pin = false; if ($options['validate']) { $noAction = false; $pin = $options['validate']; } if ($register) { // instantiate a TwitterOAuth object and request a token $oauth = new TwitterOAuth($consumerKey, $consumerSecret); $request = $oauth->getRequestToken(); $request_token = $request["oauth_token"]; $request_token_secret = $request["oauth_token_secret"];