/**
  * Returns string manipulation utility instance
  *
  * @return oxUtilsString
  */
 public static function getInstance()
 {
     // disable caching for test modules
     if (defined('OXID_PHP_UNIT')) {
         self::$_instance = modInstances::getMod(__CLASS__);
     }
     if (!self::$_instance instanceof oxUtilsString) {
         self::$_instance = oxNew('oxUtilsString');
         if (defined('OXID_PHP_UNIT')) {
             modInstances::addMod(__CLASS__, self::$_instance);
         }
     }
     return self::$_instance;
 }
Ejemplo n.º 2
0
 /**
  * Prepares SQL where query according SQL condition array and attaches it to SQL end.
  * For each search value if german umlauts exist, adds them
  * and replaced by spec. char to query
  *
  * @param array  $aWhere  SQL condition array
  * @param string $sqlFull SQL query string
  *
  * @return string
  */
 protected function _prepareWhereQuery($aWhere, $sqlFull)
 {
     if (count($aWhere)) {
         $myUtilsString = oxUtilsString::getInstance();
         while (list($sFieldName, $sFieldValue) = each($aWhere)) {
             $sFieldValue = trim($sFieldValue);
             //check if this is search string (conatains % sign at begining and end of string)
             $blIsSearchValue = $this->_isSearchValue($sFieldValue);
             //removing % symbols
             $sFieldValue = $this->_processFilter($sFieldValue);
             if (strlen($sFieldValue)) {
                 $aVal = explode(' ', $sFieldValue);
                 //for each search field using AND anction
                 $sSqlBoolAction = ' and (';
                 foreach ($aVal as $sVal) {
                     // trying to search spec chars in search value
                     // if found, add cleaned search value to search sql
                     $sUml = $myUtilsString->prepareStrForSearch($sVal);
                     if ($sUml) {
                         $sSqlBoolAction .= '(';
                     }
                     $sFieldName = oxDb::getInstance()->escapeString($sFieldName);
                     $sqlFull .= " {$sSqlBoolAction} {$sFieldName} ";
                     //for search in same field for different values using AND
                     $sSqlBoolAction = ' and ';
                     $sqlFull .= $this->_buildFilter($sVal, $blIsSearchValue);
                     if ($sUml) {
                         $sqlFull .= " or {$sFieldName} ";
                         $sqlFull .= $this->_buildFilter($sUml, $blIsSearchValue);
                         $sqlFull .= ')';
                         // end of OR section
                     }
                 }
                 // end for AND action
                 $sqlFull .= ' ) ';
             }
         }
     }
     return $sqlFull;
 }
Ejemplo n.º 3
0
 /**
  * Forms and returns SQL query string for search in DB.
  *
  * @param string $sSearchString searching string
  *
  * @return string
  */
 protected function _getWhere($sSearchString)
 {
     $oDb = oxDb::getDb();
     $myConfig = $this->getConfig();
     $blSep = false;
     $sArticleTable = getViewName('oxarticles', $this->_iLanguage);
     $aSearchCols = $myConfig->getConfigParam('aSearchCols');
     if (!(is_array($aSearchCols) && count($aSearchCols))) {
         return '';
     }
     $oTempArticle = oxNew('oxarticle');
     $sSearchSep = $myConfig->getConfigParam('blSearchUseAND') ? 'and ' : 'or ';
     $aSearch = explode(' ', $sSearchString);
     $sSearch = ' and ( ';
     $myUtilsString = oxUtilsString::getInstance();
     $oLang = oxLang::getInstance();
     foreach ($aSearch as $sSearchString) {
         if (!strlen($sSearchString)) {
             continue;
         }
         if ($blSep) {
             $sSearch .= $sSearchSep;
         }
         $blSep2 = false;
         $sSearch .= '( ';
         foreach ($aSearchCols as $sField) {
             if ($blSep2) {
                 $sSearch .= ' or ';
             }
             // as long description now is on different table table must differ
             if ($sField == 'oxlongdesc' || $sField == 'oxtags') {
                 $sSearchField = getViewName('oxartextends', $this->_iLanguage) . ".{$sField}";
             } else {
                 $sSearchField = "{$sArticleTable}.{$sField}";
             }
             $sSearch .= " {$sSearchField} like " . $oDb->quote("%{$sSearchString}%");
             // special chars ?
             if ($sUml = $myUtilsString->prepareStrForSearch($sSearchString)) {
                 $sSearch .= " or {$sSearchField} like " . $oDb->quote("%{$sUml}%");
             }
             $blSep2 = true;
         }
         $sSearch .= ' ) ';
         $blSep = true;
     }
     $sSearch .= ' ) ';
     return $sSearch;
 }
Ejemplo n.º 4
0
 public function testOxUtilsStringPrepareStrForSearch()
 {
     $sString = 'agentūЛитовfür';
     $sExpected = 'agentūЛитовfür';
     $oUtils = new oxUtilsString();
     $this->assertEquals($sExpected, $oUtils->prepareStrForSearch($sString));
 }
 /**
  * Forms and returns SQL query string for search in DB.
  *
  * @param string $sSearchString searching string
  *
  * @return string
  */
 protected function _getSearchSelect($sSearchString)
 {
     // check if it has string at all
     if (!$sSearchString || !str_replace(' ', '', $sSearchString)) {
         return '';
     }
     $oDb = oxDb::getDb();
     $myConfig = $this->getConfig();
     $myUtils = oxUtils::getInstance();
     $sArticleTable = $this->getBaseObject()->getViewName();
     $aSearch = explode(' ', $sSearchString);
     $sSearch = ' and ( ';
     $blSep = false;
     // #723
     if ($myConfig->getConfigParam('blSearchUseAND')) {
         $sSearchSep = ' and ';
     } else {
         $sSearchSep = ' or ';
     }
     $aSearchCols = $myConfig->getConfigParam('aSearchCols');
     $oBaseObject = $this->getBaseObject();
     $myUtilsString = oxUtilsString::getInstance();
     foreach ($aSearch as $sSearchString) {
         if (!strlen($sSearchString)) {
             continue;
         }
         if ($blSep) {
             $sSearch .= $sSearchSep;
         }
         $blSep2 = false;
         $sSearch .= '( ';
         $sUml = $myUtilsString->prepareStrForSearch($sSearchString);
         foreach ($aSearchCols as $sField) {
             if ($blSep2) {
                 $sSearch .= ' or ';
             }
             // as long description now is on different table table must differ
             if ($sField == 'oxlongdesc' || $sField == 'oxtags') {
                 $sSearchTable = getViewName('oxartextends');
             } else {
                 $sSearchTable = $sArticleTable;
             }
             $sSearch .= $sSearchTable . '.' . $sField . ' like ' . $oDb->quote('%' . $sSearchString . '%') . ' ';
             if ($sUml) {
                 $sSearch .= ' or ' . $sSearchTable . '.' . $sField . ' like ' . $oDb->quote('%' . $sUml . '%');
             }
             $blSep2 = true;
         }
         $sSearch .= ' ) ';
         $blSep = true;
     }
     $sSearch .= ' ) ';
     return $sSearch;
 }
 /**
  * Converts field for CSV
  *
  * @param string $sInput input to process
  *
  * @return string
  */
 public function prepareCSV($sInput)
 {
     $sInput = oxUtilsString::getInstance()->prepareCSVField($sInput);
     return str_replace(array(" ", "€", "|"), array(" ", "", ""), $sInput);
 }
Ejemplo n.º 7
0
 /**
  * Returns the OXID string utilities object.
  *
  * @return oxUtilsString
  */
 public function getUtilsString()
 {
     return oxUtilsString::getInstance();
 }
Ejemplo n.º 8
0
 /**
  * Returns current view meta description data
  *
  * @param string $sMeta                   category path
  * @param int    $iLength                 max length of result, -1 for no truncation
  * @param bool   $blRemoveDuplicatedWords if true - performs additional dublicate cleaning
  *
  * @return  string  $sString    converted string
  */
 protected function _prepareMetaDescription($sMeta, $iLength = 1024, $blRemoveDuplicatedWords = false)
 {
     if ($sMeta) {
         $oStr = getStr();
         if ($iLength != -1) {
             /* *
              * performance - we dont need a huge amount of initial text.
              * assume that effective text may be double longer than $iLength
              * and simple turncate it
              */
             $iELength = $iLength * 2;
             $sMeta = $oStr->substr($sMeta, 0, $iELength);
         }
         // decoding html entities
         $sMeta = $oStr->html_entity_decode($sMeta);
         // stripping HTML tags
         $sMeta = $oStr->strip_tags($sMeta);
         // removing some special chars
         $sMeta = $oStr->cleanStr($sMeta);
         // removing duplicate words
         if ($blRemoveDuplicatedWords) {
             $sMeta = $this->_removeDuplicatedWords($sMeta, $this->getConfig()->getConfigParam('aSkipTags'));
         }
         // some special cases
         $sMeta = str_replace(' ,', ',', $sMeta);
         $aPattern = array("/,[\\s\\+\\-\\*]*,/", "/\\s+,/");
         $sMeta = $oStr->preg_replace($aPattern, ',', $sMeta);
         $sMeta = oxUtilsString::getInstance()->minimizeTruncateString($sMeta, $iLength);
         $sMeta = $oStr->htmlspecialchars($sMeta);
         return trim($sMeta);
     }
 }
Ejemplo n.º 9
0
 /**
  * Prepares SQL where query according SQL condition array and attaches it to SQL end.
  * For each search value if german umlauts exist, adds them
  * and replaced by spec. char to query
  *
  * @param array  $aWhere     SQL condition array
  * @param string $sQueryFull SQL query string
  *
  * @return string
  */
 public function _prepareWhereQuery($aWhere, $sQueryFull)
 {
     $aNameWhere = null;
     if (isset($aWhere['oxuser.oxlname']) && ($sName = $aWhere['oxuser.oxlname'])) {
         // check if this is search string (contains % sign at begining and end of string)
         $blIsSearchValue = $this->_isSearchValue($sName);
         $sName = $this->_processFilter($sName);
         $aNameWhere['oxuser.oxfname'] = $aNameWhere['oxuser.oxlname'] = $sName;
         // unsetting..
         unset($aWhere['oxuser.oxlname']);
     }
     $sQ = parent::_prepareWhereQuery($aWhere, $sQueryFull);
     if ($aNameWhere) {
         $aVal = explode(' ', $sName);
         $sQ .= ' and (';
         $sSqlBoolAction = '';
         $myUtilsString = oxUtilsString::getInstance();
         foreach ($aNameWhere as $sFieldName => $sValue) {
             //for each search field using AND anction
             foreach ($aVal as $sVal) {
                 $sQ .= " {$sSqlBoolAction} {$sFieldName} ";
                 //for search in same field for different values using AND
                 $sSqlBoolAction = ' or ';
                 $sQ .= $this->_buildFilter($sVal, $blIsSearchValue);
                 // trying to search spec chars in search value
                 // if found, add cleaned search value to search sql
                 $sUml = $myUtilsString->prepareStrForSearch($sVal);
                 if ($sUml) {
                     $sQ .= " or {$sFieldName} ";
                     $sQ .= $this->_buildFilter($sUml, $blIsSearchValue);
                 }
             }
         }
         // end for AND action
         $sQ .= ' ) ';
     }
     return $sQ;
 }