/** * Constructs a file cache store object. * * @param Logger $Logger our Logger * @param DateFactory $DateFactory IoC Datefactory * @param string $fileCacheDirectory The absolute path where our files will be stored without trailing '/' * @param string $fileCachePrefixKey A prefix for the cache keys * @param boolean $fileCacheEnabled Flag to determine if caching is enabled * @param string $fileCacheExtension The file extension to use for cache files. */ public function __construct(LoggerInterface $Logger, DateFactory $DateFactory, $fileCacheDirectory, $fileCacheCachePrefixKey = '', $fileCacheEnabled = false, $fileCacheExtension = 'cfcache') { if ($fileCacheEnabled) { // Verify the directory exists and is writable if (!is_writable($fileCacheDirectory) && !@FileSystemUtils::recursiveMkdir($fileCacheDirectory)) { throw new CacheException("Directory '{$fileCacheDirectory}' does not exist or is not writable."); } // Remove any trailing DIRECTORY_SEPARATOR passed in // For example '/home/crowdfusion/filestore/' becomes '/home/crowdfusion/filestore' $fileCacheDirectory = rtrim($fileCacheDirectory, DIRECTORY_SEPARATOR); // Set our vars $this->cachePrefixKey = str_replace(' ', '', $fileCacheCachePrefixKey); $this->Logger = $Logger; $this->DateFactory = $DateFactory; $this->dir = $fileCacheDirectory; $this->enabled = $fileCacheEnabled; $this->fileExtension = $fileCacheExtension; $this->Logger->debug("Set FileStore options:\n" . "\tCachePrefix: {$fileCacheCachePrefixKey}\n" . "\tEnabled: TRUE"); } else { $this->enabled = false; } }
/** * Marks up a string with paragraphs and automatically links any urls. * * This function marks up the output with paragraph tags and auto-links any URLs that are found. * The resulting output is suitable for display in any web-browser, but must have * paragraph and extra html tags removed before it's ready for editing. * * Content is XSS cleaned and stripped of all but a few tags (specified by implementation.) * * @param string $string The HTML string to format * @param string $allowedTags (optional) A comma-separated list of allowed tags. * * @return string A nicely-formatted version of the input text, with automatic paragraphs and urls in place * * @see unAutoParagraph() */ public function autoParagraph($string, $allowedTags = null, $linkUrls = true) { if (is_null($allowedTags)) { $allowedTags = $this->defaultAllowedTags; } if (is_null($this->purifier)) { require_once PATH_SYSTEM . '/vendors/HTMLPurifier.php'; $this->purifier = HTMLPurifier::instance(); FileSystemUtils::recursiveMkdir($this->vendorCacheDirectory . '/purifier/'); } if ($this->injectors == null && $linkUrls) { $this->injectors = array(new CF_HTMLPurifier_Injector_Linkify()); } $purifierConfig = array('Core.Encoding' => $this->charset, 'AutoFormat.AutoParagraph' => true, 'HTML.TidyLevel' => 'none', 'HTML.Allowed' => $allowedTags, 'Cache.SerializerPath' => $this->vendorCacheDirectory); if (!is_null($this->injectors)) { $purifierConfig['AutoFormat.Custom'] = $this->injectors; } $string = $this->purifier->purify($string, $purifierConfig); $string = str_replace("\n\n", '[DBLBR]', $string); $string = str_replace("\n", '<br/>', $string); $string = str_replace('[DBLBR]', "\n\n", $string); // trim links $string = preg_replace_callback("/\\<a\\s+href\\=\"(" . URLUtils::URL_MATCH . ")\"\\>\\1<\\/a\\>/Uix", array($this, 'trimCallback'), $string); // trim all words longer than 60 chars that aren't URLs, ignoring tags if (preg_match_all("/\\S60/", strip_tags(preg_replace('/(\\<(\\/?[^\\>]+)\\>)/', ' $1', $string)), $m)) { foreach ($m[0] as $n) { if (!preg_match("/" . URLUtils::URL_MATCH . "/", $n)) { $string = str_replace($n, trim(substr($n, 0, 60 - 3), '.') . '...', $string); } } } return $string; }