示例#1
0
 protected function _loadFiles()
 {
     if (!$this->_isLoaded) {
         $readPath = Mage::getBaseDir("var") . DS . "backups";
         $ioProxy = new Varien_Io_File();
         try {
             $ioProxy->open(array('path' => $readPath));
         } catch (Exception $e) {
             $ioProxy->mkdir($readPath, 0755);
             $ioProxy->chmod($readPath, 0755);
             $ioProxy->open(array('path' => $readPath));
         }
         if (!is_file($readPath . DS . ".htaccess")) {
             // Deny from reading in browser
             $ioProxy->write(".htaccess", "deny from all", 0644);
         }
         $list = $ioProxy->ls(Varien_Io_File::GREP_FILES);
         $fileExtension = constant($this->_itemObjectClass . "::BACKUP_EXTENSION");
         foreach ($list as $entry) {
             if ($entry['filetype'] == $fileExtension) {
                 $item = new $this->_itemObjectClass();
                 $item->load($entry['text'], $readPath);
                 if ($this->_checkCondition($item)) {
                     $this->addItem($item);
                 }
             }
         }
         $this->_totalRecords = count($this->_items);
         if ($this->_totalRecords > 1) {
             usort($this->_items, array(&$this, 'compareByTypeOrDate'));
         }
         $this->_isLoaded = true;
     }
     return $this;
 }
 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);
 }
 private function _printList($cards, $path)
 {
     try {
         $io = new Varien_Io_File();
         $fullPath = Mage::getBaseDir() . $path;
         $parts = pathinfo($fullPath);
         if (!isset($parts['extension']) || strtolower($parts['extension']) != 'csv') {
             Mage::throwException('Error in file extension. Only *.csv files are supported');
         }
         $delimiter = ';';
         $enclosure = '"';
         $io->open(array('path' => $parts['dirname']));
         $io->streamOpen($fullPath, 'w+');
         $io->streamLock(true);
         $header = array('card_id' => 'Gift Card Code', 'amount' => 'Card Amount');
         $io->streamWriteCsv($header, $delimiter, $enclosure);
         $content = array();
         foreach ($cards as $card) {
             $content['card_id'] = $card['code'];
             $content['amount'] = $card['amount'];
             $io->streamWriteCsv($content, $delimiter, $enclosure);
         }
         $io->streamUnlock();
         $io->streamClose();
         $list = Mage::getModel('giftcards/cardslist')->load($fullPath, 'file_path');
         $list->setFilePath($fullPath)->save();
     } catch (Mage_Core_Exception $e) {
         Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
     } catch (Exception $e) {
         Mage::getSingleton('adminhtml/session')->addError(Mage::helper('giftcards')->__('An error occurred while save cards list.'));
     }
 }
示例#4
0
 protected function _generateStoreCss($type, $storeCode)
 {
     if (!Mage::app()->getStore($storeCode)->getIsActive()) {
         return false;
     }
     $fileName = $type . '_' . $storeCode . '.css';
     $file = Mage::helper('legenda/config')->getGeneratedCssDir() . $fileName;
     $templateFile = 'smartwave/legenda/css/' . $type . '.phtml';
     Mage::register('legenda_css_generate_store', $storeCode);
     try {
         $tempalte = Mage::app()->getLayout()->createBlock("core/template")->setData('area', 'frontend')->setTemplate($templateFile)->toHtml();
         if (empty($tempalte)) {
             throw new Exception(Mage::helper('legenda')->__("Template file is empty or doesn't exist: %s", $templateFile));
             return false;
         }
         $io = new Varien_Io_File();
         $io->setAllowCreateFolders(true);
         $io->open(array('path' => Mage::helper('legenda/config')->getGeneratedCssDir()));
         $io->streamOpen($file, 'w+');
         $io->streamLock(true);
         $io->streamWrite($tempalte);
         $io->streamUnlock();
         $io->streamClose();
     } catch (Exception $exception) {
         Mage::getSingleton('adminhtml/session')->addError(Mage::helper('legenda')->__('Failed generating CSS file: %s in %s', $fileName, Mage::helper('legenda/config')->getGeneratedCssDir()) . '<br/>Message: ' . $exception->getMessage());
         Mage::logException($exception);
         return false;
     }
     Mage::unregister('legenda_css_generate_store');
     return true;
 }
示例#5
0
 /**
  * Create additional xml index file with links to other xml files (if number of them more than 1)
  */
 public function createIndexSitemapFile()
 {
     if (sizeof($this->filenamesForIndexSitemap) > 1) {
         $io = new Varien_Io_File();
         $io->setAllowCreateFolders(true);
         $io->open(array('path' => $this->getPath()));
         $fileToCreate = Mage::helper('ascurl')->insertStringToFilename($this->getSitemapFilename(), '_index');
         if ($io->fileExists($fileToCreate) && !$io->isWriteable($fileToCreate)) {
             Mage::throwException(Mage::helper('sitemap')->__('File "%s" cannot be saved. Please, make sure the directory "%s" is writeable by web server.', $fileToCreate, $this->getPath()));
         }
         $io->streamOpen($fileToCreate);
         $io->streamWrite('<?xml version="1.0" encoding="UTF-8"?>' . "\n");
         $io->streamWrite('<sitemapindex ' . self::URLSET . '>');
         $storeId = $this->getStoreId();
         $baseUrl = Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
         $date = Mage::getSingleton('core/date')->gmtDate('Y-m-d');
         $path = $this->getSitemapPath();
         $fullPath = preg_replace('/(?<=[^:])\\/{2,}/', '/', $baseUrl . $path);
         foreach ($this->filenamesForIndexSitemap as $item) {
             $xml = sprintf('<sitemap><loc>%s</loc><lastmod>%s</lastmod></sitemap>', htmlspecialchars($fullPath . $item), $date);
             $io->streamWrite($xml);
         }
         $io->streamWrite('</sitemapindex>');
         $io->streamClose();
     }
 }
示例#6
0
 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');
 }
示例#7
0
 protected function _generateStoreCss($design, $storeCode)
 {
     if (!Mage::app()->getStore($storeCode)->getIsActive()) {
         return;
     }
     $prefix = '_' . $storeCode;
     if ($design == 'layout') {
         $filename = $design . $prefix . '.css';
     } else {
         $filename = $design . $prefix . '.less';
     }
     $filedefault = Mage::helper('dgtyaris/cssgen')->getGeneratedCssDir() . $filename;
     $path = 'dgtthemes/dgtyaris/css/' . $design . '.phtml';
     Mage::register('cssgen_store', $storeCode);
     try {
         $block = Mage::app()->getLayout()->createBlock("core/template")->setData('area', 'frontend')->setTemplate($path)->toHtml();
         if (empty($block)) {
             throw new Exception(Mage::helper('dgtyaris')->__("Template file is empty or doesn't exist: %s", $path));
         }
         $file = new Varien_Io_File();
         $file->setAllowCreateFolders(true);
         $file->open(array('path' => Mage::helper('dgtyaris/cssgen')->getGeneratedCssDir()));
         $file->streamOpen($filedefault, 'w+');
         $file->streamLock(true);
         $file->streamWrite($block);
         $file->streamUnlock();
         $file->streamClose();
     } catch (Exception $gener) {
         Mage::getSingleton('adminhtml/session')->addError(Mage::helper('dgtyaris')->__('Failed generating CSS file: %s in %s', $filename, Mage::helper('dgtyaris/cssgen')->getGeneratedCssDir()) . '<br/>Message: ' . $gener->getMessage());
         Mage::logException($gener);
     }
     Mage::unregister('cssgen_store');
 }
示例#8
0
 /**
  * Load the import data from the csv files
  *
  * @return array
  */
 public function loadData()
 {
     $ioHandler = new Varien_Io_File();
     $ioHandler->open(array('path' => $this->getImportDir()));
     $debitFiles = $ioHandler->ls(Varien_Io_File::GREP_FILES);
     $import = array();
     foreach ($debitFiles as $debitFile) {
         if ($debitFile['filetype'] != 'csv') {
             continue;
         }
         $country = str_replace('.csv', '', $debitFile['text']);
         $country = strtoupper($country);
         $import[$country] = array();
         $i = 1;
         $ioHandler->streamOpen($debitFile['text'], 'r');
         while (($line = $ioHandler->streamReadCsv()) !== false) {
             if ($i == 1) {
                 $i++;
                 continue;
             }
             // Check if routing number already exists
             $swiftCode = trim($line[2]);
             if (array_key_exists($swiftCode, $import[$country]) || empty($swiftCode)) {
                 continue;
             }
             // Add bank to array
             $import[$country][$swiftCode] = array('routing_number' => trim($line[0]), 'swift_code' => $swiftCode, 'bank_name' => trim($line[1]));
         }
         $ioHandler->streamClose();
     }
     return $import;
 }
示例#9
0
 /**
  * Generates CSV file with product's list according to the collection in the $this->_list
  * @return array
  */
 public function generateCollectionList($filename)
 {
     if (!is_null($this->_list)) {
         $items = $this->_list->getItems();
         if (count($items) > 0) {
             $io = new Varien_Io_File();
             $path = Mage::getBaseDir('var') . DS . 'export' . DS . 'specialsubscription';
             $name = $filename;
             //   $name=md5(microtime());
             $file = $path . DS . $name . '.csv';
             $io->setAllowCreateFolders(true);
             $io->open(array('path' => $path));
             $io->streamOpen($file, 'w+');
             $io->streamLock(true);
             $io->streamWriteCsv($this->_getCsvHeaders($items));
             foreach ($items as $item) {
                 $io->streamWriteCsv($item->getData());
             }
             /*    return array(
                       'type'  => 'filename',
                       'value' => $file,
                       'rm'    => false // can delete file after use
                   );*/
             return $file;
         }
     }
 }
 protected function _afterSave()
 {
     if (empty($_FILES['groups']['tmp_name']['general']['fields']['upload_locations']['value'])) {
         return $this;
     }
     $csvFile = $_FILES['groups']['tmp_name']['general']['fields']['upload_locations']['value'];
     $app = Mage::app();
     switch ($this->getData('scope')) {
         case 'websites':
             $website = $app->getWebsite($this->getData('website_code'));
             $storeIds = $website->getStoreIds();
             break;
         case 'stores':
             $storeIds = (array) $app->getStore($this->getData('store_code'))->getId();
             break;
         default:
             $storeIds = (array) $app->getStore()->getId();
             break;
     }
     $this->_importStoreIds = $storeIds;
     $this->_importErrors = array();
     $this->_importedRows = 0;
     $io = new Varien_Io_File();
     $info = pathinfo($csvFile);
     $io->open(array('path' => $info['dirname']));
     $io->streamOpen($info['basename'], 'r');
     $rawHeaders = $io->streamReadCsv();
     $this->validateImportedCoolumns($rawHeaders, $io);
     $this->importDb($io, $rawHeaders);
     return $this;
 }
示例#11
0
文件: Adapter.php 项目: mygento/cdn
 public function getFile($downloadName)
 {
     Varien_Profiler::start('cdn_download_file_' . $downloadName);
     $adapter = $this->getAdapter();
     if ($adapter) {
         $fileName = Mage::helper('mycdn')->getRelativeFile($downloadName);
         $image = $adapter->downloadFile($fileName);
         if ($image) {
             $bn = new Zend_Filter_BaseName();
             $image_name = $bn->filter($downloadName);
             $dn = new Zend_Filter_Dir();
             $image_path = $dn->filter($downloadName);
             $file = new Varien_Io_File();
             $file->setAllowCreateFolders(true);
             $file->open(['path' => $image_path]);
             $file->streamOpen($image_name);
             $file->streamLock(true);
             $file->streamWrite($image);
             $file->streamUnlock();
             $file->streamClose();
             Mage::helper('mycdn')->addLog('[DOWNLOADED] File downloaded to ' . $downloadName);
             Varien_Profiler::stop('cdn_download_file_' . $downloadName);
             //saving to cache
             Mage::helper('mycdn')->savePathInCache($fileName, $this->getUrl($fileName));
             return true;
         } else {
             Mage::helper('mycdn')->addLog('[NOT DOWNLOADED] File not downloaded to ' . $downloadName);
         }
     }
     Varien_Profiler::stop('cdn_download_file_' . $downloadName);
     return false;
 }
示例#12
0
 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));
 }
 /**
  * Export function:
  * - Returns false, if an error occured or if there are no orders to export
  * - Returns array, containing the filename and the file contents
  *
  * @return bool|array
  */
 public function export()
 {
     $collection = $this->_hasOrdersToExport();
     if (!$collection) {
         return false;
     }
     $fileName = $this->getFileName();
     // Open file
     $file = new Varien_Io_File();
     $file->open(array('path' => Mage::getBaseDir('var')));
     $file->streamOpen($fileName);
     // Add headline
     $row = array('Kundenname', 'BLZ', 'Kontonummer', 'BIC/Swift-Code', 'IBAN', 'Betrag', 'Verwendungszweck');
     $file->streamWriteCsv($row);
     // Add rows
     foreach ($collection as $order) {
         /* @var $orderModel Mage_Sales_Model_Order */
         $orderModel = Mage::getModel('sales/order')->load($order->getData('entity_id'));
         /* @var $paymentMethod Itabs_Debit_Model_Debit */
         $paymentMethod = $orderModel->getPayment()->getMethodInstance();
         // Format order amount
         $amount = number_format($order->getData('grand_total'), 2, ',', '.');
         $row = array('name' => $paymentMethod->getAccountName(), 'bank_code' => $paymentMethod->getAccountBLZ(), 'account_number' => $paymentMethod->getAccountNumber(), 'account_swift' => $paymentMethod->getAccountSwift(), 'account_iban' => $paymentMethod->getAccountIban(), 'amount' => $amount . ' ' . $order->getData('order_currency_code'), 'purpose' => 'Bestellung Nr. ' . $order->getData('increment_id'));
         $file->streamWriteCsv($row);
         $this->_getDebitHelper()->setStatusAsExported($order->getId());
     }
     // Close file, get file contents and delete temporary file
     $file->close();
     $filePath = Mage::getBaseDir('var') . DS . $fileName;
     $fileContents = file_get_contents($filePath);
     $file->rm($fileName);
     $response = array('file_name' => $fileName, 'file_content' => $fileContents);
     return $response;
 }
示例#14
0
文件: Order.php 项目: sixg/mkAnagh
 /**
  * Generates CSV file with product's list according to the collection in the $this->_list
  * @return array
  */
 public function getCsvData()
 {
     if (!is_null($this->_list)) {
         $items = $this->_list->getItems();
         if (count($items) > 0) {
             $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);
             $headers = $this->_getCsvHeaders($items);
             $notAllowedValues = array("currency", "base_grand_total", "base_total_paid", "grand_total", "total_paid");
             foreach ($headers as $key => $value) {
                 if (in_array($value, $notAllowedValues)) {
                     unset($headers[$key]);
                 }
             }
             $io->streamWriteCsv($headers);
             foreach ($items as $payment) {
                 $data = $payment->getData();
                 unset($data['currency']);
                 unset($data['base_grand_total']);
                 unset($data['grand_total']);
                 unset($data['total_paid']);
                 unset($data['base_total_paid']);
                 $io->streamWriteCsv($data);
             }
             return array('type' => 'filename', 'value' => $file, 'rm' => true);
         }
     }
 }
 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"));
 }
示例#16
0
 /**
  * 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;
 }
示例#17
0
 public function generateStoreCss($x0c, $x0e = '')
 {
     $x12 = $x0e ? '_' . $x0e : '';
     $x13 = '_' . $x0c . $x12 . '.css';
     $x14 = $this->_cssDirPath . $x13;
     $x15 = 'infortis/ultimo/css/' . $x0c . '.phtml';
     Mage::register('cssgen_store', $x0e);
     try {
         $x16 = Mage::app()->getLayout()->createBlock("core/template")->setData('area', 'frontend')->setTemplate($x15)->toHtml();
         if (empty($x16)) {
             throw new Exception(Mage::helper('ultimo')->__("Template file is empty or doesn't exist: %s", $x15));
         }
         $x17 = new Varien_Io_File();
         $x17->setAllowCreateFolders(true);
         $x17->open(array('path' => $this->_cssDirPath));
         $x17->streamOpen($x14, 'w+');
         $x17->streamLock(true);
         $x17->streamWrite($x16);
         $x17->streamUnlock();
         $x17->streamClose();
         Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('ultimo')->__('CSS file %s has been refreshed', $x13));
     } catch (Exception $x18) {
         Mage::getSingleton('adminhtml/session')->addError(Mage::helper('ultimo')->__('Failed refreshing css file %s in %s', $x13, Mage::helper('ultimo')->getGeneratedCssPath()) . '<br/>Message: ' . $x18->getMessage());
         Mage::logException($x18);
     }
     Mage::unregister('cssgen_store');
 }
示例#18
0
文件: Job.php 项目: mygento/cdn
 /**
  * Upload file to CDN async
  */
 public function uploadFile()
 {
     $adapter = Mage::getModel('mycdn/adapter');
     if (!$adapter) {
         return;
     }
     $ioObject = new Varien_Io_File();
     $ioObject->setAllowCreateFolders(true);
     $ioObject->open(array('path' => $ioObject->dirname($this->getData('filename'))));
     if (!$ioObject->fileExists($this->getData('filename'), true)) {
         Mage::helper('mycdn')->addLog('[CRON] No file ' . $this->getData('filename'));
         $this->delete();
         return;
     }
     //Mage::helper('mycdn')->addLog('[CRON] processing id = ' . $this->getId());
     //Mage::helper('mycdn')->addLog($this->getData());
     $result = $adapter->uploadFile($this->getData('filename'), $this->getData('uploadname'), $this->getData('content_type'));
     if ($result && $this->getData('delete')) {
         $ioObject->rm($this->getData('filename'));
         Mage::helper('mycdn')->addLog('[DELETE] CRON delete for ' . $this->getData('filename'));
     }
     if ($result) {
         Mage::helper('mycdn')->addLog('[JOB] CRON delete job for ' . $this->getData('filename') . "\n");
         $this->delete();
     }
 }
示例#19
0
文件: Pdf.php 项目: AleksNesh/pandora
 /**
  * @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);
 }
示例#20
0
文件: Payment.php 项目: sixg/mkAnagh
 /**
  * Generates CSV file with product's list according to the collection in the $this->_list
  * @return array
  */
 public function getVendorCommision()
 {
     if (!is_null($this->_list)) {
         $items = $this->_list->getItems();
         if (count($items) > 0) {
             $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);
             $headers = $this->_getCsvHeaders($items);
             $io->streamWriteCsv($headers);
             foreach ($items as $payment) {
                 $data = array();
                 $data = $payment->getData();
                 $datafinal = array();
                 foreach ($data as $key => $datavalue) {
                     $val = strip_tags($datavalue);
                     $datafinal[$key] = $val;
                 }
                 $io->streamWriteCsv($datafinal);
             }
             return array('type' => 'filename', 'value' => $file, 'rm' => true);
         }
     }
 }
示例#21
0
 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);
     }
 }
示例#22
0
 protected function _generateStoreCss($x0b, $x0d)
 {
     if (!Mage::app()->getStore($x0d)->getIsActive()) {
         return;
     }
     $x11 = '_' . $x0d;
     $x12 = $x0b . $x11 . '.css';
     $x13 = Mage::helper('ultimo/cssgen')->getGeneratedCssDir() . $x12;
     $x14 = Mage::helper('ultimo/cssgen')->getTemplatePath() . $x0b . '.phtml';
     Mage::register('cssgen_store', $x0d);
     try {
         $x15 = Mage::app()->getLayout()->createBlock("core/template")->setData('area', 'frontend')->setTemplate($x14)->toHtml();
         if (empty($x15)) {
             throw new Exception(Mage::helper('ultimo')->__("Template file is empty or doesn't exist: %s", $x14));
         }
         $x16 = new Varien_Io_File();
         $x16->setAllowCreateFolders(true);
         $x16->open(array('path' => Mage::helper('ultimo/cssgen')->getGeneratedCssDir()));
         $x16->streamOpen($x13, 'w+', 0777);
         $x16->streamLock(true);
         $x16->streamWrite($x15);
         $x16->streamUnlock();
         $x16->streamClose();
     } catch (Exception $x17) {
         Mage::getSingleton('adminhtml/session')->addError(Mage::helper('ultimo')->__('Failed generating CSS file: %s in %s', $x12, Mage::helper('ultimo/cssgen')->getGeneratedCssDir()) . '<br/>Message: ' . $x17->getMessage());
         Mage::logException($x17);
     }
     Mage::unregister('cssgen_store');
 }
示例#23
0
 public function toOptionArray($exclude = true)
 {
     $result = array();
     $result['Magento'] = array('label' => 'Magento');
     $path = Mage::getModuleDir('', 'Mirasvit_SearchIndex') . DS . 'Model' . DS . 'Index';
     $io = new Varien_Io_File();
     $io->open();
     $io->cd($path);
     foreach ($io->ls(Varien_Io_File::GREP_DIRS) as $space) {
         $io->cd($space['id']);
         foreach ($io->ls(Varien_Io_File::GREP_DIRS) as $module) {
             $io->cd($module['id']);
             foreach ($io->ls(Varien_Io_File::GREP_DIRS) as $entity) {
                 if ($io->fileExists($entity['id'] . DS . 'Index.php', true)) {
                     $indexCode = $space['text'] . '_' . $module['text'] . '_' . $entity['text'];
                     $index = Mage::helper('searchindex/index')->getIndexModel($indexCode);
                     if (is_object($index)) {
                         if ($index->canUse()) {
                             if (!isset($result[$index->getBaseGroup()])) {
                                 $result[$index->getBaseGroup()] = array('label' => $index->getBaseGroup(), 'value' => array());
                             }
                             $result[$index->getBaseGroup()]['value'][] = array('value' => $index->getCode(), 'label' => $index->getBaseTitle());
                         }
                     } else {
                         Mage::throwException('Wrong model for index ' . $indexCode);
                     }
                 }
             }
         }
     }
     return $result;
 }
示例#24
0
 protected function generateStoreCss($type, $storeCode)
 {
     if (!Mage::app()->getStore($storeCode)->getIsActive()) {
         return;
     }
     $str1 = '_' . $storeCode;
     $str2 = $type . $str1 . '.css';
     $str3 = Mage::helper('mango/cssconfig')->getCssConfigDir() . $str2;
     $str4 = 'mango/css/' . $type . '.phtml';
     Mage::register('cssgen_store', $storeCode);
     try {
         $block = Mage::app()->getLayout()->createBlock("core/template")->setData('area', 'frontend')->setTemplate($str4)->toHtml();
         if (empty($block)) {
             throw new Exception(Mage::helper('mango')->__("Template file is empty or doesn't exist: %s", $str4));
         }
         $file = new Varien_Io_File();
         $file->setAllowCreateFolders(true);
         $file->open(array('path' => Mage::helper('mango/cssconfig')->getCssConfigDir()));
         $file->streamOpen($str3, 'w+');
         $file->streamLock(true);
         $file->streamWrite($block);
         $file->streamUnlock();
         $file->streamClose();
     } catch (Exception $e) {
         Mage::getSingleton('adminhtml/session')->addError(Mage::helper('mango')->__('Failed generating CSS file: %s in %s', $str2, Mage::helper('mango/cssconfig')->getCssConfigDir()) . '<br/>Message: ' . $e->getMessage());
         Mage::logException($e);
     }
     Mage::unregister('cssgen_store');
 }
示例#25
0
 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);
 }
示例#26
0
 public function massConfigGenAction()
 {
     $configArray = array();
     try {
         $ids = $this->getRequest()->getPost('ids', array());
         foreach ($ids as $id) {
             $model = Mage::getModel("configgen/config")->load($id);
             $configArray[] = $model->getData();
         }
         $output = $this->getLayout()->createBlock('core/template')->setTemplate('proxiblue_configgen.phtml')->setConfigItems($configArray);
         $io = new Varien_Io_File();
         $path = Mage::getBaseDir('var') . DS . 'export' . DS;
         $name = md5(microtime());
         $file = $path . DS . $name . '.php';
         $io->setAllowCreateFolders(true);
         $io->open(array('path' => $path));
         $io->streamOpen($file, 'w+');
         $io->streamLock(true);
         $io->streamWrite($output->toHtml());
         $io->streamUnlock();
         $io->streamClose();
         $this->_prepareDownloadResponse('proxiblue_generated_config.php', array('type' => 'filename', 'value' => $file, 'rm' => true));
         Mage::getSingleton("adminhtml/session")->addSuccess(Mage::helper("adminhtml")->__("Config was generated"));
     } catch (Exception $e) {
         Mage::getSingleton("adminhtml/session")->addError($e->getMessage());
     }
     $this->_redirect('*/*/');
 }
示例#27
0
 /**
  * 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;
 }
 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">');
     $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);
     // Generate filterurl sitemap
     $changefreq = (string) Mage::getStoreConfig('sitemap/category/changefreq', $storeId);
     $priority = (string) Mage::getStoreConfig('sitemap/category/priority', $storeId);
     /* @var $collection Flagbit_FilterUrls_Model_Resource_Mysql4_Url_Collection */
     $collection = Mage::getModel('filterurls/url')->getCollection();
     $collection->addFieldToFilter('store_id', $storeId);
     foreach ($collection as $item) {
         $xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>', htmlspecialchars($baseUrl . $item->getRequestPath()), $date, $changefreq, $priority);
         $io->streamWrite($xml . PHP_EOL);
     }
     $io->streamWrite('</urlset>');
     $io->streamClose();
     $this->setSitemapTime(Mage::getSingleton('core/date')->gmtDate('Y-m-d H:i:s'));
     $this->save();
     return $this;
 }
示例#29
0
 /**
  * Generate sitemap XML file - override to dispatch more events
  *
  * @return $this|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">');
     $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);
     /**
      * 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);
     $categories = new Varien_Object();
     $categories->setItems($collection);
     Mage::dispatchEvent('sitemap_categories_generating_before', array('collection' => $categories));
     foreach ($categories->getItems() as $item) {
         $xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>', htmlspecialchars($baseUrl . $item->getUrl()), $date, $changefreq, $priority);
         $io->streamWrite($xml);
     }
     unset($collection);
     /**
      * Generate products 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);
     $products = new Varien_Object();
     $products->setItems($collection);
     Mage::dispatchEvent('sitemap_products_generating_before', array('collection' => $products));
     foreach ($products->getItems() as $item) {
         $xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>', htmlspecialchars($baseUrl . $item->getUrl()), $date, $changefreq, $priority);
         $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>', 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;
 }
示例#30
0
 /**
  * Move file from tmp path to base path
  *
  * @param string $baseTmpPath
  * @param string $basePath
  * @param string $file
  * @return string
  */
 protected function _moveFileFromTmp($baseTmpPath, $basePath, $file)
 {
     $ioObject = new Varien_Io_File();
     $destDirectory = dirname($this->getFilePath($basePath, $file));
     try {
         $ioObject->open(array('path' => $destDirectory));
     } catch (Exception $e) {
         $ioObject->mkdir($destDirectory, 0777, true);
         $ioObject->open(array('path' => $destDirectory));
     }
     if (strrpos($file, '.tmp') == strlen($file) - 4) {
         $file = substr($file, 0, strlen($file) - 4);
     }
     $destFile = dirname($file) . $ioObject->dirsep() . Varien_File_Uploader::getNewFileName($this->getFilePath($basePath, $file));
     $result = $ioObject->mv($this->getFilePath($baseTmpPath, $file), $this->getFilePath($basePath, $destFile));
     return str_replace($ioObject->dirsep(), '/', $destFile);
 }