/**
  * Rotate all files in var/log which ends with .log
  */
 public function rotateLogs()
 {
     $var = Mage::getBaseDir('log');
     $logDir = new Varien_Io_File();
     $logDir->cd($var);
     $logFiles = $logDir->ls(Varien_Io_File::GREP_FILES);
     foreach ($logFiles as $logFile) {
         if ($logFile['filetype'] == 'log') {
             $filename = $logFile['text'];
             if (extension_loaded('zlib')) {
                 $zipname = $var . DS . $this->getArchiveName($filename);
                 $zip = gzopen($zipname, 'wb9');
                 gzwrite($zip, $logDir->read($filename));
                 gzclose($zip);
             } else {
                 $logDir->cp($filename, $this->getArchiveName($filename));
             }
             foreach ($this->getFilesOlderThan(self::MAX_FILE_DAYS, $var, $filename) as $oldFile) {
                 $logDir->rm($oldFile['text']);
             }
             $logDir->rm($filename);
         }
     }
     $logDir->close();
 }
示例#2
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);
 }
示例#3
0
 /**
  * Retrieve translated template file
  * Try current design package first
  *
  * @param string $file
  * @param string $type
  * @param string $localeCode
  * @return string
  */
 public function getTemplateFile($file, $type, $localeCode = null)
 {
     if (is_null($localeCode) || preg_match('/[^a-zA-Z_]/', $localeCode)) {
         $localeCode = $this->getLocale();
     }
     $filePath = $this->getLocaleOverrideFile($localeCode, 'template' . DS . $type . DS . $file);
     if (empty($filePath) || !file_exists($filePath)) {
         return parent::getTemplateFile($file, $type, $localeCode);
     }
     $ioAdapter = new Varien_Io_File();
     $ioAdapter->open(array('path' => Mage::getBaseDir('locale')));
     return (string) $ioAdapter->read($filePath);
 }
示例#4
0
文件: File.php 项目: buttasg/cowgirlk
    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;
    }
示例#5
0
 public function saveFileContentToConfig($file, $field)
 {
     $adminsession = Mage::getSingleton('adminhtml/session');
     $io = new Varien_Io_File();
     $io->open(array('path' => Mage::getBaseDir()));
     if ($io->fileExists($file)) {
         try {
             $contents = $io->read($file);
             Mage::getModel('core/config')->saveConfig('creare' . $field . '/files/' . $field, $contents);
         } catch (Mage_Core_Exception $e) {
             $adminsession->addError($e->getMessage());
         }
     } else {
         $adminsession->addError($file . " does not exist. Please create this file on your domain root to use this feature.");
     }
     $io->streamClose();
 }
示例#6
0
 /**
  * Validates the file supplied via the file param to ensure the hash values for each param match the current value of
  * the configuration variable in Magento.
  * This cron job will only output a message if there is a validation error or if debug mode is enabled
  */
 protected function validate()
 {
     $lockFileName = $this->getArg('file');
     $invalidKeys = array();
     if ($lockFileName) {
         $inFile = new Varien_Io_File();
         $inFile->open(array('path' => dirname($lockFileName)));
         $lockData = null;
         $lockData = $inFile->read(basename($lockFileName));
         if (!$lockData) {
             $this->fatal("Unable to read supplied file");
         }
         $lockData = json_decode($lockData, true);
         foreach ($lockData['hashes'] as $storeCode => $hashes) {
             $this->debug($storeCode);
             foreach ($hashes as $configKey => $configValueHash) {
                 $store = Mage::getModel("core/store")->load($storeCode, "code");
                 $configValue = Mage::getStoreConfig($configKey, $store);
                 if (password_verify($configValue, $configValueHash)) {
                     $this->debug($configKey . " is valid");
                 } else {
                     $this->error($configKey . " is NOT valid\n");
                     $invalidKeys[] = $configKey;
                 }
             }
         }
         if (count($invalidKeys) > 0) {
             /*
              * Check if the mandrill API key was encoded into the lock file. If found, use it to send emails in case
              *  it has been modified via the admin to prevent notifications
              */
             if (array_key_exists('mandrillApiKey', $lockData) && !empty($lockData['mandrillApiKey'])) {
                 Mage::app()->getStore()->setConfig("mandrill/general/apikey", Mage::helper('core')->decrypt($lockData['mandrillApiKey']));
                 Mage::app()->getStore()->setConfig("mandrill/general/active", 'true');
             }
             $this->notifyFailures($lockData['emails'], implode(",", $invalidKeys));
             die(1);
         }
     } else {
         $this->fatal('Must supply "file" argument to read lock file');
     }
 }
 /**
  * Retrive translated template file
  *
  * @param string $file
  * @param string $type
  * @param string $localeCode
  * @return string
  */
 public function getTemplateFile($file, $type, $localeCode = null)
 {
     if (is_null($localeCode) || preg_match('/[^a-zA-Z_]/', $localeCode)) {
         $localeCode = $this->getLocale();
     }
     $filePath = Mage::getBaseDir('locale') . DS . $localeCode . DS . 'template' . DS . $type . DS . $file;
     if (!file_exists($filePath)) {
         // If no template specified for this locale, use store default
         $filePath = Mage::getBaseDir('locale') . DS . Mage::app()->getLocale()->getDefaultLocale() . DS . 'template' . DS . $type . DS . $file;
     }
     if (!file_exists($filePath)) {
         // If no template specified as  store default locale, use en_US
         $filePath = Mage::getBaseDir('locale') . DS . Mage_Core_Model_Locale::DEFAULT_LOCALE . DS . 'template' . DS . $type . DS . $file;
     }
     $ioAdapter = new Varien_Io_File();
     $ioAdapter->open(array('path' => Mage::getBaseDir('locale')));
     return (string) $ioAdapter->read($filePath);
 }
 /**
  * Cache the widget images.
  *
  * @param string $type type
  * @param string $tsId Trusted Rating Id
  *
  * @return void
  */
 private function _cacheImageData($type, $tsId = null)
 {
     $ioObject = new Varien_Io_File();
     $ioObject->open();
     if ($type == 'emailWidget') {
         $emailWidgetName = $this->getRatingLinkData('emailratingimage');
         $readPath = self::EMAIL_WIDGET_LINK . $emailWidgetName;
         $writePath = self::IMAGE_LOCAL_PATH . $emailWidgetName;
         $cacheId = self::EMAIL_CACHEID;
     } else {
         $readPath = self::WIDGET_LINK . $tsId . self::WIDGET_FILE_SUFFIX;
         $writePath = self::IMAGE_LOCAL_PATH . $tsId . self::WIDGET_FILE_SUFFIX;
         $cacheId = self::CACHEID;
     }
     $result = $ioObject->read($readPath);
     $ioObject->write($writePath, $result);
     Mage::app()->saveCache($writePath, $cacheId, array(), 1);
     $ioObject->close();
 }
示例#9
0
 /**
  * Run webservice
  *
  * @param Mage_Api_Controller_Action $controller
  * @return Mage_Api_Model_Server_Adapter_Soap
  */
 public function run()
 {
     $apiConfigCharset = Mage::getStoreConfig("api/config/charset");
     if ($this->getController()->getRequest()->getParam('wsdl') !== null) {
         // Generating wsdl content from template
         $io = new Varien_Io_File();
         $io->open(array('path' => Mage::getModuleDir('etc', 'Mage_Api')));
         $wsdlContent = $io->read('wsdl.xml');
         $template = Mage::getModel('core/email_template_filter');
         $wsdlConfig = new Varien_Object();
         $queryParams = $this->getController()->getRequest()->getQuery();
         if (isset($queryParams['wsdl'])) {
             unset($queryParams['wsdl']);
         }
         $wsdlConfig->setUrl(htmlspecialchars(Mage::getUrl('*/*/*', array('_query' => $queryParams))));
         $wsdlConfig->setName('Magento');
         $wsdlConfig->setHandler($this->getHandler());
         $template->setVariables(array('wsdl' => $wsdlConfig));
         $this->getController()->getResponse()->clearHeaders()->setHeader('Content-Type', 'text/xml; charset=' . $apiConfigCharset)->setBody(preg_replace('/<\\?xml version="([^\\"]+)"([^\\>]+)>/i', '<?xml version="$1" encoding="' . $apiConfigCharset . '"?>', $template->filter($wsdlContent)));
     } else {
         try {
             $this->_instantiateServer();
             $this->getController()->getResponse()->clearHeaders()->setHeader('Content-Type', 'text/xml; charset=' . $apiConfigCharset)->setBody(preg_replace('/<\\?xml version="([^\\"]+)"([^\\>]+)>/i', '<?xml version="$1" encoding="' . $apiConfigCharset . '"?>', $this->_soap->handle()));
         } catch (Zend_Soap_Server_Exception $e) {
             $this->fault($e->getCode(), $e->getMessage());
         } catch (Exception $e) {
             $this->fault($e->getCode(), $e->getMessage());
         }
     }
     return $this;
 }
示例#10
0
 /**
  * Run webservice
  *
  * @param Mage_Api_Controller_Action $controller
  * @return Mage_Api_Model_Server_Adapter_Soap
  */
 public function run()
 {
     if ($this->getController()->getRequest()->getParam('wsdl')) {
         // Generating wsdl content from template
         $io = new Varien_Io_File();
         $io->open(array('path' => Mage::getModuleDir('etc', 'Mage_Api')));
         $wsdlContent = $io->read('wsdl.xml');
         $template = Mage::getModel('core/email_template_filter');
         $wsdlConfig = new Varien_Object();
         $wsdlConfig->setUrl(Mage::getUrl('*/*/*'));
         $wsdlConfig->setName('Magento');
         $wsdlConfig->setHandler($this->getHandler());
         $template->setVariables(array('wsdl' => $wsdlConfig));
         $this->getController()->getResponse()->setHeader('Content-Type', 'text/xml')->setBody($template->filter($wsdlContent));
     } elseif ($this->_extensionLoaded()) {
         $this->_soap = new SoapServer(Mage::getUrl('*/*/*', array('wsdl' => 1)));
         use_soap_error_handler(false);
         $this->_soap->setClass($this->getHandler());
         $this->getController()->getResponse()->setHeader('Content-Type', 'text/xml')->setBody($this->_soap->handle());
     } else {
         $this->fault('0', 'Unable to load Soap extension on the server');
     }
     return $this;
 }
示例#11
0
 /**
  * Retrieve file content from file container array
  *
  * @param array $fileData
  * @return string
  */
 protected function _getFileContainerContent(array $fileData)
 {
     $io = new Varien_Io_File();
     $path = $io->dirname($fileData['value']);
     $io->open(array('path' => $path));
     return $io->read($fileData['value']);
 }
示例#12
0
文件: Data.php 项目: booklein/bookle
 public function readSampleFile($folder, $filepath = "")
 {
     $result = "";
     if ($filepath) {
         $flocal = new Varien_Io_File();
         $flocal->open(array('path' => $folder));
         $result = $flocal->read($filepath);
     }
     return $result;
 }
示例#13
0
 /**
  * Retrive translated template file
  * line 460 in Mage_Core_Model_Translate
  *
  * @modified_by MaWoScha <*****@*****.**>
  * @param string $file
  * @param string $type
  * @param string $localeCode
  * @return string
  */
 public function getTemplateFile($file, $type, $localeCode = null)
 {
     if (is_null($localeCode) || preg_match('/[^a-zA-Z_]/', $localeCode)) {
         $localeCode = $this->getLocale();
     }
     $filePath = Mage::getBaseDir('locale') . DS . $localeCode . DS . 'template' . DS . $type . DS . $file;
     /** START - MaWoScha */
     if (!file_exists($filePath)) {
         // If template doesn't exist for this locale, use fallback locale
         $filePath = Mage::getBaseDir('locale') . DS . Mage::getStoreConfig('general/locale/code_fallback') . DS . 'template' . DS . $type . DS . $file;
     }
     /** END - MaWoScha */
     if (!file_exists($filePath)) {
         // If template doesn't exist for fallback locale, use store default
         $filePath = Mage::getBaseDir('locale') . DS . Mage::app()->getLocale()->getDefaultLocale() . DS . 'template' . DS . $type . DS . $file;
     }
     if (!file_exists($filePath)) {
         // If template doesn't exist for store default, use en_US
         $filePath = Mage::getBaseDir('locale') . DS . Mage_Core_Model_Locale::DEFAULT_LOCALE . DS . 'template' . DS . $type . DS . $file;
     }
     $ioAdapter = new Varien_Io_File();
     $ioAdapter->open(array('path' => Mage::getBaseDir('locale')));
     return (string) $ioAdapter->read($filePath);
 }
示例#14
0
 public function getContentCustomCss()
 {
     $output = "";
     $theme = Mage::registry('theme_data')->get('group');
     $tmp_theme = explode("/", $theme);
     if (count($tmp_theme) == 1) {
         $theme = "default/" . $tmp_theme;
     }
     if ($theme) {
         $custom_css_path = Mage::getBaseDir('skin') . "/frontend/" . $theme . "/css/local/custom.css";
         if (is_file($custom_css_path) && file_exists($custom_css_path)) {
             $file = new Varien_Io_File();
             $file->open(array('path' => Mage::getBaseDir('skin') . "/frontend/" . $theme . "/css/local/"));
             //$flocal->streamOpen('customers.txt', 'r');
             $output = $file->read(Mage::getBaseDir('skin') . "/frontend/" . $theme . "/css/local/custom.css");
             $file->close();
         }
     }
     return $output;
 }
示例#15
0
 public function buildFeeds($storeId, $type, $page)
 {
     $store = Mage::app()->getStore($storeId);
     if (Mage::getStoreConfig('clerk/settings/active', $store->getId())) {
         $feedData = array();
         if ($type == 'products') {
             $feedData[$type] = $this->__getFeedProductData($store->getId(), $page);
         }
         if ($type == 'categories') {
             $feedData[$type] = $this->__getFeedCategoryData($store->getId(), $page);
         }
         if ($type == 'sales') {
             $feedData[$type] = $this->__getFeedSalesData($store->getId(), $page);
         }
         if ($type != 'done') {
             $filename_tmp = Mage::helper('clerk')->getFileName($store, $tmp = true);
             $path = Mage::getBaseDir('media') . "/clerk/feeds/";
             $file = new Varien_Io_File();
             $file->checkAndCreateFolder($path);
             $file->open(array('path' => $path));
             if (file_exists($path . $filename_tmp)) {
                 $content = $file->read($filename_tmp);
                 $json = json_decode($content, true);
                 if (isset($json[$type])) {
                     if ($type == 'products') {
                         $add = true;
                         foreach ($json[$type] as $item_added) {
                             if ($item_added['id'] == $feedData[$type][0]['id']) {
                                 $add = false;
                                 break;
                             }
                         }
                         if ($add) {
                             $json[$type] = array_merge($json[$type], $feedData[$type]);
                         }
                     } else {
                         $json[$type] = array_merge($json[$type], $feedData[$type]);
                     }
                 } else {
                     $json[$type] = $feedData[$type];
                 }
                 $json['created'] = (int) time();
                 $file->write($filename_tmp, json_encode($json, JSON_HEX_QUOT));
             } else {
                 $feedData['created'] = (int) time();
                 $file->write($filename_tmp, json_encode($feedData, JSON_HEX_QUOT));
             }
         } else {
             $filename_tmp = Mage::helper('clerk')->getFileName($store, $tmp = true);
             $filename = Mage::helper('clerk')->getFileName($store, $tmp = false);
             $path = Mage::getBaseDir('media') . "/clerk/feeds/";
             $file = new Varien_Io_File();
             $file->checkAndCreateFolder($path);
             $file->open(array('path' => $path));
             $file->mv($filename_tmp, $filename);
             Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('clerk')->__("Done building feed. Data stored in %s", $filename));
             Mage::getModel('clerk/communicator')->startImportOfFeed($storeId);
         }
     }
     return true;
 }
 /**
  * Read nfe
  *
  * @return string
  */
 public function read()
 {
     $io = new Varien_Io_File();
     return $io->read($this->_path . $this->_getFileName());
 }
示例#17
0
 public function checkLicense($product, $key, $update = false)
 {
     return true;
     //        if ($update)
     //            $this->checkUpdate();
     # Get Variables from storage (retrieve from wherever it's stored - DB, file, etc...)
     $session = Mage::getSingleton('adminhtml/session');
     $msgs = $session->getMessages(true);
     $msgs->deleteMessageByIdentifier($product);
     $licensekey = $key;
     $dir = Mage::getBaseDir("var") . DS . "smartosc" . DS . strtolower(substr($product, 0, 5)) . DS;
     $filepath = $dir . "license.dat";
     $file = new Varien_Io_File();
     if (!($localkey = $file->read($filepath))) {
         $localkey = "";
     }
     # The call below actually performs the license check. You need to pass in the license key and the local key data
     if (!$update) {
         $results = $this->_checkLicense($licensekey, $localkey);
     } else {
         $results = $this->_checkLicense($licensekey);
     }
     # For Debugging, Echo Results
     //        ob_start();
     //        echo "<textarea cols=100 rows=20>";
     //        print_r($results);
     //        echo "</textarea>";
     //die;
     if (strtoupper($results["status"]) == "ACTIVE") {
         # Allow Script to Run
         if (strtoupper($results['productname']) == strtoupper($product)) {
             if ($results["localkey"]) {
                 # Save Updated Local Key to DB or File
                 $localkeydata = $results["localkey"];
                 if (!is_dir_writeable($dir)) {
                     $file->checkAndCreateFolder($dir);
                 }
                 if (!$file->write($filepath, $localkeydata)) {
                     die('Cannot update licensing data to ' . $filepath);
                 }
             }
             Mage::getModel('core/config')->saveConfig($product . '/general/license_status', $results["status"] . " until " . $results['nextduedate']);
             Mage::getConfig()->cleanCache();
             if ($update) {
                 $session->addSuccess("The license key is valid!");
                 if ($msgs->getLastAddedMessage()) {
                     $msgs->getLastAddedMessage()->setIdentifier($product);
                 }
             }
             return true;
         }
     } elseif ($results["status"] == "Invalid") {
         $message = $results["status"];
     } elseif ($results["status"] == "Expired") {
         $message = $results["status"];
     } elseif ($results["status"] == "Suspended") {
         $message = $results["status"];
     }
     $session->addError('The "' . $product . '" extension has been disabled or your license key is invalid!');
     if ($msgs->getLastAddedMessage()) {
         $msgs->getLastAddedMessage()->setIdentifier($product);
     }
     Mage::getModel('core/config')->saveConfig($product . '/general/license_status', $message);
     Mage::getConfig()->cleanCache();
     return false;
 }
示例#18
0
 /**
  * Get uploaded file content
  *
  * @return string
  */
 public function getFileContent()
 {
     return $this->_fileIo->read($this->getFilePath());
 }