} else { return $placeholder_img; } } return $svg_url; } /** * get "" enclosed part of Label to use it as Image alt
protected function open($write = false) { $ioAdapter = new Varien_Io_File(); try { $path = $ioAdapter->getCleanPath($this->getPath()); $ioAdapter->checkAndCreateFolder($path); $filePath = $path . DS . $this->getFileName(); } catch (Exception $e) { Mage::helper('mailchimp')->addException($e); } if ($write && $ioAdapter->fileExists($filePath)) { $ioAdapter->rm($filePath); } if (!$write && !$ioAdapter->fileExists($filePath)) { $message = Mage::helper('mailchimp')->__('File "%s" does not exist.', $this->getFileName()); Mage::getSingleton('adminhtml/session')->addError($this->__('Mailchimp General Error: ') . $message); } $mode = $write ? 'wb' . self::COMPRESS_RATE : 'rb'; try { $this->_handler = gzopen($filePath, $mode); } catch (Exception $e) { Mage::helper('mailchimp')->addException($e); } return $this; }
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; }
/** * @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); }
/** * Create/update file in file system * * @return bool|int */ protected function _saveFile() { $filePath = $this->getFilePath(true); $this->_ioFile->checkAndCreateFolder(dirname($filePath)); $result = $this->_ioFile->write($filePath, $this->getContent()); $this->_design->cleanMergedJsCss(); return $result; }
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 ''; }
/** * Create extension folders. * @param $folderName * @throws Exception */ protected function createExtensionFolders($folderName) { try { $this->_filesystem->checkAndCreateFolder($folderName); } catch (Exception $e) { Mage::log($e->getMessage(), null, $this->_helper->getLogFilename()); Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); } }
/** * Create physical certificate file based on DB data * * @param string $file */ protected function _createCertFile($file) { $certDir = $this->_getBaseDir(); if (!is_dir($certDir)) { $ioAdapter = new Varien_Io_File(); $ioAdapter->checkAndCreateFolder($certDir); } else { $this->_removeOutdatedCertFile(); } file_put_contents($file, Mage::helper('core')->decrypt($this->getContent())); }
/** * @param $file * @param $filename * @throws Exception */ public function saveFile($file, $filename) { $varienFile = new Varien_Io_File(); $varienFile->open(); $path = $this->getFilePath($filename); $varienFile->checkAndCreateFolder($path); if ($varienFile->write($path . DS . $filename, $file) !== false) { return $path . DS . $filename; } else { throw new Exception('Could not save PDF file'); } }
protected function createConfigFile() { $base_url = explode("/", Mage::getBaseUrl('js')); $base_url = explode($base_url[count($base_url) - 2], Mage::getBaseUrl('js')); $this->_base_url = $base_url[0]; $base_URLs = preg_replace('/http:\\/\\//is', 'https://', $base_url[0]); /** Create file config for javascript */ $js = "var mw_baseUrl = '{BASE_URL}';\n"; $js = str_replace("{BASE_URL}", $base_url[0], $js); $js .= "var mw_baseUrls = '{$base_URLs}';\n"; $js .= "var FACEBOOK_ID = '" . Mage::helper('mw_socialgift')->getFBID() . "';\n"; $file = new Varien_Io_File(); $file->checkAndCreateFolder($this->baseDir . "/media/mw_socialgift/js/"); $file->checkAndCreateFolder($this->baseDir . "/media/mw_socialgift/css/"); foreach ($this->_multi_path_js as $code => $path) { if (!file_exists($path) && Mage::app()->getStore()->getCode() == $code) { $file->write($path, $js); $file->close(); } } return $js; }
protected function _rewriteGrid($blcgClass, $originalClass, $gridType) { $classParts = explode('_', str_replace($this->_getBlcgClassPrefix(), '', $blcgClass)); $fileName = array_pop($classParts) . '.php'; $rewriteDir = dirname(__FILE__) . '/../../../Block/Rewrite/' . implode('/', $classParts); $ioFile = new Varien_Io_File(); $ioFile->setAllowCreateFolders(true); $ioFile->checkAndCreateFolder($rewriteDir); $ioFile->cd($rewriteDir); // Use open() to initialize Varien_Io_File::$_iwd // Prevents a warning when chdir() is used without error control in Varien_Io_File::read() if ($ioFile->fileExists($fileName, true) && $ioFile->open()) { if ($content = $ioFile->read($fileName)) { $lines = preg_split('#\\R#', $content, 3); $isUpToDate = false; if (isset($lines[0]) && isset($lines[1]) && $lines[0] == '<?php' && preg_match('#^// BLCG_REWRITE_CODE_VERSION\\=([0-9]+)$#', $lines[1], $matches)) { if ($matches[1] === strval(self::REWRITE_CODE_VERSION)) { $isUpToDate = true; } } } $ioFile->close(); if ($isUpToDate) { return $this; } } $content = '<?php // BLCG_REWRITE_CODE_VERSION=' . self::REWRITE_CODE_VERSION . ' // This file was generated automatically. Do not alter its content. /** * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * * @category BL * @package BL_CustomGrid * @copyright Copyright (c) ' . date('Y') . ' Benoît Leulliette <*****@*****.**> * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ '; $content .= $this->_getRewriteCode($blcgClass, $originalClass, $gridType); if (!$ioFile->write($fileName, $content)) { Mage::throwException(); } return $this; }
protected function _debugWriteToFile($str) { if (!$this->_debugIoAdapter) { $this->_debugIoAdapter = new Varien_Io_File(); $dir = $this->_debugIoAdapter->dirname($this->_debugFile); $this->_debugIoAdapter->checkAndCreateFolder($dir); $this->_debugIoAdapter->open(array('path' => $dir)); $this->_debugFile = basename($this->_debugFile); } $this->_debugIoAdapter->streamOpen($this->_debugFile, 'a'); $this->_debugIoAdapter->streamLock(); $this->_debugIoAdapter->streamWrite($str); $this->_debugIoAdapter->streamUnlock(); $this->_debugIoAdapter->streamClose(); }
/** * Product image add * * @throws Mage_Api2_Exception * @param array $data * @return string */ protected function _create(array $data) { /* @var $validator Mage_Catalog_Model_Api2_Product_Image_Validator_Image */ $validator = Mage::getModel('Mage_Catalog_Model_Api2_Product_Image_Validator_Image'); if (!$validator->isValidData($data)) { foreach ($validator->getErrors() as $error) { $this->_error($error, Mage_Api2_Model_Server::HTTP_BAD_REQUEST); } $this->_critical(self::RESOURCE_DATA_PRE_VALIDATION_ERROR); } $imageFileContent = @base64_decode($data['file_content'], true); if (!$imageFileContent) { $this->_critical('The image content must be valid base64 encoded data', Mage_Api2_Model_Server::HTTP_BAD_REQUEST); } unset($data['file_content']); $apiTempDir = Mage::getBaseDir('var') . DS . 'api' . DS . Mage::getSingleton('Mage_Api_Model_Session')->getSessionId(); $imageFileName = $this->_getFileName($data); try { $ioAdapter = new Varien_Io_File(); $ioAdapter->checkAndCreateFolder($apiTempDir); $ioAdapter->open(array('path' => $apiTempDir)); $ioAdapter->write($imageFileName, $imageFileContent, 0666); unset($imageFileContent); // try to create Image object to check if image data is valid try { $adapter = Mage::helper('Mage_Core_Helper_Data')->getImageAdapterType(); new Varien_Image($apiTempDir . DS . $imageFileName, $adapter); } catch (Exception $e) { $ioAdapter->rmdir($apiTempDir, true); $this->_critical($e->getMessage(), Mage_Api2_Model_Server::HTTP_INTERNAL_ERROR); } $product = $this->_getProduct(); $imageFileUri = $this->_getMediaGallery()->addImage($product, $apiTempDir . DS . $imageFileName, null, false, false); $ioAdapter->rmdir($apiTempDir, true); // updateImage() must be called to add image data that is missing after addImage() call $this->_getMediaGallery()->updateImage($product, $imageFileUri, $data); if (isset($data['types'])) { $this->_getMediaGallery()->setMediaAttribute($product, $data['types'], $imageFileUri); } $product->save(); return $this->_getImageLocation($this->_getCreatedImageId($imageFileUri)); } catch (Mage_Core_Exception $e) { $this->_critical($e->getMessage(), Mage_Api2_Model_Server::HTTP_INTERNAL_ERROR); } catch (Exception $e) { $this->_critical(self::RESOURCE_UNKNOWN_ERROR); } }
/** * Log messages under a specific folder for easy grouping of all Bitloop * module logs. * * @param string $message * @param int $level * @param bool $forceLog * * @return $this * @throws Exception */ public function log($message, $level = null, $forceLog = false) { // Buld the log folder directory location, relative to Magento's root // var/log folder $_logFolder = Mage::getBaseDir('var') . DS . 'log' . DS . self::LOGS_SUBFOLDER; // Check if the folder exists and if it doesn't create it. // If it exists or it was created successfully, log inside that folder // using the module name as the file name $_io = new Varien_Io_File(); if ($_io->checkAndCreateFolder($_logFolder)) { // Build the log file name. $_logFile = self::LOGS_SUBFOLDER . $this->_getModuleName() . '.log'; // Log the message Mage::log($message, $level, $_logFile, $forceLog); } return $this; }
function writeRewriteFile() { $adapter = Mage::getModel('freelunchlabs_cloudfront/refreshadapters_apache'); $base_dir = Mage::getBaseDir() . DS; $file = new Varien_Io_File(); try { if ($file->cd($base_dir) && $file->checkAndCreateFolder($this->cdn_rewrite_directory, 0755)) { if ($file->cd($base_dir . $this->cdn_rewrite_directory)) { if (!$file->write($adapter->filename, $adapter->buildFileContents(), 0644)) { throw new Exception("Could not write .htaccess to: " . $file->pwd()); } } } } catch (Exception $e) { Mage::getSingleton('core/session')->addWarning('Configuration saved but there was an error creating the .htaccess file: ' . $e->getMessage()); } }
/** * Create temp csv file and write export * * @return mixed */ protected function _createFile() { $dir = $this->_getTmpDir(); $fileName = Mage::getStoreConfig(self::XML_PATH_SETTINGS_FINDFEED_FILENAME); if (!$dir || !$fileName) { return false; } if (!($attributes = $this->_getImportAttributes()) || count($attributes) <= 0) { return false; } $headers = array_keys($attributes); $file = new Varien_Io_File(); $file->checkAndCreateFolder($dir); $file->cd($dir); $file->streamOpen($fileName, 'w+'); $file->streamLock(); $file->streamWriteCsv($headers, self::SEPARATOR, self::ENCLOSURE); $productCollectionPrototype = Mage::getResourceModel('catalog/product_collection'); $productCollectionPrototype->setPageSize(self::COLLECTION_PAGE_SIZE); $pageNumbers = $productCollectionPrototype->getLastPageNumber(); unset($productCollectionPrototype); for ($i = 1; $i <= $pageNumbers; $i++) { $productCollection = Mage::getResourceModel('catalog/product_collection'); $productCollection->addAttributeToSelect($attributes); $productCollection->addAttributeToFilter('is_imported', 1); $productCollection->setPageSize(self::COLLECTION_PAGE_SIZE); $productCollection->setCurPage($i)->load(); foreach ($productCollection as $product) { $attributesRow = array(); foreach ($attributes as $key => $value) { $attributesRow[$key] = $product->getData($value); } $file->streamWriteCsv($attributesRow, self::SEPARATOR, self::ENCLOSURE); } unset($productCollection); } $file->streamUnlock(); $file->streamClose(); if ($file->fileExists($fileName)) { return $fileName; } return false; }
/** * Generate data feeds for this specific website * * @param in $websiteId Id of the website for which to generate data feeds * @param bool $bBaselineFile Should this file be a baseline file or an automated daily file * @param string $feedType Type of feed to generate, null = generate all feeds * @param int|string $minEntityId Number representing minimum value for entity Id to export - This acts as a placeholder for where the feed export left off */ public function generateForWebsite($websiteId, $bBaselineFile, $feedType, &$minEntityId, &$bDone) { // Log mem usage Mage::helper('mybuys')->log('Memory usage: ' . memory_get_usage(), Zend_Log::DEBUG, Mybuys_Connector_Helper_Data::LOG_FILE); // Check data feeds enabled // Check feed of this type if config is enabled if (Mage::app()->getWebsite($websiteId)->getConfig('mybuys_datafeeds/general/allfeedsenabled') != 'enabled' || Mage::app()->getWebsite($websiteId)->getConfig('mybuys_datafeeds/feedsenabled/' . $feedType) != 'enabled') { Mage::throwException('Data feeds or feedtype ' . $feedType . ' not enabled for website: ' . $websiteId); } // Lookup up throttle param $throttle = Mage::app()->getWebsite($websiteId)->getConfig('mybuys_datafeeds/advanced/throttle'); // Build path of where to store feeds $feedExportPath = Mage::getConfig()->getVarDir() . DS . Mybuys_Connector_Model_Generatefeeds::MBUYS_FEED_PATH; // Check and create folder $oIo = new Varien_Io_File(); $oIo->checkAndCreateFolder($feedExportPath); // Create feed // Generate just the one specific type of feed $modelFeed = Mage::getModel('mybuys/feed_' . $feedType); $modelFeed->generate($websiteId, $feedExportPath, $bBaselineFile, $throttle, $minEntityId, $bDone); }
public function buildFeeds() { foreach (Mage::app()->getStores() as $store) { if (Mage::getStoreConfig('clerk/settings/active', $store->getId()) && Mage::getStoreConfig('clerk/datasync/magentocron', $store->getId())) { $feedData = array(); $feedData['products'] = $this->__getFeedProductData($store->getId()); $feedData['categories'] = $this->__getFeedCategoryData($store->getId()); if (Mage::getStoreConfig('clerk/datasync/include_historical_salesdata', $store->getId() == -1)) { $feedData['sales'] = $this->__getFeedSalesData($store->getId()); } $feedData['created'] = (int) time(); $filename = Mage::helper('clerk')->getFileName($store); $path = Mage::getBaseDir('media') . "/clerk/feeds/"; $file = new Varien_Io_File(); $file->checkAndCreateFolder($path); $file->open(array('path' => $path)); $file->write($filename, json_encode($feedData, JSON_HEX_QUOT)); Mage::getModel('clerk/communicator')->startImportOfFeed($store->getId()); } } return true; }
/** * Create new image for product and return image filename * * @param int|string $productId * @param array $data * @param string|int $store * @return string */ public function create($productId, $data, $store = null, $identifierType = null) { $data = $this->_prepareImageData($data); $product = $this->_initProduct($productId, $store, $identifierType); $gallery = $this->_getGalleryAttribute($product); if (!isset($data['file']) || !isset($data['file']['mime']) || !isset($data['file']['content'])) { $this->_fault('data_invalid', Mage::helper('catalog')->__('The image is not specified.')); } if (!isset($this->_mimeTypes[$data['file']['mime']])) { $this->_fault('data_invalid', Mage::helper('catalog')->__('Invalid image type.')); } $fileContent = @base64_decode($data['file']['content'], true); if (!$fileContent) { $this->_fault('data_invalid', Mage::helper('catalog')->__('The image contents is not valid base64 data.')); } unset($data['file']['content']); $tmpDirectory = Mage::getBaseDir('var') . DS . 'api' . DS . $this->_getSession()->getSessionId(); if (isset($data['file']['name']) && $data['file']['name']) { $fileName = $data['file']['name']; } else { $fileName = 'image'; } $fileName .= '.' . $this->_mimeTypes[$data['file']['mime']]; $ioAdapter = new Varien_Io_File(); try { // Create temporary directory for api $ioAdapter->checkAndCreateFolder($tmpDirectory); $ioAdapter->open(array('path' => $tmpDirectory)); // Write image file $ioAdapter->write($fileName, $fileContent, 0666); unset($fileContent); // try to create Image object - it fails with Exception if image is not supported try { new Varien_Image($tmpDirectory . DS . $fileName); } catch (Exception $e) { // Remove temporary directory $ioAdapter->rmdir($tmpDirectory, true); throw new Mage_Core_Exception($e->getMessage()); } // Adding image to gallery $file = $gallery->getBackend()->addImage($product, $tmpDirectory . DS . $fileName, null, true); // Remove temporary directory $ioAdapter->rmdir($tmpDirectory, true); $gallery->getBackend()->updateImage($product, $file, $data); if (isset($data['types'])) { $gallery->getBackend()->setMediaAttribute($product, $data['types'], $file); } $product->save(); } catch (Mage_Core_Exception $e) { $this->_fault('not_created', $e->getMessage()); } catch (Exception $e) { $this->_fault('not_created', Mage::helper('catalog')->__('Cannot create image.')); } return $gallery->getBackend()->getRenamedImage($file); }
/** * Open backup file (write or read mode) * * @param bool $write * @return Mage_Backup_Model_Backup */ public function open($write = false) { if (is_null($this->getPath())) { Mage::exception('Mage_Backup', Mage::helper('backup')->__('Backup file path was not specified.')); } $ioAdapter = new Varien_Io_File(); try { $path = $ioAdapter->getCleanPath($this->getPath()); $ioAdapter->checkAndCreateFolder($path); $filePath = $path . DS . $this->getFileName(); } catch (Exception $e) { Mage::exception('Mage_Backup', $e->getMessage()); } if ($write && $ioAdapter->fileExists($filePath)) { $ioAdapter->rm($filePath); } if (!$write && !$ioAdapter->fileExists($filePath)) { Mage::exception('Mage_Backup', Mage::helper('backup')->__('Backup file "%s" does not exist.', $this->getFileName())); } $mode = $write ? 'wb' . self::COMPRESS_RATE : 'rb'; try { $this->_handler = gzopen($filePath, $mode); } catch (Exception $e) { Mage::exception('Mage_Backup', Mage::helper('backup')->__('Backup file "%s" cannot be read from or written to.', $this->getFileName())); } return $this; }
/** * Retrieve absolute path to folder to store wrapping image to * * @return string */ protected function _getImageFolderAbsolutePath() { $path = Mage::getBaseDir('media') . DS . strtr(self::IMAGE_PATH, '/', DS); if (!is_dir($path)) { $ioAdapter = new Varien_Io_File(); $ioAdapter->checkAndCreateFolder($path); } return $path; }
/** * Ensure $dir exists (if not then create one) * * @param string $dir * @throw Mage_Core_Exception */ protected function _verifyDirExist($dir) { try { $ioFile = new Varien_Io_File(); $ioFile->checkAndCreateFolder($dir); } catch (Exception $e) { Mage::throwException($e->getMessage()); } }
/** * Reads directory media/xmlconnect/themes/* * * @param bool $flushCache Reads default color Themes * @return array contains Mage_XmlConnect_Model_Theme */ public function getAllThemes($flushCache = false) { if (!$this->_themeArray || $flushCache) { try { $saveLibxmlErrors = libxml_use_internal_errors(true); $this->_themeArray = array(); $themeDir = $this->getMediaThemePath(); $ioFile = new Varien_Io_File(); $ioFile->checkAndCreateFolder($themeDir); $ioFile->open(array('path' => $themeDir)); $fileList = $ioFile->ls(Varien_Io_File::GREP_FILES); if (!count($fileList) || !$this->_checkDefaultThemes($fileList)) { $this->resetTheme(); $this->getAllThemes(true); } foreach ($fileList as $file) { $src = $themeDir . DS . $file['text']; if (is_readable($src)) { $theme = Mage::getModel('xmlconnect/theme', $src); $this->_themeArray[$theme->getName()] = $theme; } } asort($this->_themeArray); libxml_use_internal_errors($saveLibxmlErrors); } catch (Exception $e) { Mage::logException($e); } } return $this->_themeArray; }
/** * Retrieve custom size image url * * @param string $imageFile * @param int $width * @param int $height * @return string|bool */ public function getCustomSizeImageUrl($imageFile, $width = 100, $height = 100) { /** @var $imageHelper Mage_XmlConnect_Helper_Image */ $imageHelper = Mage::helper('xmlconnect/image'); $screenSize = $width . 'x' . $height; $customDir = $imageHelper->getMediaPath('custom' . DS . $screenSize); $ioFile = new Varien_Io_File(); $ioFile->checkAndCreateFolder($customDir); $filePath = self::getBasePath() . DS . $imageFile; $isImagePng = true; if (!$ioFile->fileExists($filePath)) { return false; } $originalImageType = $this->_getImageType($filePath); if ($originalImageType !== IMAGETYPE_PNG) { $imageFile = $this->_convertFileExtensionToPng($imageFile); $isImagePng = false; } $customSizeFile = $customDir . DS . $imageFile; if (!file_exists($customSizeFile)) { if (!$isImagePng) { $filePath = $this->_forcedConvertPng($filePath, $customSizeFile, $originalImageType); } $image = new Varien_Image($filePath); $widthOriginal = $image->getOriginalWidth(); $heightOriginal = $image->getOriginalHeight(); if ($width != $widthOriginal) { $widthOriginal = $width; } if ($height != $heightOriginal) { $heightOriginal = $height; } if ($widthOriginal != $image->getOriginalWidth() || $heightOriginal != $image->getOriginalHeight()) { $image->keepTransparency(true); $image->keepFrame(true); $image->keepAspectRatio(true); $image->backgroundColor(array(0, 0, 0)); $image->resize($widthOriginal, $heightOriginal); $image->save($customDir, basename($imageFile)); } else { $ioFile->cp($filePath, $customSizeFile); } } return $imageHelper->getMediaUrl("custom/{$screenSize}/" . basename($imageFile)); }
/** * Debug write to file process * * @param string $str */ protected function _debugWriteToFile($str) { $str = '## ' . date('Y-m-d H:i:s') . "\r\n" . $str; if (!$this->_debugIoAdapter) { $this->_debugIoAdapter = new Varien_Io_File(); $dir = Mage::getBaseDir() . DS . $this->_debugIoAdapter->dirname($this->_debugFile); $this->_debugIoAdapter->checkAndCreateFolder($dir); $this->_debugIoAdapter->open(array('path' => $dir)); $this->_debugFile = basename($this->_debugFile); } $this->_debugIoAdapter->streamOpen($this->_debugFile, 'a'); $this->_debugIoAdapter->streamLock(); $this->_debugIoAdapter->streamWrite($str); $this->_debugIoAdapter->streamUnlock(); $this->_debugIoAdapter->streamClose(); }
/** * Get system dir to copy the rating button images to Magento's media dir * '/var/www/magento_shop/media/trustedrating/buttons' * * @return bool */ public function initTrustedRatingRateusButtonMediaDir() { if (is_null($this->_btnMediaDirExists)) { $ioF = new Varien_Io_File(); $dir = Mage::getBaseDir(Mage_Core_Model_Store::URL_TYPE_MEDIA) . DS . Symmetrics_TrustedRating_Model_Trustedrating::RATEUS_BUTTON_IMAGE_SUBPATH; $this->_btnMediaDirExists = $ioF->checkAndCreateFolder($dir); } return $this->_btnMediaDirExists; }
/** * @return string * @throws Exception */ public function getBaseDir() { $io = new Varien_Io_File(); $io->checkAndCreateFolder(Mage::getBaseDir('media') . DS . self::TIMION_ORDERPHOTO_DIR); return Mage::getBaseDir('media') . DS . self::TIMION_ORDERPHOTO_DIR . DS; }
/** * Get captcha image directory * * @param mixed $website * @return string */ public function getImgDir($website = null) { $websiteCode = Mage::app()->getWebsite($website)->getCode(); $captchaDir = Mage::getBaseDir('media') . DS . 'captcha' . DS . $websiteCode . DS; $io = new Varien_Io_File(); $io->checkAndCreateFolder($captchaDir, 0755); return $captchaDir; }
public function getUpdatedCustomerFromFile($lastUpdatedTime) { $customerIds = array(); $dir = Mage::getBaseDir('media') . DS . 'webpos'; $customer_updatedfile = $dir . DS . 'customer_updated.txt'; if (!is_dir_writeable($dir)) { $file = new Varien_Io_File(); $file->checkAndCreateFolder($dir); } $fileContent = file_get_contents($customer_updatedfile); $fileContent = Zend_Json::decode($fileContent); if (count($fileContent) > 0) { foreach ($fileContent as $customerId => $updated_time) { if ($lastUpdatedTime < $updated_time) { $customerIds[] = $customerId; } } } return $customerIds; }
/** * Return URL for resized Item Image * * @param Mymodule_Hello_Model_Hello $item * @param integer $width * @param integer $height * @return bool|string */ public function resize(Mymodule_Hello_Model_Posts $item, $width, $height = null) { if (!$item->getImage()) { return false; } if ($width < self::MIN_WIDTH || $width > self::MAX_WIDTH) { return false; } $width = (int) $width; if (!is_null($height)) { if ($height < self::MIN_HEIGHT || $height > self::MAX_HEIGHT) { return false; } $height = (int) $height; } $imageFile = $item->getImage(); $cacheDir = $this->getBaseDir() . DS . 'cache' . DS . $width; $cacheUrl = $this->getBaseUrl() . '/' . 'cache' . '/' . $width . '/'; $io = new Varien_Io_File(); $io->checkAndCreateFolder($cacheDir); $io->open(array('path' => $cacheDir)); if ($io->fileExists($imageFile)) { return $cacheUrl . $imageFile; } try { $image = new Varien_Image($this->getBaseDir() . DS . $imageFile); $image->resize($width, $height); $image->save($cacheDir . DS . $imageFile); return $cacheUrl . $imageFile; } catch (Exception $e) { Mage::logException($e); return false; } }