/** * Returns a database backup zip file to the browser. * * @return null */ public function actionDownloadBackupFile() { $fileName = craft()->request->getRequiredQuery('fileName'); if (($filePath = IOHelper::fileExists(craft()->path->getTempPath() . $fileName . '.zip')) == true) { craft()->request->sendFile(IOHelper::getFileName($filePath), IOHelper::getFileContents($filePath), array('forceDownload' => true)); } }
/** * Downloads a file and cleans up old temporary assets */ public function actionDownloadFile() { // Clean up temp assets files that are more than a day old $fileResults = array(); $files = IOHelper::getFiles(craft()->path->getTempPath(), true); foreach ($files as $file) { $lastModifiedTime = IOHelper::getLastTimeModified($file, true); if (substr(IOHelper::getFileName($file, false, true), 0, 6) === "assets" && DateTimeHelper::currentTimeStamp() - $lastModifiedTime->getTimestamp() >= 86400) { IOHelper::deleteFile($file); } } // Sort out the file we want to download $id = craft()->request->getParam('id'); $criteria = craft()->elements->getCriteria(ElementType::Asset); $criteria->id = $id; $asset = $criteria->first(); if ($asset) { // Get a local copy of the file $sourceType = craft()->assetSources->getSourceTypeById($asset->sourceId); $localCopy = $sourceType->getLocalCopy($asset); // Send it to the browser craft()->request->sendFile($asset->filename, IOHelper::getFileContents($localCopy), array('forceDownload' => true)); craft()->end(); } }
/** * Download zipfile. * * @param array $files * @param string $filename * * @return string */ public function download($files, $filename) { // Get assets $criteria = craft()->elements->getCriteria(ElementType::Asset); $criteria->id = $files; $criteria->limit = null; $assets = $criteria->find(); // Set destination zip $destZip = craft()->path->getTempPath() . $filename . '_' . time() . '.zip'; // Create zip $zip = new \ZipArchive(); // Open zip if ($zip->open($destZip, $zip::CREATE) === true) { // Loop through assets foreach ($assets as $asset) { // Get asset source $source = $asset->getSource(); // Get asset source type $sourceType = $source->getSourceType(); // Get asset file $file = $sourceType->getLocalCopy($asset); // Add to zip $zip->addFromString($asset->filename, IOHelper::getFileContents($file)); // Remove the file IOHelper::deleteFile($file); } // Close zip $zip->close(); // Return zip destination return $destZip; } // Something went wrong throw new Exception(Craft::t('Failed to generate the zipfile')); }
/** * Get the sections of the CP. * * @return array */ public function nav($iconSize = 32) { $nav['dashboard'] = array('label' => Craft::t('Dashboard'), 'icon' => 'gauge'); if (craft()->sections->getTotalEditableSections()) { $nav['entries'] = array('label' => Craft::t('Entries'), 'icon' => 'section'); } $globals = craft()->globals->getEditableSets(); if ($globals) { $nav['globals'] = array('label' => Craft::t('Globals'), 'url' => 'globals/' . $globals[0]->handle, 'icon' => 'globe'); } if (craft()->categories->getEditableGroupIds()) { $nav['categories'] = array('label' => Craft::t('Categories'), 'icon' => 'categories'); } if (craft()->assetSources->getTotalViewableSources()) { $nav['assets'] = array('label' => Craft::t('Assets'), 'icon' => 'assets'); } if (craft()->getEdition() == Craft::Pro && craft()->userSession->checkPermission('editUsers')) { $nav['users'] = array('label' => Craft::t('Users'), 'icon' => 'users'); } // Add any Plugin nav items $plugins = craft()->plugins->getPlugins(); foreach ($plugins as $plugin) { if ($plugin->hasCpSection()) { $pluginHandle = $plugin->getClassHandle(); if (craft()->userSession->checkPermission('accessPlugin-' . $pluginHandle)) { $lcHandle = StringHelper::toLowerCase($pluginHandle); $iconPath = craft()->path->getPluginsPath() . $lcHandle . '/resources/icon-mask.svg'; if (IOHelper::fileExists($iconPath)) { $iconSvg = IOHelper::getFileContents($iconPath); } else { $iconSvg = false; } $nav[$lcHandle] = array('label' => $plugin->getName(), 'iconSvg' => $iconSvg); } } } if (craft()->userSession->isAdmin()) { $nav['settings'] = array('label' => Craft::t('Settings'), 'icon' => 'settings'); } // Allow plugins to modify the nav craft()->plugins->call('modifyCpNav', array(&$nav)); // Figure out which item is selected, and normalize the items $firstSegment = craft()->request->getSegment(1); if ($firstSegment == 'myaccount') { $firstSegment = 'users'; } foreach ($nav as $handle => &$item) { if (is_string($item)) { $item = array('label' => $item); } $item['sel'] = $handle == $firstSegment; if (isset($item['url'])) { $item['url'] = UrlHelper::getUrl($item['url']); } else { $item['url'] = UrlHelper::getUrl($handle); } } return $nav; }
/** * Gets the source code of a template. * * @param string $name The name of the template to load, or a StringTemplate object. * @return string The template source code. */ public function getSource($name) { if (is_string($name)) { return IOHelper::getFileContents(craft()->templates->findTemplate($name)); } else { return $name->template; } }
/** * @param $fileName * * @return array|bool|string * * @throws Exception */ private function getFileContents($fileName) { $filePath = craft()->path->getLogPath() . $fileName; if (IOHelper::fileExists($filePath) === false) { $message = sprintf('Requested logfile "%s" does not seem to exist', $fileName); throw new Exception($message); } else { return IOHelper::getFileContents($filePath); } }
/** * Set our location based on contents of filename * * @return String */ public function getContents() { if ($this->_contents === null) { $this->_contents = IOHelper::getFileContents($this->filenamePath); if ($this->_contents === false) { throw new Exception('Minimee could not get local asset: ' . $this->filenamePath); } } return $this->_contents; }
/** * Download zip. */ public function actionDownload() { // Get wanted filename $filename = craft()->request->getRequiredParam('filename'); // Get file id's $files = craft()->request->getRequiredParam('files'); // Generate zipfile $zipfile = craft()->zipAssets->download($files, $filename); // Download it craft()->request->sendFile(IOHelper::getFileName($zipfile), IOHelper::getFileContents($zipfile), array('forceDownload' => true)); }
/** * Gets the source code of a template. * * @param string $name The name of the template to load, or a StringTemplate object. * * @throws Exception * @return string The template source code. */ public function getSource($name) { if (is_string($name)) { $template = $this->_findTemplate($name); if (IOHelper::isReadable($template)) { return IOHelper::getFileContents($template); } else { throw new Exception(Craft::t('Tried to read the template at {path}, but could not. Check the permissions.', array('path' => $template))); } } else { return $name->template; } }
/** * @param $view * @param $data * * @return mixed */ protected function render($view, $data) { if (!craft()->isConsole() && !craft()->request->isResourceRequest() && !craft()->request->isAjaxRequest() && craft()->config->get('devMode') && in_array(HeaderHelper::getMimeType(), array('text/html', 'application/xhtml+xml'))) { if (($userAgent = craft()->request->getUserAgent()) !== null && preg_match('/msie [5-9]/i', $userAgent)) { echo '<script type="text/javascript">'; echo IOHelper::getFileContents(IOHelper::getFolderName(__FILE__) . '/../vendors/console-normalizer/normalizeconsole.min.js'); echo "</script>\n"; } else { $viewFile = craft()->path->getCpTemplatesPath() . 'logging/' . $view . '-firebug.php'; include craft()->findLocalizedFile($viewFile, 'en'); } } }
/** * @param $filePath * * @throws Exception */ public function restore($filePath) { if (!IOHelper::fileExists($filePath)) { throw new Exception(Craft::t('Could not find the SQL file to restore: {filePath}', array('filePath' => $filePath))); } $this->_nukeDb(); $sql = IOHelper::getFileContents($filePath, true); array_walk($sql, array($this, 'trimValue')); $sql = array_filter($sql); $statements = $this->_buildSQLStatements($sql); foreach ($statements as $statement) { Craft::log('Executing SQL statement: ' . $statement); $command = craft()->db->createCommand($statement); $command->execute(); } }
/** * Downloads an import file. * * @throws HttpException If not found */ public function actionDownload() { // Get history id $history = craft()->request->getParam('id'); // Get history $model = Import_HistoryRecord::model()->findById($history); // Get filepath $path = craft()->path->getStoragePath() . 'import/' . $history . '/' . $model->file; // Check if file exists if (file_exists($path)) { // Send the file to the browser craft()->request->sendFile($model->file, IOHelper::getFileContents($path), array('forceDownload' => true)); } // Not found, = 404 throw new HttpException(404); }
/** * Loads an image from a file system path. * * @param string $path * * @throws Exception * @return Image */ public function loadImage($path) { if (!IOHelper::fileExists($path)) { throw new Exception(Craft::t('No file exists at the path “{path}”', array('path' => $path))); } list($width, $height) = ImageHelper::getImageSize($path); $svg = IOHelper::getFileContents($path); // If the size is defined by viewbox only, add in width and height attributes if (!preg_match(static::SVG_WIDTH_RE, $svg) && preg_match(static::SVG_HEIGHT_RE, $svg)) { $svg = preg_replace(static::SVG_TAG_RE, "<svg width=\"{$width}px\" height=\"{$height}px\" ", $svg); } $this->_height = $height; $this->_width = $width; $this->_svgContent = $svg; return $this; }
public function getTemplateFiles() { $folderEmpty = true; if (IOHelper::isFolderEmpty(craft()->path->getPluginsPath() . 'formbuilder2/templates/email/layouts')) { throw new HttpException(404, Craft::t('Looks like you don\'t have any templates in your email/layouts folder.')); } else { $folderEmpty = false; } $fileList = IOHelper::getFolderContents(craft()->path->getPluginsPath() . 'formbuilder2/templates/email/layouts'); $files = []; $filesModel = []; if (!$folderEmpty) { foreach ($fileList as $key => $file) { $files[$key] = ['fileName' => IOHelper::getFileName($file, false), 'fileOriginalName' => IOHelper::getFileName($file), 'fileNameCleaned' => IOHelper::cleanFilename(IOHelper::getFileName($file, false)), 'fileExtension' => IOHelper::getExtension($file), 'filePath' => $file, 'fileContents' => IOHelper::getFileContents($file)]; $filesModel[] = FormBuilder2_FileModel::populateModel($files[$key]); } } return $filesModel; }
public function serveAsset(array $options = array()) { if (isset($options['id'])) { if (!$this->_asset or $this->_asset->id != $options['id'] or !$this->_asset instanceof AssetFileModel) { $this->_asset = craft()->assets->getFileById($options['id']); if (!$this->_asset) { throw new Exception(Craft::t("Unable to find asset")); } } $sendFile = false; if ($this->_asset->source->type == 'Local') { $sourcePath = $this->_asset->source->sourceType->getBasePath(); $folderPath = $this->_asset->getFolder()->path; $path = $sourcePath . $folderPath . $this->_asset->filename; if (IOHelper::fileExists($path)) { $content = IOHelper::getFileContents($path); $sendFile = true; } } else { $path = $this->_asset->url; $client = new \Guzzle\Http\Client(); $response = $client->get($this->_asset->url)->send(); if ($response->isSuccessful()) { $content = $response->getBody(); $sendFile = true; } } if ($sendFile) { if (isset($options['forceDownload']) and !$options['forceDownload']) { $extraParams = array('forceDownload' => false); } else { $extraParams = array('forceDownload' => true); } craft()->request->sendFile($path, $content, $extraParams); } else { throw new Exception(Craft::t("Unable to serve file")); } } }
public function actionDownload() { // Get wanted filename $source_id = craft()->request->getRequiredPost('assetsSource'); if ($source_id == 'all') { $source_name = 'All Sources'; $source_ids = craft()->downloadAssets->getSourceIds(); } else { $source = craft()->assetSources->getSourceById($source_id); $source_name = $source->name; $source_ids = array($source_id); } // Get assets $criteria = craft()->elements->getCriteria(ElementType::Asset); $criteria->sourceId = $source_ids; $criteria->limit = null; $assets = $criteria->find(); // Get filename $filename = 'craftAssetDownload_' . $this->slugify($source_name); // Create zip $zip = new \ZipArchive(); $zipfile = craft()->path->getTempPath() . $filename . '_' . time() . '.zip'; // Open zip if ($zip->open($zipfile, $zip::CREATE) === true) { // Loop through assets foreach ($assets as $asset) { // Get asset path $source = craft()->assetSources->getSourceById($asset->sourceId); // Add asset to zip $zip->addFile($source->settings['path'] . $asset->filename, $asset->filename); } // Close zip $zip->close(); // Download zip craft()->request->sendFile(IOHelper::getFileName($zipfile), IOHelper::getFileContents($zipfile), array('forceDownload' => true)); } // If not redirected, something went wrong throw new Exception(Craft::t('Failed to generate the zipfile')); }
public function actionLogs() { craft()->config->maxPowerCaptain(); if (IOHelper::folderExists(craft()->path->getLogPath())) { $dateTimePattern = '/^[0-9]{4}\\/[0-9]{2}\\/[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/'; $logEntries = array(); $currentLogFileName = 'feedme.log'; $currentFullPath = craft()->path->getLogPath() . $currentLogFileName; if (IOHelper::fileExists($currentFullPath)) { // Split the log file's contents up into arrays of individual logs, where each item is an array of // the lines of that log. $contents = IOHelper::getFileContents(craft()->path->getLogPath() . $currentLogFileName); $requests = explode('******************************************************************************************************', $contents); foreach ($requests as $request) { $logChunks = preg_split('/^(\\d{4}\\/\\d{2}\\/\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(.*?)\\] \\[(.*?)\\] /m', $request, null, PREG_SPLIT_DELIM_CAPTURE); // Ignore the first chunk array_shift($logChunks); // Loop through them $totalChunks = count($logChunks); for ($i = 0; $i < $totalChunks; $i += 4) { $logEntryModel = new LogEntryModel(); $logEntryModel->dateTime = DateTime::createFromFormat('Y/m/d H:i:s', $logChunks[$i]); $logEntryModel->level = $logChunks[$i + 1]; $logEntryModel->category = $logChunks[$i + 2]; $message = $logChunks[$i + 3]; $rowContents = explode("\n", $message); // This is a non-devMode log entry. $logEntryModel->message = str_replace('[Forced]', '', $rowContents[0]); // And save the log entry. $logEntries[] = $logEntryModel; } } } // Put these logs at the top $logEntries = array_reverse($logEntries); $this->renderTemplate('feedme/logs/index', array('logEntries' => $logEntries)); } }
/** * Downloads an import file. * * @throws HttpException If not found */ public function actionDownload() { // Get history id $history = craft()->request->getParam('id'); // Get history $model = Import_HistoryRecord::model()->findById($history); // Get filepath $path = craft()->path->getStoragePath() . 'import/' . $history . '/' . $model->file; // Check if file exists if (file_exists($path)) { craft()->request->sendFile($model->file, IOHelper::getFileContents($path), array('forceDownload' => true)); } // OR get file from cloud $asset = craft()->assets->getFileById($model->file); if ($asset) { $source = $asset->getSource(); $sourceType = $source->getSourceType(); $file = $sourceType->getLocalCopy($asset); // Send the file to the browser craft()->request->sendFile($asset->filename, IOHelper::getFileContents($file), array('forceDownload' => true)); } // Not found, = 404 throw new HttpException(404); }
/** * @param bool $array * * @return mixed */ public function getContents($array = false) { if ($array) { if (!$this->_arrayContents) { $this->_arrayContents = IOHelper::getFileContents($this->getRealPath(), $array); } return $this->_arrayContents; } else { if (!$this->_stringContents) { $this->_stringContents = IOHelper::getFileContents($this->getRealPath(), $array); } return $this->_stringContents; } }
/** * Returns the Redactor config JS used by this field. * * @return string */ private function _getConfigJs() { if ($this->getSettings()->configFile) { $configPath = craft()->path->getConfigPath() . 'redactor/' . $this->getSettings()->configFile; $js = IOHelper::getFileContents($configPath); } if (empty($js)) { $js = '{}'; } return $js; }
/** * Get icon path for a given extension * * @param $ext * * @return string */ private function _getIconPath($ext) { $sourceIconPath = craft()->path->getResourcesPath() . 'images/file.svg'; $extLength = mb_strlen($ext); if ($extLength > 5) { // Too long; just use the blank file icon return $sourceIconPath; } // See if the icon already exists $iconPath = craft()->path->getAssetsIconsPath() . StringHelper::toLowerCase($ext) . '.svg'; if (IOHelper::fileExists($iconPath)) { return $iconPath; } // Create a new one $svgContents = IOHelper::getFileContents($sourceIconPath); $textSize = $extLength <= 3 ? '26' : ($extLength == 4 ? '22' : '18'); $textNode = '<text x="50" y="73" text-anchor="middle" font-family="sans-serif" fill="#8F98A3" ' . 'font-size="' . $textSize . '">' . StringHelper::toUpperCase($ext) . '</text>'; $svgContents = str_replace('<!-- EXT -->', $textNode, $svgContents); IOHelper::writeToFile($iconPath, $svgContents); return $iconPath; }
/** * Sends a resource back to the browser. * * @param string $path * @throws HttpException */ public function sendResource($path) { if (PathHelper::ensurePathIsContained($path) === false) { throw new HttpException(403); } $path = $this->getResourcePath($path); if ($path === false || !IOHelper::fileExists($path)) { throw new HttpException(404); } // If there is a timestamp and HTTP_IF_MODIFIED_SINCE exists, check the timestamp against requested file's last modified date. // If the last modified date is less than the timestamp, return a 304 not modified and let the browser serve it from cache. $timestamp = craft()->request->getParam('d', null); $fetchContent = true; if ($timestamp !== null && array_key_exists('HTTP_IF_MODIFIED_SINCE', $_SERVER)) { $requestDate = DateTime::createFromFormat('U', $timestamp); $lastModifiedFileDate = IOHelper::getLastTimeModified($path); if ($lastModifiedFileDate && $lastModifiedFileDate <= $requestDate) { header('HTTP/1.1 304 Not Modified'); $fetchContent = false; $content = ''; } } if ($fetchContent) { // Note that $content may be empty -- they could be requesting a blank text file or something. // It doens't matter. No need to throw a 404. $content = IOHelper::getFileContents($path); } // Normalize URLs in CSS files $mimeType = IOHelper::getMimeTypeByExtension($path); if (strpos($mimeType, 'css') !== false) { $content = preg_replace_callback('/(url\\(([\'"]?))(.+?)(\\2\\))/', array(&$this, '_normalizeCssUrl'), $content); } if (!craft()->config->get('useXSendFile')) { $options['forceDownload'] = false; if (craft()->request->getQuery($this->dateParam)) { $options['cache'] = true; } craft()->request->sendFile($path, $content, $options); } else { craft()->request->xSendFile($path); } exit(1); }
/** * Open file and parse translate tags. * * @param string $path * @param string $file * @param ElementCriteriaModel $criteria * * @return array */ protected function _parseFile($path, $file, ElementCriteriaModel $criteria) { // Collect matches in file $occurences = array(); // Get file contents $contents = IOHelper::getFileContents($file); // Get extension $extension = IOHelper::getExtension($file); // Get matches per extension foreach ($this->_expressions[$extension] as $regex) { // Match translation functions if (preg_match_all($regex, $contents, $matches)) { // Collect foreach ($matches[2] as $original) { // Translate $translation = Craft::t($original, array(), null, $criteria->locale); // Show translation in textfield $field = craft()->templates->render('_includes/forms/text', array('id' => ElementHelper::createSlug($original), 'name' => 'translation[' . $original . ']', 'value' => $translation, 'placeholder' => $translation)); // Fill element with translation data $element = TranslateModel::populateModel(array('id' => ElementHelper::createSlug($original), 'original' => $original, 'translation' => $translation, 'source' => $path, 'file' => $file, 'locale' => $criteria->locale, 'field' => $field)); // If searching, only return matches if ($criteria->search && !stristr($element->original, $criteria->search) && !stristr($element->translation, $criteria->search)) { continue; } // If wanting one status, ditch the rest if ($criteria->status && $criteria->status != $element->getStatus()) { continue; } // Collect in array $occurences[$original] = $element; } } } // Return occurences return $occurences; }
/** * Returns the size of an image based on its file path. * * @param string $filePath The path to the image * * @return array [$width, $height] */ public static function getImageSize($filePath) { if (IOHelper::getExtension($filePath) == 'svg') { $svg = IOHelper::getFileContents($filePath); return static::parseSvgSize($svg); } else { $image = craft()->images->loadImage($filePath); return array($image->getWidth(), $image->getHeight()); } }
/** * @inheritDoc IZip::add() * * @param string $sourceZip * @param string $pathToAdd * @param string $basePath * @param null $pathPrefix * * @return bool */ public function add($sourceZip, $pathToAdd, $basePath, $pathPrefix = null) { $zip = new \ZipArchive(); $zipContents = $zip->open($sourceZip); if ($zipContents !== true) { Craft::log('Unable to open zip file: ' . $sourceZip, LogLevel::Error); return false; } if (IOHelper::fileExists($pathToAdd)) { $folderContents = array($pathToAdd); } else { $folderContents = IOHelper::getFolderContents($pathToAdd, true); } foreach ($folderContents as $itemToZip) { if (IOHelper::isReadable($itemToZip)) { // Figure out the relative path we'll be adding to the zip. $relFilePath = mb_substr($itemToZip, mb_strlen($basePath)); if ($pathPrefix) { $pathPrefix = IOHelper::normalizePathSeparators($pathPrefix); $relFilePath = $pathPrefix . $relFilePath; } if (IOHelper::folderExists($itemToZip)) { if (IOHelper::isFolderEmpty($itemToZip)) { $zip->addEmptyDir($relFilePath); } } elseif (IOHelper::fileExists($itemToZip)) { // We can't use $zip->addFile() here but it's a terrible, horrible, POS method that's buggy on Windows. $fileContents = IOHelper::getFileContents($itemToZip); if (!$zip->addFromString($relFilePath, $fileContents)) { Craft::log('There was an error adding the file ' . $itemToZip . ' to the zip: ' . $itemToZip, LogLevel::Error); } } } } $zip->close(); return true; }
/** * Returns the relevant lines from the update manifest file starting with the current local version/build. * * @param $manifestDataPath * @param $handle * * @throws Exception * @return array */ public static function getManifestData($manifestDataPath, $handle) { if (static::$_manifestData == null) { if (IOHelper::fileExists($manifestDataPath . '/' . $handle . '_manifest')) { // get manifest file $manifestFileData = IOHelper::getFileContents($manifestDataPath . '/' . $handle . '_manifest', true); if ($manifestFileData === false) { throw new Exception(Craft::t('There was a problem reading the update manifest data.')); } // Remove any trailing empty newlines if ($manifestFileData[count($manifestFileData) - 1] == '') { array_pop($manifestFileData); } $manifestData = array_map('trim', $manifestFileData); $updateModel = craft()->updates->getUpdates(); $localVersion = null; if ($handle == 'craft') { $localVersion = $updateModel->app->localVersion . '.' . $updateModel->app->localBuild; } else { foreach ($updateModel->plugins as $plugin) { if (strtolower($plugin->class) == $handle) { $localVersion = $plugin->localVersion; break; } } } // Only use the manifest data starting from the local version for ($counter = 0; $counter < count($manifestData); $counter++) { if (mb_strpos($manifestData[$counter], '##' . $localVersion) !== false) { break; } } $manifestData = array_slice($manifestData, $counter); static::$_manifestData = $manifestData; } } return static::$_manifestData; }
function getBase64Encoded() { $image = IOHelper::getFileContents($this->path); return base64_encode($image); }
/** * Returns the field's input HTML. * * @param string $name * @param mixed $value * @return string */ public function getInputHtml($name, $value) { $this->_includeFieldResources(); // Config? if ($this->getSettings()->configFile) { $configPath = craft()->path->getConfigPath() . 'redactor/' . $this->getSettings()->configFile; $config = IOHelper::getFileContents($configPath); } if (empty($config)) { $config = '{}'; } $sections = JsonHelper::encode($this->_getSectionSources()); craft()->templates->includeJs(craft()->templates->render('_components/fieldtypes/RichText/init.js', array('handle' => $this->model->handle, 'config' => $config, 'lang' => static::$_inputLang, 'sections' => $sections))); // Swap any <!--pagebreak-->'s with <hr>'s $value = str_replace('<!--pagebreak-->', '<hr class="redactor_pagebreak" style="display:none" unselectable="on" contenteditable="false" />', $value); return '<textarea name="' . $name . '" class="redactor-' . $this->model->handle . '" style="display: none">' . htmlentities($value, ENT_NOQUOTES, 'UTF-8') . '</textarea>'; }
/** * Strip orientation from EXIF data for an image at a path. * * @param $filePath * * @return bool */ public function stripOrientationFromExifData($filePath) { if (!ImageHelper::canHaveExifData($filePath)) { return null; } $data = new \PelDataWindow(IOHelper::getFileContents($filePath)); // Is this a valid JPEG? if (\PelJpeg::isValid($data)) { $jpeg = $file = new \PelJpeg(); $jpeg->load($data); $exif = $jpeg->getExif(); if ($exif) { $tiff = $exif->getTiff(); $ifd0 = $tiff->getIfd(); // Delete the Orientation entry and re-save the file $ifd0->offsetUnset(\PelTag::ORIENTATION); $file->saveFile($filePath); } return true; } else { return false; } }
/** * @return null|string */ private function _getLicenseKey() { $licenseKeyPath = craft()->path->getLicenseKeyPath(); if (($keyFile = IOHelper::fileExists($licenseKeyPath)) !== false) { return trim(preg_replace('/[\\r\\n]+/', '', IOHelper::getFileContents($keyFile))); } return null; }