public function viewfileAction() { $file = null; $plain = false; if ($this->getRequest()->getParam('file')) { // download file $file = Mage::helper('core')->urlDecode($this->getRequest()->getParam('file')); } else { if ($this->getRequest()->getParam('image')) { // show plain image $file = Mage::helper('core')->urlDecode($this->getRequest()->getParam('image')); $plain = true; } else { return $this->norouteAction(); } } if (strpos($file, 'medma_avatar') !== false) { $path = Mage::getBaseDir('media') . DS . 'medma_avatar' . DS; } else { $path = Mage::getBaseDir('media') . DS . 'customer'; } $ioFile = new Varien_Io_File(); $ioFile->open(array('path' => $path)); $fileName = $ioFile->getCleanPath($path . $file); $path = $ioFile->getCleanPath($path); if ((!$ioFile->fileExists($fileName) || strpos($fileName, $path) !== 0) && !Mage::helper('core/file_storage')->processStorageFile(str_replace('/', DS, $fileName))) { return $this->norouteAction(); } if ($plain) { $extension = pathinfo($fileName, PATHINFO_EXTENSION); switch (strtolower($extension)) { case 'gif': $contentType = 'image/gif'; break; case 'jpg': $contentType = 'image/jpeg'; break; case 'png': $contentType = 'image/png'; break; default: $contentType = 'application/octet-stream'; break; } $ioFile->streamOpen($fileName, 'r'); $contentLength = $ioFile->streamStat('size'); $contentModify = $ioFile->streamStat('mtime'); $this->getResponse()->setHttpResponseCode(200)->setHeader('Pragma', 'public', true)->setHeader('Content-type', $contentType, true)->setHeader('Content-Length', $contentLength)->setHeader('Last-Modified', date('r', $contentModify))->clearBody(); $this->getResponse()->sendHeaders(); while (false !== ($buffer = $ioFile->streamRead())) { echo $buffer; } } else { $name = pathinfo($fileName, PATHINFO_BASENAME); $this->_prepareDownloadResponse($name, array('type' => 'filename', 'value' => $fileName)); } exit; }
public function _ToHtml() { $txt = null; $i = 0; $io = new Varien_Io_File(); $realPath = $io->getCleanPath(Mage::getBaseDir() . $this->getRequest()->getParam('file')); $io->streamOpen($realPath, "r+"); while (false !== ($line = $io->streamRead())) { if (stripos($line, str_replace('__', '&', $this->getRequest()->getParam('s'))) !== FALSE) { $txt .= $line; } } return $txt; }
protected function _loadPatchFile() { $ioAdapter = new Varien_Io_File(); if (!$ioAdapter->fileExists($this->patchFile)) { return; } $ioAdapter->open(array('path' => $ioAdapter->dirname($this->patchFile))); $ioAdapter->streamOpen($this->patchFile, 'r'); while ($buffer = $ioAdapter->streamRead()) { if (stristr($buffer, '|') && stristr($buffer, 'SUPEE')) { list($date, $patch) = array_map('trim', explode('|', $buffer)); $this->appliedPatches[] = $patch; } } $ioAdapter->streamClose(); }
/** * Print output * */ public function output() { if (!$this->exists()) { return; } $ioAdapter = new Varien_Io_File(); $ioAdapter->open(array('path' => $this->getPath())); $ioAdapter->streamOpen($this->getFileName(), 'r'); while ($buffer = $ioAdapter->streamRead()) { echo $buffer; } $ioAdapter->streamClose(); }
/** * Declare headers and content file in response for file download * * @param string $fileName * @param string|array $content set to null to avoid starting output, $contentLength should be set explicitly in * that case * @param string $contentType * @param int $contentLength explicit content length, if strlen($content) isn't applicable * @return Mage_Core_Controller_Varien_Action */ protected function _prepareDownloadResponse($fileName, $content, $contentType = 'application/octet-stream', $contentLength = null) { $session = Mage::getSingleton('admin/session'); if ($session->isFirstPageAfterLogin()) { $this->_redirect($session->getUser()->getStartupPageUrl()); return $this; } $isFile = false; $file = null; if (is_array($content)) { if (!isset($content['type']) || !isset($content['value'])) { return $this; } if ($content['type'] == 'filename') { $isFile = true; $file = $content['value']; $contentLength = filesize($file); } } $this->getResponse()->setHttpResponseCode(200)->setHeader('Pragma', 'public', true)->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)->setHeader('Content-type', $contentType, true)->setHeader('Content-Length', is_null($contentLength) ? strlen($content) : $contentLength, true)->setHeader('Content-Disposition', 'attachment; filename="' . $fileName . '"', true)->setHeader('Last-Modified', date('r'), true); if (!is_null($content)) { if ($isFile) { $this->getResponse()->clearBody(); $this->getResponse()->sendHeaders(); $ioAdapter = new Varien_Io_File(); $ioAdapter->open(array('path' => $ioAdapter->dirname($file))); $ioAdapter->streamOpen($file, 'r'); while ($buffer = $ioAdapter->streamRead()) { print $buffer; } $ioAdapter->streamClose(); if (!empty($content['rm'])) { $ioAdapter->rm($file); } exit(0); } else { $this->getResponse()->setBody($content); } } return $this; }
protected function _afterSave() { set_time_limit(60000); ini_set('max_execution_time', 60000); ini_set('memory_limit', '512M'); if (empty($_FILES['groups']['tmp_name']['export_import']['fields']['upload_productrestriction']['value'])) { return $this; } $csvFile = $_FILES['groups']['tmp_name']['export_import']['fields']['upload_productrestriction']['value']; $this->_importedRows = 0; $io = new Varien_Io_File(); $info = pathinfo($csvFile); $io->open(array('path' => $info['dirname'])); $io->streamOpen($info['basename'], 'r'); $hlp = Mage::helper('productrestriction'); $zipcodearray = array(); $resource = Mage::getSingleton('core/resource'); $tablename = $resource->getTableName('productrestriction'); $model = Mage::getModel('productrestriction/productrestriction'); $writeConnection = $resource->getConnection('core_write'); try { $rowNumber = 0; $rowNumberCount = 0; $pkj = 0; $query = " values "; $importData = array(); $this->deletePrevious(); while (false !== ($csvLinecount = $io->streamRead())) { $rowNumberCount++; } $rowNumberCount = $rowNumberCount - 1; $io->streamClose(); $io->streamOpen($info['basename'], 'r'); while (false !== ($csvLine = $io->streamRead())) { $rowNumber++; $pkj++; if ($rowNumber != 1) { $csvLinedata = explode(',', $csvLine); $actual_data = $csvLinedata; $isExist = 0; $zipcode = trim(preg_replace('/\\s+/', ' ', $actual_data[0])); if (in_array($zipcode, $zipcodearray)) { $isExist = 1; } else { $zipcodearray[] = $zipcode; } if ($isExist == 0) { $new_data = array(); $new_data['pin_code'] = $zipcode; // trim(preg_replace('/\s+/',' ', $actual_data[0])); $new_data['city'] = str_replace('"', '', trim(preg_replace('/\\s+/', ' ', $actual_data[1]))); $new_data['delivery_days'] = str_replace('"', '', trim(preg_replace('/\\s+/', ' ', $actual_data[2]))); $new_data['cod'] = trim(preg_replace('/\\s+/', ' ', $actual_data[3])); $query .= " (\r\n '" . $new_data['pin_code'] . "',\r\n '" . $new_data['city'] . "',\r\n '" . $new_data['delivery_days'] . "',\r\n \t'" . $new_data['cod'] . "'),"; } if ($rowNumberCount < 500) { if ($rowNumber == $rowNumberCount + 1) { $final_query = "INSERT into " . $tablename . " (pin_code,city,delivery_days,cod) " . trim($query, ','); $writeConnection->query($final_query); $query = " values "; $pkj = 0; } } elseif ($rowNumber > $rowNumberCount - 500) { if ($rowNumber == $rowNumberCount + 1) { $final_query = "INSERT into " . $tablename . " (pin_code,city,delivery_days,cod) " . trim($query, ','); $writeConnection->query($final_query); $query = " values "; $pkj = 0; } } else { if ($pkj == 500) { $final_query = "INSERT into " . $tablename . " (pin_code,city,delivery_days,cod) " . trim($query, ','); $writeConnection->query($final_query); $query = " values "; $pkj = 0; } } } } Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Zipcode imported successfully')); } catch (Mage_Core_Exception $e) { //$adapter->rollback(); $io->streamClose(); Mage::throwException($e->getMessage()); } catch (Exception $e) { //$adapter->rollback(); $io->streamClose(); Mage::logException($e); Mage::throwException($hlp->__('An error occurred while importing ' . $tablename . '.')); } }
public function categoriesAction() { $i = 0; $io = new Varien_Io_File(); $realPath = $io->getCleanPath(Mage::getBaseDir() . "/lib/Google/taxonomy.txt"); $io->streamOpen($realPath, "r+"); while (false !== ($line = $io->streamRead())) { if (stripos($line, $this->getRequest()->getParam('s')) !== FALSE) { echo $line; } } die; }
/** * Declare headers and content file in response for file download * * @param string $fileName * @param string|array $content set to null to avoid starting output, $contentLength should be set explicitly in * that case * @param string $contentType * @param int $contentLength explicit content length, if strlen($content) isn't applicable * @return Mage_Core_Controller_Varien_Action */ protected function _prepareDownloadResponse($fileName, $content, $contentType = 'application/octet-stream', $contentLength = null) { $isFile = false; $file = null; if (is_array($content)) { if (!isset($content['type']) || !isset($content['value'])) { return $this; } if ($content['type'] == 'filename') { $isFile = true; $file = $content['value']; $contentLength = filesize($file); } } $this->getResponse()->setHttpResponseCode(200)->setHeader('Pragma', 'public', true)->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)->setHeader('Content-type', $contentType, true)->setHeader('Content-Length', is_null($contentLength) ? strlen($content) : $contentLength, true)->setHeader('Content-Disposition', 'attachment; filename="' . $fileName . '"', true)->setHeader('Last-Modified', date('r'), true); if (!is_null($content)) { if ($isFile) { $this->getResponse()->clearBody(); $this->getResponse()->sendHeaders(); $ioAdapter = new Varien_Io_File(); if (!$ioAdapter->fileExists($file)) { Mage::throwException(Mage::helper('Mage_Core_Helper_Data')->__('File not found')); } $ioAdapter->open(array('path' => $ioAdapter->dirname($file))); $ioAdapter->streamOpen($file, 'r'); while ($buffer = $ioAdapter->streamRead()) { print $buffer; } $ioAdapter->streamClose(); if (!empty($content['rm'])) { $ioAdapter->rm($file); } exit(0); } else { $this->getResponse()->setBody($content); } } return $this; }
/** * Print output * */ public function output() { if (!$this->isFileExists()) { return; } $ioAdapter = new Varien_Io_File(); $ioAdapter->open(array('path' => Mage::getBaseDir('media') . DS . 'resumes')); $ioAdapter->streamOpen($this->getFilename(), 'r'); while ($buffer = $ioAdapter->streamRead()) { echo $buffer; } $ioAdapter->streamClose(); }
public function importProcess() { $x7a = "stristr"; $x7b = "is_readable"; $x7c = "time"; $x7d = "file_get_contents"; $x7e = "in_array"; $x7f = "implode"; $x80 = "array_key_exists"; $x81 = "trim"; $x82 = "str_replace"; $x83 = "log"; $x84 = "is_array"; $x85 = "json_encode"; $x86 = "json_decode"; $x87 = "array_splice"; $x88 = "array_unshift"; $x89 = "count"; $x8a = "is_numeric"; $x8b = "array_push"; $x8c = "strtolower"; $x8d = "strstr"; $x8e = "explode"; $x8f = "addslashes"; Mage::$x83("-------------------- IMPORTATION PROCESS ---------------", null, "MassStockUpate.{$x83}"); $this->x90(); $x4a = $this->getFilePath(); if ($this->getFileSystemType() === "1") { $x3b = $this->x91(); if ($x84($x3b)) { $x4b['status'] = 'error'; $x4b['body'] = $x3b[0]; die($x85($x4b)); } else { $x4a = $x3b; } } $x31 = new Varien_Io_File(); $x32 = $x31->getCleanPath(Mage::getBaseDir() . "/" . $x4a); if ($this->getFileType() === "1") { $x49 = $this->x92($x32, $this->getXpathToProduct()); if ($x84($x49)) { $x4b['status'] = 'error'; $x4b['body'] = $x49[0]; die($x85($x4b)); } $x32 = $x31->getCleanPath(Mage::getBaseDir() . '/' . $x49); } $x31->streamOpen($x32, "r"); Mage::$x83("--> File opened : " . $x32, null, "MassStockUpate.{$x83}"); $x4c = $this->getIdentifierCode() ? $this->getIdentifierCode() : "sku"; $x41 = Mage::getModel("catalog/product")->getCollection()->addAttributeToSelect($x4c); foreach ($x41 as $x4d) { $this->_products[$x81($x4d->getData($x4c))] = $x4d->getId(); } Mage::$x83("--> Products collected", null, "MassStockUpate.{$x83}"); if (Mage::helper("core")->isModuleEnabled("Wyomind_Advancedinventory")) { $x4e = Mage::getModel("advancedinventory/stock")->getCollection(); foreach ($x4e as $x4f) { $this->_stocks[$x4f->getProductId()] = $x4f->getId(); } Mage::$x83("--> Local stocks collected (Advanced Inventory)", null, "MassStockUpate.{$x83}"); } $x50 = array("ac" => "activation_code", "ak" => "activation_key", "bu" => "base_url", "md" => "md5", "th" => "this", "dm" => "_demo", "ext" => "msi", "ver" => "3.9.2"); $x51 = Mage::getSingleton("core/resource"); $x52 = $x51->getConnection("core_read"); $this->_tables["csi"] = Mage::getSingleton("core/resource")->getTableName("cataloginventory_stock_item"); if (Mage::helper("core")->isModuleEnabled("Wyomind_Advancedinventory")) { $this->_tables["aip"] = Mage::getSingleton("core/resource")->getTableName("advancedinventory_item"); $this->_tables["ais"] = Mage::getSingleton("core/resource")->getTableName("advancedinventory_stock"); $x53 = "SELECT MAX(id) AS INC FROM " . $this->_tables["aip"] . " ;"; $x54 = $x52->fetchAll($x53); $this->_autoInc = $x54[0]["INC"]; Mage::$x83("--> Max increment found #" . $x54[0]["INC"] . "(Advanced Inventory)", null, "MassStockUpate.{$x83}"); } $x55 = array("activation_key" => Mage::getStoreConfig("massstockupdate/license/activation_key"), "activation_code" => Mage::getStoreConfig("massstockupdate/license/activation_code"), "base_url" => Mage::getStoreConfig("web/secure/base_url")); $x40 = $x86($this->getMapping()); foreach ($x40->columns as $x44 => $x56) { if (!$x7e($x56->id, array("not-used", "total", "is_in_stock", "manage_local_stock"))) { $this->_columns[] = $x56->id; } elseif ($x7e($x56->id, array("total"))) { $this->_columns[] = "total"; $this->_total = $x44 + 1; } elseif ($x7e($x56->id, array("is_in_stock"))) { $this->_columns[] = "is_in_stock"; $this->_is_in_stock = $x44 + 1; } elseif ($x7e($x56->id, array("manage_local_stock"))) { $this->_columns[] = "manage_local_stock"; $this->_manage_local_stock = $x44 + 1; } else { $this->_columns[] = false; } } Mage::$x83("--> Column mapping analyzed", null, "MassStockUpate.{$x83}"); if ($x55[$x50["ac"]] != $x50["md"]($x50["md"]($x55[$x50["ak"]]) . $x50["md"]($x55[$x50["bu"]]) . $x50["md"]($x50["ext"]) . $x50["md"]($x50["ver"]))) { ${$x50}["ext"] = "valid"; ${$x50}["th"]->{$x50}["dm"] = true; } else { ${$x50}["th"]->{$x50}["dm"] = false; ${$x50}["ext"] = "valid"; } if (!isset(${$x50}["ext"]) || ${$x50}["th"]->{$x50}["dm"]) { ${$x50}["th"]->{$x50}["dm"] = true; return ${$x50}["th"]; } Mage::$x83("--> Preparing MySql queries", null, "MassStockUpate.{$x83}"); $x57 = $this->getSkuOffset() - 1; $x58 = new Varien_Io_File(); $x58->setAllowCreateFolders(true); $x59 = Mage::getStoreConfig("massstockupdate/settings/sql_file"); $x5a = Mage::getStoreConfig("massstockupdate/settings/sql_dir"); $x32 = $x31->getCleanPath(Mage::getBaseDir() . '/' . $x5a); if (!$x58->fileExists($x32, false)) { Mage::throwException(Mage::helper('massstockupdate')->__('Please create the specified folder "%s".', $x32)); } if (!$x58->isWriteable($x32)) { Mage::throwException(Mage::helper('massstockupdate')->__('Please make sure that "%s" is writable by web-server.', $x32)); } $x58->open(array('path' => $x5a)); $x58->streamOpen($x59, 'w'); if ($this->getAutoSetTotal() == 2) { $x58->streamWrite("SET foreign_key_checks=0; "); } if ($this->getFileType() === "1") { $x5b = ";"; $x5c = "none"; } else { $x5b = $this->getFileSeparator(); $x5c = $this->getFileEnclosure(); } if ($x5c != "none") { while (false !== ($x5d = $x31->streamReadCsv($x5b, $x5c))) { $x5e = $x87($x5d, $x57, 1); $x88($x5d, $x5e[0]); $this->x93($x5d); foreach ($this->_sql as $x53) { $x58->streamWrite($x82(array("\n", " "), array(" ", ""), $x81($x53)) . "\n"); } } } else { while (false !== ($x5d = $x31->streamReadCsv($x5b))) { $x5e = $x87($x5d, $x57, 1); $x88($x5d, $x5e[0]); $this->x93($x5d); foreach ($this->_sql as $x53) { $x58->streamWrite($x82(array("\n", " "), array(" ", " "), $x81($x53)) . "\n"); } } } Mage::$x83("--> File closed : " . $x32 . $x59, null, "MassStockUpate.{$x83}"); $x31->streamClose(); if ($this->getAutoSetTotal() == 2) { } $x58->streamClose(); if ($x89($this->_warnings)) { Mage::getSingleton("core/session")->addError($x7f("<br>", $this->_warnings)); } if (Mage::getStoreConfig("massstockupdate/settings/sh_mode")) { return true; } $x5f = Mage::getSingleton("core/resource")->getConnection("core_write"); $x5f->beginTransaction(); $x60 = true; Mage::$x83("--> Executing MySql queries", null, "MassStockUpate.{$x83}"); $x31 = new Varien_Io_File(); $x31->streamOpen($x32 . $x59, "r"); while (false !== ($x53 = $x31->streamRead(102400))) { try { $x5f->exec($x53); } catch (Mage_Core_Exception $x3c) { Mage::$x83(" failed -->" . $x53, null, "MassStockUpate.{$x83}"); $x60 = false; } catch (Exception $x3c) { Mage::$x83(" failed -->" . $x53, null, "MassStockUpate.{$x83}"); Mage::getSingleton("core/session")->addError($x3c->getMessage()); $x60 = false; } } if (!$x60) { Mage::$x83("--> MySql Rollback", null, "MassStockUpate.{$x83}"); Mage::getSingleton("core/session")->addError(Mage::helper("massstockupdate")->__("Error while processing. Rollback happened.")); $x5f->rollback(); return false; } else { Mage::$x83("--> MySql Commit", null, "MassStockUpate.{$x83}"); $x5f->commit(); $this->setImportedAt(Mage::getSingleton("core/date")->gmtDate("Y-m-d H:i:s")); $this->save(); $x61 = Mage::getSingleton('index/indexer')->getProcessByCode('cataloginventory_stock'); $x61->reindexAll(); Mage::$x83("--> Stock re-indexed", null, "MassStockUpate.{$x83}"); $x31->open(array('path' => $x5a)); $x31->rm($x59); return true; } }
public function output() { if (!$this->exists()) { Mage::throwException(Mage::helper('mailchimp')->__("File does not exist.")); return; } $ioAdapter = new Varien_Io_File(); $ioAdapter->open(array('path' => $this->getPath())); $ioAdapter->streamOpen($this->getFileName(), 'r'); while ($buffer = $ioAdapter->streamRead()) { echo $buffer; } $ioAdapter->streamClose(); }