public function testGetStr() { if ($this->getConfig()->getConfigParam('iUtfMode')) { $this->assertTrue(oxStr::getStr() instanceof oxStrMb); } else { $this->assertFalse(oxStr::getStr() instanceof oxStrMb); } }
/** * Static method initializing new string handler or returning the existing one. * * @return object */ public static function getStr() { if (!isset(self::$_oHandler)) { //let's init now non-static instance of oxStr to get the instance of str handler self::$_oHandler = oxNew("oxStr")->_getStrHandler(); } return self::$_oHandler; }
/** * Get a list of settings available to export and import. * * @return array */ public function getSettingsList() { $aSettings = array(); foreach ($this->_aModuleSettings as $sSetting) { $aSettings[$sSetting] = sprintf('OXPS_MODULESCONFIG_SETTING_%s', oxStr::getStr()->strtoupper($sSetting)); } return $aSettings; }
/** * Parse new blocks multi-line data to valid metadata blocks definition. * Each valid element will have a template, block and file keys. * * @todo (nice2have): When using block name as blocks list key, block becomes unique in a module. * Maybe it should not be unique, i.e. module could extend same block many times, or not? * * @param string $sBlocks * @param string $sVendorPrefix * @param string $sModuleName * * @return array */ protected function _parseBlocksData($sBlocks, $sVendorPrefix, $sModuleName) { $sModuleId = oxStr::getStr()->strtolower(sprintf('%s%s', $sVendorPrefix, $sModuleName)); $aBlocks = $this->_parseMultiLineInput($sBlocks, 'not_empty'); $aValidBlocks = array(); foreach ($aBlocks as $sBlockDefinition) { $aBlock = $this->_parseBlockDefinition($sBlockDefinition, $sModuleId); if (isset($aBlock['template'], $aBlock['block'], $aBlock['file'])) { $aValidBlocks[sprintf('_%s', $aBlock['block'])] = (object) $aBlock; } } return $aValidBlocks; }
/** * Performs search for "sid", removes it and adds shop id to string. * * @param string $sAltBody Body. * * @return string */ private function _clearSidFromBody($sAltBody) { return oxStr::getStr()->preg_replace('/(\\?|&(amp;)?)(force_)?(admin_)?sid=[A-Z0-9\\.]+/i', '\\1shp=' . $this->getConfig()->getShopId(), $sAltBody); }
/** * Method performs user passed SQL query */ public function performsql() { $oAuthUser = oxNew('oxuser'); $oAuthUser->loadAdminUser(); if ($oAuthUser->oxuser__oxrights->value === "malladmin") { $sUpdateSQL = oxRegistry::getConfig()->getRequestParameter("updatesql"); $sUpdateSQLFile = $this->_processFiles(); if ($sUpdateSQLFile && strlen($sUpdateSQLFile) > 0) { if (isset($sUpdateSQL) && strlen($sUpdateSQL)) { $sUpdateSQL .= ";\r\n" . $sUpdateSQLFile; } else { $sUpdateSQL = $sUpdateSQLFile; } } $sUpdateSQL = trim(stripslashes($sUpdateSQL)); $oStr = getStr(); $iLen = $oStr->strlen($sUpdateSQL); if ($this->_prepareSQL($sUpdateSQL, $iLen)) { $aQueries = $this->aSQLs; $this->_aViewData["aQueries"] = array(); $aPassedQueries = array(); $aQAffectedRows = array(); $aQErrorMessages = array(); $aQErrorNumbers = array(); if (count($aQueries) > 0) { $blStop = false; $oDB = oxDb::getDb(); $iQueriesCounter = 0; for ($i = 0; $i < count($aQueries); $i++) { $sUpdateSQL = $aQueries[$i]; $sUpdateSQL = trim($sUpdateSQL); if ($oStr->strlen($sUpdateSQL) > 0) { $aPassedQueries[$iQueriesCounter] = nl2br(oxStr::getStr()->htmlentities($sUpdateSQL)); if ($oStr->strlen($aPassedQueries[$iQueriesCounter]) > 200) { $aPassedQueries[$iQueriesCounter] = $oStr->substr($aPassedQueries[$iQueriesCounter], 0, 200) . "..."; } while ($sUpdateSQL[$oStr->strlen($sUpdateSQL) - 1] == ";") { $sUpdateSQL = $oStr->substr($sUpdateSQL, 0, $oStr->strlen($sUpdateSQL) - 1); } try { $oDB->execute($sUpdateSQL); } catch (Exception $oExcp) { // catching exception ... $blStop = true; } $aQAffectedRows[$iQueriesCounter] = null; $aQErrorMessages[$iQueriesCounter] = null; $aQErrorNumbers[$iQueriesCounter] = null; $iErrorNum = $oDB->ErrorNo(); if ($iAffectedRows = $oDB->affected_Rows() !== false && $iErrorNum == 0) { $aQAffectedRows[$iQueriesCounter] = $iAffectedRows; } else { $aQErrorMessages[$iQueriesCounter] = oxStr::getStr()->htmlentities($oDB->errorMsg()); $aQErrorNumbers[$iQueriesCounter] = oxStr::getStr()->htmlentities($iErrorNum); } $iQueriesCounter++; // stopping on first error.. if ($blStop) { break; } } } } $this->_aViewData["aQueries"] = $aPassedQueries; $this->_aViewData["aAffectedRows"] = $aQAffectedRows; $this->_aViewData["aErrorMessages"] = $aQErrorMessages; $this->_aViewData["aErrorNumbers"] = $aQErrorNumbers; } $this->_iDefEdit = 1; } }
/** * Returns string handler * * @deprecated since v6.0.0 (2016-05-16); Use oxStr::getStr(). * * @return oxStrRegular|oxStrMb */ function getStr() { return oxStr::getStr(); }
/** * Create template files for a given classes in provided location. * * @param array $aClasses Class names array to create templates for. * @param string $sDestinationPath A full path to folder to create templates in. * @param bool $blBlocks If true block templates are generated. * * @return bool */ protected function _createTemplates(array $aClasses, $sDestinationPath, $blBlocks = false) { $oFileSystemHelper = $this->getFileSystemHelper(); if (!$oFileSystemHelper->isDir($sDestinationPath)) { return false; } $oModule = $this->getModule(); $sModuleId = $oModule->getModuleId(); $sClassPrefix = $oModule->getModuleClassName(); $sDemoContentFormat = $this->_getTemplateContentFormat($blBlocks); foreach ($aClasses as $sClass) { $sTemplateFileName = sprintf('%s%s.tpl', $sModuleId, oxStr::getStr()->strtolower($sClass)); $sTemplateFilePath = $sDestinationPath . $sTemplateFileName; $sTemplateContent = sprintf($sDemoContentFormat, $sClass, $sTemplateFilePath, $sClassPrefix . $sClass); $oFileSystemHelper->createFile($sTemplateFilePath, $sTemplateContent); } return true; }
/** * Test sending ordering mail to user */ public function testSendOrderEmailToUser() { $oPrice = $this->getMock('oxprice'); $oPrice->expects($this->any())->method('getPrice')->will($this->returnValue(256)); $oPrice->expects($this->any())->method('getBruttoPrice')->will($this->returnValue(8)); $oBasketItem = $this->getMock('oxbasketitem', array('getPrice', 'getUnitPrice', 'getRegularUnitPrice', 'getTitle')); $oBasketItem->expects($this->any())->method('getPrice')->will($this->returnValue($oPrice)); $oBasketItem->expects($this->any())->method('getUnitPrice')->will($this->returnValue($oPrice)); $oBasketItem->expects($this->any())->method('getRegularUnitPrice')->will($this->returnValue($oPrice)); $oBasketItem->expects($this->any())->method('getTitle')->will($this->returnValue("testarticle")); // insert test article $oArticle = oxNew("oxArticle"); $oArticle->setId('_testArticleId'); $oArticle->setId('_testArticleId'); $oArticle->oxarticles__oxtitle = new oxField(); $aBasketContents[] = $oBasketItem; $aBasketArticles[] = $oArticle; $oPrice->setPrice(0); $oBasket = $this->getMock('oxBasket', array("getBasketArticles", "getContents", "getCosts", "getBruttoSum")); $oBasket->expects($this->any())->method('getBasketArticles')->will($this->returnValue($aBasketArticles)); $oBasket->expects($this->any())->method('getContents')->will($this->returnValue($aBasketContents)); $oBasket->expects($this->any())->method('getCosts')->will($this->returnValue($oPrice)); $oBasket->expects($this->any())->method('getBruttoSum')->will($this->returnValue(7)); $oPayment = oxNew('oxPayment'); $oPayment->oxpayments__oxdesc = new oxField("testPaymentDesc"); $oUser = oxNew("oxuser"); $oUser->setId('_testUserId'); $oUser->oxuser__oxusername = new oxField('*****@*****.**', oxField::T_RAW); $oUser->oxuser__oxfname = new oxField('testUserFName', oxField::T_RAW); $oUser->oxuser__oxlname = new oxField('testUserLName', oxField::T_RAW); $oOrder = $this->getMock('oxOrder', array("getOrderUser", "getBasket", "getPayment")); $oOrder->expects($this->any())->method('getOrderUser')->will($this->returnValue($oUser)); $oOrder->expects($this->any())->method('getBasket')->will($this->returnValue($oBasket)); $oOrder->expects($this->any())->method('getPayment')->will($this->returnValue($oPayment)); $oOrder->oxorder__oxordernr = new oxField('987654321', oxField::T_RAW); $oOrder->oxorder__oxbillfname = new oxField(''); $oOrder->oxorder__oxbilllname = new oxField(''); $oOrder->oxorder__oxbilladdinfo = new oxField(''); $oOrder->oxorder__oxbillstreet = new oxField(''); $oOrder->oxorder__oxbillcity = new oxField(''); $oOrder->oxorder__oxbillcountry = new oxField(''); $oOrder->oxorder__oxbillcompany = new oxField(''); $oOrder->oxorder__oxdeltype = new oxField("oxidstandard"); $oShop = oxNew("oxshop"); $oShop->load($this->getConfig()->getShopId()); $oEmail = $this->getMock('oxEmail', array("_sendMail", "_getShop")); $oEmail->expects($this->once())->method('_sendMail')->will($this->returnValue(true)); $oEmail->expects($this->any())->method('_getShop')->will($this->returnValue($oShop)); $oEmail->expects($this->any())->method('getOrderFileList')->will($this->returnValue(false)); $blRet = $oEmail->sendOrderEmailToUser($oOrder); $this->assertTrue($blRet); $sBody = $oEmail->getBody(); //uncoment line to generate template for checking mail body //file_put_contents (__DIR__ .'/../testData/email_templates/'.__FUNCTION__.'_.html', $oEmail->getBody() ); $oStr = oxStr::getStr(); // checking if there are some utf-8 strings // translation check $this->assertTrue($oStr->strpos($sBody, "Grußkarte:") > 0); // euro sign check $this->assertTrue($oStr->strpos($sBody, "256,00 €") > 0); // strings, that comes from oxcontent $this->assertTrue($oStr->strpos($sBody, "Vielen Dank für Ihre Bestellung!") > 0); $this->assertTrue($oStr->strpos($sBody, "Bitte fügen Sie hier Ihre vollständige Anbieterkennzeichnung ein.") > 0); }
/** * Removes spaces and symbols: '-',',','.' from string * * @param string $sValue Value. * * @return string */ protected function _cleanUp($sValue) { return (string) oxStr::getStr()->preg_replace("/\\s|-/", '', $sValue); }
/** * Get columns names from CSV file header. If file has no header * returns default columns names Column 1, Column 2.. * * @return array */ protected function _getCsvFieldsNames() { $blCsvContainsHeader = $this->getConfig()->getRequestParameter('blContainsHeader'); oxRegistry::getSession()->setVariable('blCsvContainsHeader', $blCsvContainsHeader); $sCsvPath = $this->_getUploadedCsvFilePath(); $aFirstRow = $this->_getCsvFirstRow(); if (!$blCsvContainsHeader) { $iIndex = 1; foreach ($aFirstRow as $sValue) { $aCsvFields[$iIndex] = 'Column ' . $iIndex++; } } else { foreach ($aFirstRow as $sKey => $sValue) { $aFirstRow[$sKey] = oxStr::getStr()->htmlentities($sValue); } $aCsvFields = $aFirstRow; } return $aCsvFields; }
/** * Check if module with provided name exists in the configured vendor directory. * * @param string $sModuleName * * @return boolean */ protected function _moduleExists($sModuleName) { /** @var oxpsModuleGeneratorFileSystem $oFileSystemHelper */ $oFileSystemHelper = oxRegistry::get('oxpsModuleGeneratorFileSystem'); return $oFileSystemHelper->isDir($this->getVendorPath() . oxStr::getStr()->strtolower($sModuleName)); }
/** * Boolean type value parser. * * @param string $sInitialValue * * @return string */ protected function _getBooleanSettingValue($sInitialValue) { return (empty($sInitialValue) or oxStr::getStr()->strtolower($sInitialValue) == 'false') ? 'false' : 'true'; }