/** * Instanciantes the image converter with a set of filters * * @param array(ezcImageFilter) $filter Filters to add to the image converter * @return void * @throws ezcBaseSettingValueException Error adding the transformation */ public function __construct($filter) { $imageINI = eZINI::instance('image.ini'); // we get an array of handlers, where order of entries in array gives priority // for each entry, we need to check if the matching handler is enabled, and this has to be manual $imageHandlers = $imageINI->variable('ImageConverterSettings', 'ImageConverters'); foreach ($imageHandlers as $imageHandler) { switch ($imageHandler) { case 'ImageMagick': $hasImageMagick = $imageINI->variable('ImageMagick', 'IsEnabled') == 'true'; if ($hasImageMagick) { break 2; } break; // GD2 is required for the image editor // @todo Make the image editor degrade as nicely as possible if GD is not bundled // GD2 is required for the image editor // @todo Make the image editor degrade as nicely as possible if GD is not bundled case 'GD': $hasGD2 = $imageINI->variable('GD', 'IsEnabled') == 'true' && $imageINI->variable('GDSettings', 'HasGD2' == 'true'); if ($hasGD2) { break 2; } break; } } if ($hasImageMagick) { // we need to use the ImageMagick path configured in the image.ini file $executable = $imageINI->variable('ImageMagick', 'Executable'); if (eZSys::osType() == 'win32' && $imageINI->hasVariable('ImageMagick', 'ExecutableWin32')) { $executable = $imageINI->variable('ImageMagick', 'ExecutableWin32'); } else { if (eZSys::osType() == 'mac' && $imageINI->hasVariable('ImageMagick', 'ExecutableMac')) { $executable = $imageINI->variable('ImageMagick', 'ExecutableMac'); } else { if (eZSys::osType() == 'unix' && $imageINI->hasVariable('ImageMagick', 'ExecutableUnix')) { $executable = $imageINI->variable('ImageMagick', 'ExecutableUnix'); } } } if ($imageINI->hasVariable('ImageMagick', 'ExecutablePath') && $imageINI->variable('ImageMagick', 'ExecutablePath')) { $executable = $imageINI->variable('ImageMagick', 'ExecutablePath') . eZSys::fileSeparator() . $executable; } // @todo Remove if ezc indeed do it automatically // if ( eZSys::osType() == 'win32' ) // $executable = "\"$executable\""; $imageHandlerSettings = new ezcImageHandlerSettings('ImageMagick', 'eZIEEzcImageMagickHandler', array('binary' => $executable)); $settings = new ezcImageConverterSettings(array($imageHandlerSettings)); } else { $settings = new ezcImageConverterSettings(array(new ezcImageHandlerSettings('GD', 'eZIEEzcGDHandler'))); } $this->converter = new ezcImageConverter($settings); $mimeType = $imageINI->variable('OutputSettings', 'AllowedOutputFormat'); $this->converter->createTransformation('transformation', $filter, $mimeType); }
function getStore() { $varDirPath = realpath(eZSys::varDirectory()); $store_path = $varDirPath . eZSys::fileSeparator() . 'openid_consumer'; if (!file_exists($store_path) && !mkdir($store_path)) { //throw error exit(0); } $store = new Auth_OpenID_FileStore($store_path); return $store; }
function sPdf2png() { $ini = eZINI::instance('spdf2png.ini'); $this->cacheEnabled = $ini->variable('CacheSettings', 'Cache') == 'enabled'; $this->debugEnabled = $ini->variable('DebugSettings', 'DebugPDF') == 'enabled'; $this->javaExec = $ini->variable('BinarySettings', 'JavaExecutable'); $this->cacheTTL = $ini->variable('CacheSettings', 'TTL'); $fileSep = eZSys::fileSeparator(); $this->fileSep = $fileSep; $this->extensionDir = eZSys::rootDir() . $fileSep . eZExtension::baseDirectory() . $fileSep . 'pdf2png'; //$this->paradoxPDFExec = $this->pdf2pngExtensionDir.$fileSep.'bin'.$fileSep.'paradoxpdf.jar'; $this->tmpDir = eZSys::rootDir() . $fileSep . 'var' . $fileSep . 'cache' . $fileSep . 'public' . $fileSep . 'pdf2png'; }
function parseFile($fileName) { if (!$fileName) { eZDebug::writeError("eztika cannot find the file {$fileName}; skipping", 'eztika class eZMultiParser'); return false; } $originalFileSize = filesize($fileName); $this->writeEzTikaLog('[START] eZMultiParser for File: ' . round($originalFileSize / 1024, 2) . ' KByte ' . $fileName); $binaryINI = eZINI::instance('binaryfile.ini'); $textExtractionTool = $binaryINI->variable('MultiHandlerSettings', 'TextExtractionTool'); $startTime = mktime(); $tmpName = eZSys::cacheDirectory() . eZSys::fileSeparator() . 'eztika_' . md5($startTime) . '.txt'; $handle = fopen($tmpName, "w"); fclose($handle); chmod($tmpName, 0777); $cmd = "{$textExtractionTool} {$fileName} > {$tmpName}"; $this->writeEzTikaLog('exec: ' . $cmd); // perform eztika command exec($cmd, $returnArray, $returnCode); $this->writeEzTikaLog("exec returnCode: {$returnCode}"); $metaData = ''; if (file_exists($tmpName)) { $fp = fopen($tmpName, 'r'); $fileSize = filesize($tmpName); $metaData = fread($fp, $fileSize); fclose($fp); // keep tempfile in debugmode if ($this->DebugKeepTempFiles === true) { $this->writeEzTikaLog('keep tempfile for debugging extracted metadata: ' . $tmpName); } else { $this->writeEzTikaLog('unlink tempfile: ' . $tmpName); unlink($tmpName); } if ($fileSize === false || $fileSize === 0) { $this->writeEzTikaLog("[ERROR] no metadata was extracted! Check if eztika is working correctly"); } else { $this->writeEzTikaLog('metadata read from tempfile ' . round($fileSize / 1024, 2) . ' KByte'); } } else { $this->writeEzTikaLog("[ERROR] no tempfile '{$tmpName}' for eztika output exists,\n check if eztika command is working,\n check if eztika is executeable"); } // write an error message to error.log if no data could be extracted if ($metaData == '' && $originalFileSize > 0) { eZDebug::writeError("eztika can not extract content from binaryfile for searchindex \nexec( {$cmd} )", 'eztika class eZMultiParser'); } $endTime = mktime(); $seconds = $endTime - $startTime; $this->writeEzTikaLog("[END] after {$seconds} s"); return $metaData; }
/** * tmp dir for mail parser * ezvardir / cjw_newsletter/tmp/ * @return string dirname */ public function getTmpDir($createDirIfNotExists = true) { $varDir = eZSys::varDirectory(); // $dir = $varDir . "/cjw_newsletter/tmp/"; $dir = eZDir::path(array($varDir, 'cjw_newsletter', 'tmp')); $fileSep = eZSys::fileSeparator(); $filePath = $dir . $fileSep; if ($createDirIfNotExists === true) { if (!file_exists($filePath)) { eZDir::mkdir($filePath, false, true); } } return $filePath; }
function eZSetupPrvtAreDirAndFilesWritable($dir) { if (!eZDir::isWriteable($dir)) { return FALSE; } // Check if all files within a given directory are writeable $files = eZDir::findSubitems($dir, 'f'); // find only files, skip dirs and symlinks $fileSeparator = eZSys::fileSeparator(); foreach ($files as $file) { if (!eZFile::isWriteable($dir . $fileSeparator . $file)) { return FALSE; } } return TRUE; }
/** * create the dir and filename for the current mailboxItem * * @return array array( 'file_path' => $filePath, * 'file_dir' => $dir, * 'file_name' => $fileName ) */ public function getFilePathArray() { $mailboxItemId = $this->attribute('id'); $mailboxId = $this->attribute('mailbox_id'); $messageId = $this->attribute('message_id'); $messageIdentifier = $this->attribute('message_identifier'); $createTimestamp = $this->attribute('created'); $varDir = eZSys::varDirectory(); $year = date('Y', $createTimestamp); $month = date('m', $createTimestamp); $day = date('d', $createTimestamp); // $dir = $varDir . "/cjw_newsletter/mailbox/$mailboxId/$year/$month/$day/"; $dir = eZDir::path(array($varDir, 'cjw_newsletter', 'mailbox', $mailboxId, $year, $month, $day)); $fileName = "{$mailboxId}-{$year}{$month}{$day}-{$mailboxItemId}.mail"; $fileSep = eZSys::fileSeparator(); $filePath = $dir . $fileSep . $fileName; return array('file_path' => $filePath, 'file_dir' => $dir, 'file_name' => $fileName); }
static function isWriteable( $dirname ) { if ( eZSys::osType() != 'win32' ) return is_writable( $dirname ); /* PHP function is_writable() doesn't work correctly on Windows NT descendants. * So we have to use the following hack on those OSes. */ $tmpfname = $dirname . eZSys::fileSeparator() . "ezsetup_" . md5( microtime() ) . ".tmp"; // try to create temporary file if ( !( $fp = @fopen( $tmpfname, "w" ) ) ) return FALSE; fclose( $fp ); unlink( $tmpfname ); return TRUE; }
function getImportResultFilePath($importId) { $fileSep = eZSys::fileSeparator(); $dir = eZSys::varDirectory() . $fileSep . 'cjw_newsletter' . $fileSep . 'csvimport'; $file = $importId . '-import_result.serialize'; return $dir . $fileSep . $file; }
function convert($manager, $sourceMimeData, &$destinationMimeData, $filters = false) { $argumentList = array(); $executable = $this->Executable; if (eZSys::osType() == 'win32' and $this->ExecutableWin32) { $executable = $this->ExecutableWin32; } else { if (eZSys::osType() == 'mac' and $this->ExecutableMac) { $executable = $this->ExecutableMac; } else { if (eZSys::osType() == 'unix' and $this->ExecutableUnix) { $executable = $this->ExecutableUnix; } } } if ($this->Path) { $executable = $this->Path . eZSys::fileSeparator() . $executable; } if (eZSys::osType() == 'win32') { $executable = "\"{$executable}\""; } $argumentList[] = $executable; if ($this->PreParameters) { $argumentList[] = $this->PreParameters; } $frameRangeParameters = $this->FrameRangeParameters; if ($frameRangeParameters && isset($frameRangeParameters[$sourceMimeData['name']])) { $sourceMimeData['url'] .= $frameRangeParameters[$sourceMimeData['name']]; } $argumentList[] = eZSys::escapeShellArgument($sourceMimeData['url']); $qualityParameters = $this->QualityParameters; if ($qualityParameters and isset($qualityParameters[$destinationMimeData['name']])) { $qualityParameter = $qualityParameters[$destinationMimeData['name']]; $outputQuality = $manager->qualityValue($destinationMimeData['name']); if ($outputQuality) { $qualityArgument = eZSys::createShellArgument($qualityParameter, array('%1' => $outputQuality)); $argumentList[] = $qualityArgument; } } if ($filters !== false) { foreach ($filters as $filterData) { $argumentList[] = $this->textForFilter($filterData); } } $destinationURL = $destinationMimeData['url']; if ($this->UseTypeTag) { $destinationURL = $this->tagForMIMEType($destinationMimeData) . $this->UseTypeTag . $destinationURL; } $argumentList[] = eZSys::escapeShellArgument($destinationURL); if ($this->PostParameters) { $argumentList[] = $this->PostParameters; } $systemString = implode(' ', $argumentList); system($systemString, $returnCode); if ($returnCode == 0) { if (!file_exists($destinationMimeData['url'])) { eZDebug::writeError('Unknown destination file: ' . $destinationMimeData['url'] . " when executing '{$systemString}'", 'eZImageShellHandler(' . $this->HandlerName . ')'); return false; } $this->changeFilePermissions($destinationMimeData['url']); return true; } else { eZDebug::writeWarning("Failed executing: {$systemString}, Error code: {$returnCode}", __METHOD__); return false; } }
function convert($manager, $sourceMimeData, &$destinationMimeData, $filters = false) { $argumentList = array(); $executable = $this->Executable; if (eZSys::osType() == 'win32' and $this->ExecutableWin32) { $executable = $this->ExecutableWin32; } else { if (eZSys::osType() == 'mac' and $this->ExecutableMac) { $executable = $this->ExecutableMac; } else { if (eZSys::osType() == 'unix' and $this->ExecutableUnix) { $executable = $this->ExecutableUnix; } } } if ($this->Path) { $executable = $this->Path . eZSys::fileSeparator() . $executable; } if (eZSys::osType() == 'win32') { $executable = "\"{$executable}\""; } $argumentList[] = $executable; if ($this->PreParameters) { $argumentList[] = $this->PreParameters; } $frameRangeParameters = $this->FrameRangeParameters; if ($frameRangeParameters && isset($frameRangeParameters[$sourceMimeData['name']])) { $sourceMimeData['url'] .= $frameRangeParameters[$sourceMimeData['name']]; } // Issue EZP-21357: // ImageMagick has it's own meta-characters support, hence: // $ convert 'File*.jpg'' ... // Still expand File*.jpg as the shell would do, however, this is only true for the file's basename part and not // for the whole path. $argumentList[] = eZSys::escapeShellArgument($sourceMimeData['dirpath'] . DIRECTORY_SEPARATOR . addcslashes($sourceMimeData['filename'], '~*?[]{}<>')); $qualityParameters = $this->QualityParameters; if ($qualityParameters and isset($qualityParameters[$destinationMimeData['name']])) { $qualityParameter = $qualityParameters[$destinationMimeData['name']]; $outputQuality = $manager->qualityValue($destinationMimeData['name']); if ($outputQuality) { $qualityArgument = eZSys::createShellArgument($qualityParameter, array('%1' => $outputQuality)); $argumentList[] = $qualityArgument; } } if ($filters !== false) { foreach ($filters as $filterData) { $argumentList[] = $this->textForFilter($filterData); } } $destinationURL = $destinationMimeData['url']; if ($this->UseTypeTag) { $destinationURL = $this->tagForMIMEType($destinationMimeData) . $this->UseTypeTag . $destinationURL; } $argumentList[] = eZSys::escapeShellArgument($destinationURL); if ($this->PostParameters) { $argumentList[] = $this->PostParameters; } $systemString = implode(' ', $argumentList); system($systemString, $returnCode); if ($returnCode == 0) { if (!file_exists($destinationMimeData['url'])) { eZDebug::writeError('Unknown destination file: ' . $destinationMimeData['url'] . " when executing '{$systemString}'", 'eZImageShellHandler(' . $this->HandlerName . ')'); return false; } $this->changeFilePermissions($destinationMimeData['url']); return true; } else { eZDebug::writeWarning("Failed executing: {$systemString}, Error code: {$returnCode}", __METHOD__); return false; } }
$cli->error("Could not open package " . $commandItem['name']); } } else { if ($command == 'export') { if (isset($createdPackages[$commandItem['name']])) { $package =& $createdPackages[$commandItem['name']]; } else { $package = eZPackage::fetch($commandItem['name']); } if ($package) { if (isset($commandItem['export-directory'])) { $exportDirectory = $commandItem['export-directory']; if (!file_exists($exportDirectory)) { $cli->warning("The directory " . $cli->style('dir') . $exportDirectory . $cli->style('dir-end') . " does not exist, cannot export package"); } else { $package->exportToArchive($exportDirectory . eZSys::fileSeparator() . $package->exportName()); $cli->output("Package " . $cli->stylize('symbol', $package->attribute('name')) . " exported to directory " . $cli->stylize('dir', $exportDirectory)); } } else { $exportPath = $package->exportToArchive($package->exportName()); $cli->output("Package " . $cli->stylize('symbol', $package->attribute('name')) . " exported to file " . $cli->stylize('file', $exportPath)); } } else { $cli->error("Could not locate package " . $cli->stylize('emphasize', $commandItem['name'])); } } else { if ($command == 'create') { if ($alreadyCreated) { $cli->output(); } $package = eZPackage::create($commandItem['name'], array('summary' => $commandItem['summary']), false, $repositoryID);
/** * Generate text html of a output for preview and sending email * * @see classes/cjwnewslettermail.php getAllOutputFormatTextByContentObjectVersion() * @see modules/newsletter/preview.php * @param unknown_type $editionContentObjectId * @param unknown_type $versionId * @param unknown_type $outputFormat * @param string $siteAccess * @param string $skinName * @param int $forceImageIncludeSettings -1 - use default settings * 1 - force do not render all img to file://settings from newsletterContentArray['html_mail_image_include'] will be used * 0 - force renders all img to file:// * @return array */ static function getOutput($editionContentObjectId, $versionId, $outputFormat, $siteAccess, $skinName = 'default', $forceSettingImageIncludeTo = -1) { if ($skinName == '') { $skinName = 'default'; } $cjwNewsletterIni = eZINI::instance('cjw_newsletter.ini'); $phpCli = $cjwNewsletterIni->variable('NewsletterSettings', 'PhpCli'); $currentHostName = eZSys::hostname(); $wwwDir = eZSys::wwwDir(); //$wwwDir = 'tmp'; $wwwDirString = ''; if ($wwwDir != '') { $wwwDirString = "--www_dir={$wwwDir} "; } $cmd = "\"{$phpCli}\" extension/cjw_newsletter/bin/php/createoutput.php --object_id={$editionContentObjectId} --object_version={$versionId} --output_format_id={$outputFormat} {$wwwDirString}--current_hostname={$currentHostName} --skin_name={$skinName} -s {$siteAccess}"; $fileSep = eZSys::fileSeparator(); $cmd = str_replace('/', $fileSep, $cmd); eZDebug::writeDebug("shell_exec( {$cmd} )", 'newsletter/preview'); // echo "<hr>$cmd<hr>"; $returnValue = shell_exec(escapeshellcmd($cmd)); $newsletterContentArray = unserialize(trim($returnValue)); if (CjwNewsletterEdition::imageIncludeIsEnabled()) { $htmlMailImageInclude = 1; } // forpreview $imageInclude = false; // render file:// if we want to force it // or use setting from $newsletterContentArray['html_mail_image_include'] if ($forceSettingImageIncludeTo === -1 && $newsletterContentArray['html_mail_image_include'] === 1) { $imageInclude = true; } elseif ($forceSettingImageIncludeTo === 1) { $imageInclude = true; } elseif ($forceSettingImageIncludeTo === 0) { // $imageInclude = false; } if ($imageInclude === true) { $newsletterContentArray = CjwNewsletterEdition::prepareImageInclude($newsletterContentArray); } return $newsletterContentArray; }
/** * * @param string $siteAccess * @return object */ function getSiteIniObjectBySiteAccessName($siteAccess) { $iniObject = NULL; // $phpCli = 'php'; $cjwNewsletterIni = eZINI::instance('cjw_newsletter.ini'); $phpCli = $cjwNewsletterIni->variable('NewsletterSettings', 'PhpCli'); $cmd = "\"{$phpCli}\" extension/cjw_newsletter/bin/php/iniloader.php -s {$siteAccess} site.ini"; // for WINDOWS replace / => \ $fileSep = eZSys::fileSeparator(); $cmd = str_replace('/', $fileSep, $cmd); eZDebug::writeDebug("shell_exec( {$cmd} )", 'CjwNewsletterList::getSiteIniObjectBySiteAccessName()'); $returnValue = shell_exec(escapeshellcmd($cmd)); $iniObject = unserialize(trim($returnValue)); return $iniObject; }