public function getPatchefiles() { /* Mage::getBaseDir('etc') . DS . 'applied.patches.list'; */ $path = BP . DS . "app" . DS . "etc" . DS; $filename = 'applied.patches.list'; $filepath = $path . $filename; if (!file_exists($filepath)) { return "No Patch file found."; } if (!is_readable($filepath)) { return "Patch file is not readable."; } $flocal = new Varien_Io_File(); $flocal->open(array('path' => dirname($filepath))); $flocal->streamOpen($filepath, 'r'); $patch_install_version = array(); $patch_uninstall_version = array(); $patch_version = array(); while (false !== ($patchFileLines = $flocal->streamReadCsv())) { if (strpos($patchFileLines[0], 'SUPEE') !== false) { $patch_name = explode('|', $patchFileLines[0]); $patch_install_version[] = str_replace("SUPEE-", '', $patch_name[1]); } if (strpos($patchFileLines[0], 'REVERTED') !== false) { $patch_name = explode('|', $patchFileLines[0]); $patch_uninstall_version[] = str_replace("SUPEE-", '', $patch_name[1]); } } $patch_install_version = array_unique($patch_install_version); $patch_uninstall_version = array_unique($patch_uninstall_version); $patch_version = array_diff($patch_install_version, $patch_uninstall_version); return implode(",", $patch_version); }
/** * regenerate theme css based on appearance settings */ public function regenerate() { $websites = Mage::app()->getWebsites(); foreach ($websites as $_website) { $_website_code = $_website->getCode(); foreach ($_website->getStores() as $_store) { if (!Mage::app()->getStore($_store)->getIsActive()) { continue; } ob_start(); require $this->_css_template_path; $css = ob_get_clean(); $filename = str_replace(array('%WEBSITE%', '%STORE%'), array($_website_code, $_store->getCode()), $this->_css_file); try { $file = new Varien_Io_File(); $file->setAllowCreateFolders(true)->open(array('path' => $this->_css_path)); $file->streamOpen($filename, 'w+'); $file->streamWrite($css); $file->streamClose(); } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError(Mage::helper('athlete')->__('Css generation error: %s', $this->_css_path . $filename) . '<br/>' . $e->getMessage()); Mage::logException($e); } } } }
final function uninstall(Varien_Event_Observer $observer) { $module = $observer->getEvent()->getModule(); if (0 !== strpos(get_class($this), $module)) { return false; } $this->run(); $manifestPath = str_replace('_', '/', $module) . '/etc/manifest.xml'; foreach (explode(PS, get_include_path()) as $includePath) { if (file_exists($includePath . DS . $manifestPath)) { $manifestPath = $includePath . DS . $manifestPath; break; } } if (!file_exists($manifestPath)) { throw new Exception('Manifest path "' . $manifestPath . '" does not exist'); } $manifestXml = new SimpleXMLElement($manifestPath, null, true); $paths = $manifestXml->xpath('/manifest/' . $module . '/paths/path'); $file = new Varien_Io_File(); foreach ($paths as $path) { $path = BP . DS . $path; if (file_exists($path)) { if (is_dir($path)) { $file->rmdir($path, true); } else { $file->rm($path); } } } $this->_removeResources($module); }
/** * Check is folders exist and have writable permissions * * @return string Error message if exist */ public function checkFolderPermissionsErrors() { $arrFolders = array('image_dir' => Mage::getConfig()->getOptions()->getMediaDir() . DS . Mage::helper('nwdrevslider/images')->getImageDir(), 'thumb_dir' => Mage::getConfig()->getOptions()->getMediaDir() . DS . Mage::helper('nwdrevslider/images')->getImageThumbDir(), 'admin_css_dir' => Mage::getBaseDir() . Mage::helper('nwdrevslider/css')->getAdminCssDir(), 'front_css_dir' => Mage::getBaseDir() . Mage::helper('nwdrevslider/css')->getFrontCssDir()); $ioFile = new Varien_Io_File(); $arrErrors = array(); foreach ($arrFolders as $_folder) { try { if (!($ioFile->checkandcreatefolder($_folder) && $ioFile->isWriteable($_folder))) { $arrErrors[] = $_folder; } } catch (Exception $e) { $arrErrors[] = $_folder; Mage::logException($e); } } if (!(in_array($arrFolders['admin_css_dir'], $arrErrors) || in_array($arrFolders['front_css_dir'], $arrErrors))) { if (!file_exists($arrFolders['admin_css_dir'] . 'statics.css')) { Mage::helper('nwdrevslider/css')->putStaticCss(); } if (!file_exists($arrFolders['admin_css_dir'] . 'dynamic.css')) { Mage::helper('nwdrevslider/css')->putDynamicCss(); } } $strError = $arrErrors ? Mage::helper('nwdrevslider')->__('Following directories not found or not writable, please change permissions to: ') . implode(' , ', $arrErrors) : ''; return $strError; }
/** * Set base dir */ public function __construct() { $this->_baseDir = Mage::getBaseDir('var') . DS . 'connect'; $io = new Varien_Io_File(); $io->setAllowCreateFolders(true)->createDestinationDir($this->_baseDir); $this->addTargetDir($this->_baseDir); }
public function createModule($data) { $namespace = $this->_cleanString($data['namespace']); $module = $this->_cleanString($data['module']); $pool = $data['pool']; $version = $this->_cleanString($data['version']); $dependencies = array(); if (isset($data['depends'])) { foreach ($data['depends'] as $dependency) { $dependencies[] = sprintf('%s<%s />', str_repeat(' ', 4 * 4), $dependency); } } $replacements = array('{{Namespace}}' => $namespace, '{{namespace}}' => strtolower($namespace), '{{Module}}' => $module, '{{module}}' => strtolower($module), '{{pool}}' => $pool, '{{version}}' => $version, '{{depends}}' => implode(PHP_EOL, $dependencies)); $io = new Varien_Io_File(); $tplDir = $this->getTemplateDir(); $tmpDir = $this->getTmpModuleDir($namespace . '_' . $module); $io->checkAndCreateFolder($tmpDir); if (!$io->isWriteable($tmpDir)) { Mage::throwException('Module temp dir is not writeable'); } @shell_exec("cp -r {$tplDir} {$tmpDir}"); $files = $this->_getTemplateFiles($tmpDir); if (empty($files)) { Mage::throwException('Could not copy templates files to module temp dir'); } $this->_replaceVars($tmpDir, $replacements); $dest = Mage::getBaseDir(); if (!$io->isWriteable($dest)) { Mage::throwException(sprintf('Could not move module files to Magento tree. However, module structure is available in %s', $tmpDir)); } @shell_exec("cp -r {$tmpDir} {$dest}"); return true; }
} else { return $placeholder_img; } } return $svg_url; } /** * get "" enclosed part of Label to use it as Image alt
/** * Flush the media/slider/resized folder, when the catalog image cache is flushed * * @param Varien_Event_Observer $observer * @return Soon_Image_Model_Observer */ public function cleanImageCache(Varien_Event_Observer $observer) { $directory = Mage::getBaseDir('media') . DS . 'slider' . DS . 'resized' . DS; $io = new Varien_Io_File(); $io->rmdir($directory, true); return $this; }
public function save($destination = null, $newName = null) { $fileName = !isset($destination) ? $this->_fileName : $destination; if (isset($destination) && isset($newName)) { $fileName = $destination . "/" . $fileName; } elseif (isset($destination) && !isset($newName)) { $info = pathinfo($destination); $fileName = $destination; $destination = $info['dirname']; } elseif (!isset($destination) && isset($newName)) { $fileName = $this->_fileSrcPath . "/" . $newName; } else { $fileName = $this->_fileSrcPath . $this->_fileSrcName; } $destinationDir = isset($destination) ? $destination : $this->_fileSrcPath; if (!is_writable($destinationDir)) { try { $io = new Varien_Io_File(); $io->mkdir($destination); } catch (Exception $e) { throw new Exception("Unable to write file into directory '{$destinationDir}'. Access forbidden."); } } // keep alpha transparency $isAlpha = false; $this->_getTransparency($this->_imageHandler, $this->_fileType, $isAlpha); if ($isAlpha) { $this->_fillBackgroundColor($this->_imageHandler); } call_user_func($this->_getCallback('output'), $this->_imageHandler, $fileName); }
public function getCSVFile() { $data = $this->dataExport; if ($this->isVersion13) { $content = ''; foreach ($data as $val) { $content .= implode(',', $val) . "\r\n"; } return $content; } else { $io = new Varien_Io_File(); $path = Mage::getBaseDir('var') . DS . 'export' . DS; $name = md5(microtime()); $file = $path . DS . $name . '.csv'; $io->setAllowCreateFolders(true); $io->open(array('path' => $path)); $io->streamOpen($file, 'w+'); $io->streamLock(true); // $this->dataExport[0] == csvHeader $io->streamWriteCsv($data[0]); unset($data[0]); //$delimiter = Mage::getSingleton('core/session')->getExportSeperator(); foreach ($data as $val) { $io->streamWriteCsv($val); } return array('type' => 'filename', 'value' => $file, 'rm' => false); } }
/** * Write Sample Data to File. Store in folder: "skin/frontend/default/ves theme name/import/" */ public function writeSampleDataFile($importDir, $file_name, $content = "") { $file = new Varien_Io_File(); //Create import_ready folder $error = false; if (!file_exists($importDir)) { $importReadyDirResult = $file->mkdir($importDir); $error = false; if (!$importReadyDirResult) { //Handle error $error = true; Mage::getSingleton('adminhtml/session')->addError(Mage::helper('ves_tempcp')->__('Can not create folder "%s".', $importDir)); } } else { $file->open(array('path' => $importDir)); } if (!$file->write($importDir . $file_name, $content)) { //Handle error $error = true; Mage::getSingleton('adminhtml/session')->addError(Mage::helper('ves_tempcp')->__('Can not save import sample file "%s".', $file_name)); } if (!$error) { Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('cms')->__('Successfully, Stored sample data file "%s".', $file_name)); } return !$error; }
/** * Write file to file system. * * @param null $destination * @param null $newName * @throws Exception */ public function save($destination = null, $newName = null) { Varien_Profiler::start(__METHOD__); if (isset($destination) && isset($newName)) { $fileName = $destination . "/" . $newName; } elseif (isset($destination) && !isset($newName)) { $info = pathinfo($destination); $fileName = $destination; $destination = $info['dirname']; } elseif (!isset($destination) && isset($newName)) { $fileName = $this->_fileSrcPath . "/" . $newName; } else { $fileName = $this->_fileSrcPath . $this->_fileSrcName; } $destinationDir = isset($destination) ? $destination : $this->_fileSrcPath; if (!is_writable($destinationDir)) { try { $io = new Varien_Io_File(); $io->mkdir($destination); } catch (Exception $e) { Varien_Profiler::stop(__METHOD__); throw new Exception("Unable to write into directory '{$destinationDir}'."); } } //set compression quality $this->getImageMagick()->setImageCompressionQuality($this->getQuality()); //remove all underlying information $this->getImageMagick()->stripImage(); //write to file system $this->getImageMagick()->writeImage($fileName); //clear data and free resources $this->getImageMagick()->clear(); $this->getImageMagick()->destroy(); Varien_Profiler::stop(__METHOD__); }
/** * @param $filename * @return bool|string */ public function loadFile($filename) { $varienFile = new Varien_Io_File(); $varienFile->open(); $path = $this->getFilePath($filename); return $varienFile->read($path . DS . $filename); }
/** * Resize image * * @param string $fileName * @param int $width * @param int $height * @return string Resized image url */ public function resizeImg($fileName, $width, $height = '') { if (!$height) { $height = $width; } $thumbDir = self::IMAGE_THUMB_DIR; $resizeDir = $thumbDir . "/resized_{$width}x{$height}"; $ioFile = new Varien_Io_File(); $ioFile->checkandcreatefolder(Mage::getBaseDir(Mage_Core_Model_Store::URL_TYPE_MEDIA) . DS . $resizeDir); $imageParts = explode('/', $fileName); $imageFile = end($imageParts); $folderURL = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA); $imageURL = $folderURL . $fileName; $basePath = Mage::getBaseDir(Mage_Core_Model_Store::URL_TYPE_MEDIA) . DS . $fileName; $newPath = Mage::getBaseDir(Mage_Core_Model_Store::URL_TYPE_MEDIA) . DS . $resizeDir . DS . $imageFile; if ($width != '') { if (file_exists($basePath) && is_file($basePath) && !file_exists($newPath)) { $imageObj = new Varien_Image($basePath); $imageObj->constrainOnly(TRUE); $imageObj->keepAspectRatio(TRUE); $imageObj->keepFrame(FALSE); $imageObj->keepTransparency(TRUE); //$imageObj->backgroundColor(array(255,255,255)); $imageObj->resize($width, $height); $imageObj->save($newPath); } $resizedURL = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . $resizeDir . '/' . $imageFile; } else { $resizedURL = $imageURL; } return $resizedURL; }
/** * @$forceCreation true overwrites existing entities with the new values */ public function import($forceCreation = false) { if (is_null($this->_entity)) { throw Mage::exception('Please specify a valid entity.'); } if (!file_exists($this->_importFile)) { throw Mage::exception('Please specify a valid csv file.'); } if (is_null($this->_storeId)) { throw Mage::exception('Please specify a valid store.'); } $io = new Varien_Io_File(); $io->streamOpen($this->_importFile, 'r'); $io->streamLock(true); $firstLine = true; while (false !== ($line = $io->streamReadCsv())) { if ($firstLine) { $firstLine = false; $this->_headerColumns = $line; continue; } $data = array(); foreach ($this->_headerColumns as $key => $val) { $data[$val] = $line[$key]; } $this->_importEntity($data, $forceCreation); } }
/** * @todo better subdirectories * saves a file in the dir: media/wysiwyg/markdown/.... * * @return $this */ public function fileUploadAction() { $return = array('err' => TRUE, 'msg' => 'An error occurred.', 'fileUrl' => ''); $binaryData = base64_decode($this->getRequest()->getParam('binaryData', '')); $file = json_decode($this->getRequest()->getParam('file', '[]'), TRUE); if (!(isset($file['extra']['nameNoExtension']) && isset($file['extra']['extension'])) || empty($binaryData)) { $return['msg'] = 'Either fileName or binaryData or file is empty ...'; return $this->_setReturn($return, TRUE); } $fileName = $file['extra']['nameNoExtension'] . '.' . $file['extra']['extension']; if (strpos(strtolower($fileName), 'clipboard') !== FALSE) { $fileName = 'clipboard_' . date('Ymd-His') . '_' . str_replace('clipboard', '', strtolower($fileName)); } $fileName = preg_replace('~[^\\w\\.]+~i', '_', $fileName); $savePath = $this->_getStorageRoot() . $this->_getStorageSubDirectory(); $io = new Varien_Io_File(); if ($io->checkAndCreateFolder($savePath)) { $result = (int) file_put_contents($savePath . $fileName, $binaryData); // io->write will not work :-( if ($result > 10) { $return['err'] = FALSE; $return['msg'] = ''; $return['fileUrl'] = Mage::helper('markdown')->getTemplateMediaUrl($this->_getStorageSubDirectory() . $fileName); } } $this->_setReturn($return, TRUE); }
public function getCsvFileEnhanced() { $collectionData = $this->getCollection()->getData(); $this->_isExport = true; $io = new Varien_Io_File(); $path = Mage::getBaseDir('var') . DS . 'export' . DS; $name = md5(microtime()); $file = $path . DS . $name . '.csv'; while (file_exists($file)) { sleep(1); $name = md5(microtime()); $file = $path . DS . $name . '.csv'; } $io->setAllowCreateFolders(true); $io->open(array('path' => $path)); $io->streamOpen($file, 'w+'); $io->streamLock(true); if ($this->_columns) { $io->streamWriteCsv($this->_columns); } foreach ($collectionData as $item) { if ($this->_removeIndexes && is_array($this->_removeIndexes)) { foreach ($this->_removeIndexes as $index) { unset($item[$index]); } } $io->streamWriteCsv($item); } $io->streamUnlock(); $io->streamClose(); return array('type' => 'filename', 'value' => $file, 'rm' => true); }
public function importAction() { try { $productId = $this->getRequest()->getParam('id'); $fileName = $this->getRequest()->getParam('Filename'); $path = Mage::getBaseDir('var') . DS . 'import' . DS; $uploader = new Mage_Core_Model_File_Uploader('file'); $uploader->setAllowedExtensions(array('csv')); $uploader->setAllowRenameFiles(false); $uploader->setFilesDispersion(false); $result = $uploader->save($path, $fileName); $io = new Varien_Io_File(); $io->open(array('path' => $path)); $io->streamOpen($path . $fileName, 'r'); $io->streamLock(true); while ($data = $io->streamReadCsv(';', '"')) { if ($data[0]) { $model = Mage::getModel('giftcards/pregenerated')->load($data[0], 'card_code'); if ($model->getId()) { continue; } $model->setCardCode($data[0]); $model->setCardStatus(1); $model->setProductId($productId); $model->save(); } else { continue; } } } catch (Exception $e) { $result = array('error' => $e->getMessage(), 'errorcode' => $e->getCode()); } $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); }
public function uploadAndImport(Varien_Object $object) { $hlr = Mage::helper("amacart"); if (empty($_FILES['groups']['tmp_name']['import']['fields']['blacklist']['value'])) { return $this; } $csvFile = $_FILES['groups']['tmp_name']['import']['fields']['blacklist']['value']; $io = new Varien_Io_File(); $info = pathinfo($csvFile); $io->open(array('path' => $info['dirname'])); $io->streamOpen($info['basename'], 'r'); $emails = array(); while (($csvLine = $io->streamReadCsv()) !== FALSE) { foreach ($csvLine as $email) { if (!Zend_Validate::is($email, 'NotEmpty')) { } else { if (!Zend_Validate::is($email, 'EmailAddress')) { $this->_warnings[] = $email . " " . $hlr->__("not valid email"); } else { $emails[] = array("email" => $email, 'created_at' => date("Y-m-d H:i:s", time())); } } if (count($emails) == 100) { $this->saveImportData($emails); $emails = array(); } } } $this->saveImportData($emails); foreach (array_slice($this->_warnings, 0, 10) as $warning) { Mage::getSingleton('adminhtml/session')->addWarning($warning); } Mage::getSingleton('core/session')->addSuccess($hlr->__("Import completed")); }
/** * Generate XML file * * @return Mage_Sitemap_Model_Sitemap */ public function generateXml() { $io = new Varien_Io_File(); $io->setAllowCreateFolders(true); $io->open(array('path' => $this->getPath())); if ($io->fileExists($this->getSitemapFilename()) && !$io->isWriteable($this->getSitemapFilename())) { Mage::throwException(Mage::helper('sitemap')->__('File "%s" cannot be saved. Please, make sure the directory "%s" is writeable by web server.', $this->getSitemapFilename(), $this->getPath())); } $io->streamOpen($this->getSitemapFilename()); $io->streamWrite('<?xml version="1.0" encoding="UTF-8"?>' . "\n"); $io->streamWrite('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:content="http://www.google.com/schemas/sitemap-content/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">' . "\n"); $storeId = $this->getStoreId(); $date = Mage::getSingleton('core/date')->gmtDate('Y-m-d'); $baseUrl = Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK); // Hans2103 change -> set mediaUrl $mediaUrl = Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA); $mediaUrl = preg_replace('/^https/', 'http', $mediaUrl); /** * Generate categories sitemap */ $changefreq = (string) Mage::getStoreConfig('sitemap/category/changefreq', $storeId); $priority = (string) Mage::getStoreConfig('sitemap/category/priority', $storeId); $collection = Mage::getResourceModel('sitemap/catalog_category')->getCollection($storeId); foreach ($collection as $item) { $xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>' . "\n", htmlspecialchars($baseUrl . $item->getUrl()), $date, $changefreq, $priority); $io->streamWrite($xml); $this->check_counter($io); } unset($collection); /** * Generate products sitemap */ /** * override to include images in sitemap */ $changefreq = (string) Mage::getStoreConfig('sitemap/product/changefreq', $storeId); $priority = (string) Mage::getStoreConfig('sitemap/product/priority', $storeId); $collection = Mage::getResourceModel('sitemap/catalog_product')->getCollection($storeId); foreach ($collection as $item) { $xml = sprintf('<url><loc>%s</loc><image:image><image:loc>%s</image:loc><image:title>%s</image:title></image:image><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority><PageMap xmlns="http://www.google.com/schemas/sitemap-pagemap/1.0"><DataObject type="thumbnail"><Attribute name="name" value="%s"/><Attribute name="src" value="%s"/></DataObject></PageMap></url>' . "\n", htmlspecialchars($baseUrl . $item->getUrl()), htmlspecialchars($mediaUrl . 'catalog/product' . $item->getMedia()), htmlspecialchars($item->getName()), $date, $changefreq, $priority, htmlspecialchars($item->getName()), htmlspecialchars($mediaUrl . 'catalog/product' . $item->getMedia())); $io->streamWrite($xml); } unset($collection); /** * Generate cms pages sitemap */ $changefreq = (string) Mage::getStoreConfig('sitemap/page/changefreq', $storeId); $priority = (string) Mage::getStoreConfig('sitemap/page/priority', $storeId); $collection = Mage::getResourceModel('sitemap/cms_page')->getCollection($storeId); foreach ($collection as $item) { $xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>' . "\n", htmlspecialchars($baseUrl . $item->getUrl()), $date, $changefreq, $priority); $io->streamWrite($xml); } unset($collection); $io->streamWrite('</urlset>'); $io->streamClose(); $this->setSitemapTime(Mage::getSingleton('core/date')->gmtDate('Y-m-d H:i:s')); $this->save(); return $this; }
protected function _generateStoreCss($storeCode) { $store = Mage::app()->getStore($storeCode); $store_id = $store->getId(); $package_name = Mage::getStoreConfig('design/package/name', $store_id); $theme = Mage::getStoreConfig('design/theme/defaults', $store_id); if ($theme == '') { $theme = 'default'; } if (!$store->getIsActive()) { return; } $cssFile = Mage::getBaseDir('skin') . DS . 'frontend' . DS . $package_name . DS . $theme . DS . 'themesettings' . DS . 'css' . DS . 'themesettings_' . $storeCode . '.css'; $cssTemplate = 'ves/themesettings/themesettings_styles.phtml'; Mage::register('ves_store', $store); try { $cssBlockHtml = Mage::app()->getLayout()->createBlock("core/template")->setData('area', 'frontend')->setTemplate($cssTemplate)->toHtml(); if (empty($cssBlockHtml)) { throw new Exception(Mage::helper('themesettings')->__("The system has an issue when create css file")); } $file = new Varien_Io_File(); $file->setAllowCreateFolders(true); $file->open(array('path' => Mage::getBaseDir('skin') . DS . 'frontend' . DS . $package_name . DS . $theme . DS . 'themesettings' . DS . 'css')); $file->streamOpen($cssFile, 'w+', 0777); $file->streamLock(true); $file->streamWrite($cssBlockHtml); $file->streamUnlock(); $file->streamClose(); } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError(Mage::helper('themesettings')->__('The system has an issue when create css file') . '<br/>Message: ' . $e->getMessage()); Mage::logException($e); } Mage::unregister('ves_store'); }
public function save($destination = null, $newName = null) { $fileName = !isset($destination) ? $this->_fileName : $destination; if (isset($destination) && isset($newName)) { $fileName = $destination . "/" . $newName; } elseif (isset($destination) && !isset($newName)) { $info = pathinfo($destination); $fileName = $destination; $destination = $info['dirname']; } elseif (!isset($destination) && isset($newName)) { $fileName = $this->_fileSrcPath . "/" . $newName; } else { $fileName = $this->_fileSrcPath . $this->_fileSrcName; } $destinationDir = isset($destination) ? $destination : $this->_fileSrcPath; if (!is_writable($destinationDir)) { try { $io = new Varien_Io_File(); $io->mkdir($destination); } catch (Exception $e) { throw new Exception("Unable to write file into directory '{$destinationDir}'. Access forbidden."); } } if (!$this->_resized) { // keep alpha transparency $isAlpha = false; $isTrueColor = false; $this->_getTransparency($this->_imageHandler, $this->_fileType, $isAlpha, $isTrueColor); if ($isAlpha) { if ($isTrueColor) { $newImage = imagecreatetruecolor($this->_imageSrcWidth, $this->_imageSrcHeight); } else { $newImage = imagecreate($this->_imageSrcWidth, $this->_imageSrcHeight); } $this->_fillBackgroundColor($newImage); imagecopy($newImage, $this->_imageHandler, 0, 0, 0, 0, $this->_imageSrcWidth, $this->_imageSrcHeight); $this->_imageHandler = $newImage; } } $functionParameters = array(); $functionParameters[] = $this->_imageHandler; $functionParameters[] = $fileName; // set quality param for JPG file type if (!is_null($this->quality()) && $this->_fileType == IMAGETYPE_JPEG) { $functionParameters[] = $this->quality(); } // set quality param for PNG file type if (!is_null($this->quality()) && $this->_fileType == IMAGETYPE_PNG) { $quality = round($this->quality() / 100 * 10); if ($quality < 1) { $quality = 1; } elseif ($quality > 10) { $quality = 10; } $quality = 10 - $quality; $functionParameters[] = $quality; } call_user_func_array($this->_getCallback('output'), $functionParameters); }
protected function _getVarienIoFileObject() { $file = new Varien_Io_File(); $file->setAllowCreateFolders(true); $file->open(array('path' => Mage::helper('wordpress')->getFileCachePath())); $file->setAllowCreateFolders(true); return $file; }
/** * Set target dir for scanning */ public function __construct() { parent::__construct(); $basePath = Mage::getModel('enterprise_logging/archive')->getBasePath(); $file = new Varien_Io_File(); $file->setAllowCreateFolders(true)->createDestinationDir($basePath); $this->addTargetDir($basePath); }
public function checkFilePermissions() { $io = new Varien_Io_File(); $io->checkAndCreateFolder($this->local_dir); if (!$io->isWriteable($this->local_dir)) { return 'folder is not writable'; } return ''; }
public function saveAction() { $post_data = $this->getRequest()->getPost(); if ($post_data) { try { $post_data['category'] = implode(',', $post_data['category']); //save image try { if ((bool) $post_data['image']['delete'] == 1) { $post_data['image'] = ''; } else { unset($post_data['image']); if (isset($_FILES)) { if ($_FILES['image']['name']) { if ($this->getRequest()->getParam("id")) { $model = Mage::getModel("gallery/image")->load($this->getRequest()->getParam("id")); if ($model->getData('image')) { $io = new Varien_Io_File(); $io->rm(Mage::getBaseDir('media') . DS . implode(DS, explode('/', $model->getData('image')))); } } $path = Mage::getBaseDir('media') . DS . 'gallery' . DS . 'image' . DS; $uploader = new Varien_File_Uploader('image'); $uploader->setAllowedExtensions(array('jpg', 'png', 'gif')); $uploader->setAllowRenameFiles(false); $uploader->setFilesDispersion(false); $destFile = $path . $_FILES['image']['name']; $filename = $uploader->getNewFileName($destFile); $uploader->save($path, $filename); $post_data['image'] = 'gallery/image/' . $filename; } } } } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id'))); return; } //save image $model = Mage::getModel("gallery/image")->addData($post_data)->setId($this->getRequest()->getParam("id"))->save(); Mage::getSingleton("adminhtml/session")->addSuccess(Mage::helper("adminhtml")->__("Image was successfully saved")); Mage::getSingleton("adminhtml/session")->setImageData(false); if ($this->getRequest()->getParam("back")) { $this->_redirect("*/*/edit", array("id" => $model->getId())); return; } $this->_redirect("*/*/"); return; } catch (Exception $e) { Mage::getSingleton("adminhtml/session")->addError($e->getMessage()); Mage::getSingleton("adminhtml/session")->setImageData($this->getRequest()->getPost()); $this->_redirect("*/*/edit", array("id" => $this->getRequest()->getParam("id"))); return; } } $this->_redirect("*/*/"); }
public function isFileExists($fileName) { $ioObject = new Varien_Io_File(); $ioObject->setAllowCreateFolders(true); $ioObject->open(array('path' => $ioObject->dirname($fileName))); if ($ioObject->fileExists($fileName, true)) { return true; } return false; }
/** * Decode uploaded file base64 encoded content * * @param array $fileInfo * @return array */ private function _decodeFile($fileInfo) { $tmpFileName = $this->_getTmpFilePath(); $file = new Varien_Io_File(); $file->open(array('path' => sys_get_temp_dir())); $file->streamOpen($tmpFileName); $file->streamWrite(base64_decode($fileInfo['base64_content'])); $file->streamClose(); return array('name' => $fileInfo['name'], 'type' => isset($fileInfo['type']) ? $fileInfo['type'] : self::DEFAULT_FILE_TYPE, 'tmp_name' => $tmpFileName, 'error' => 0, 'size' => filesize($tmpFileName)); }
protected function fileCreate() { $io = new Varien_Io_File(); $io->setAllowCreateFolders(true); $io->open(array('path' => $this->getPath())); $io->streamOpen($this->getSitemapFilename()); $io->streamWrite('<?xml version="1.0" encoding="UTF-8"?>' . "\n"); $io->streamWrite('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'); $this->io = $io; }
protected function finaliseStoreData() { // Write DOM to file $filename = $this->info("clean_store_name") . '-products.xml'; $io = new Varien_Io_File(); $io->setAllowCreateFolders(true); $io->open(array('path' => $this->getPath())); $io->write($filename, $this->_dom->saveXML()); $io->close(); }