Exemplo n.º 1
0
 /**
  * Method to build the part of WHERE clause related to Alpha Index
  *
  * @access private
  * @return array
  */
 function _buildAlphaIndexWhere()
 {
     // Get alpha index request variable and do some security checks, by removing any quotes and other non-valid characters
     $alpha = JRequest::getVar('letter', NULL, 'request', 'string');
     $alpha = preg_replace("/(\\(|\\)\\'|\"|\\\\)/u", "", $alpha);
     if (JString::strlen($alpha) == 0) {
         // nothing to do
         return '';
     }
     // Detect and handle character groups and character ranges,  WARNING: The following is needed because
     // utf8 is multibyte and MySQL regexp doesnot support multibyte, thus we can not use [] with utf8
     $range = explode("-", $alpha);
     if (count($range) > 2) {
         echo "Error in Alpha Index please correct letter range: " . $alpha . "<br>";
         return '';
     } else {
         if (count($range) == 1) {
             $regexp = '"^(' . JString::substr($alpha, 0, 1);
             for ($i = 1; $i < JString::strlen($alpha); $i++) {
                 $regexp .= '|' . JString::substr($alpha, $i, 1);
             }
             $regexp .= ')"';
         } else {
             if (count($range) == 2) {
                 // Get range characters
                 $startletter = $range[0];
                 $endletter = $range[1];
                 // ERROR CHECK: Range START and END are single character strings
                 if (JString::strlen($startletter) != 1 || JString::strlen($endletter) != 1) {
                     echo "Error in Alpha Index<br>letter range: " . $alpha . " start and end must be one character<br>";
                     return '';
                 }
                 // Get ord of characters and their rangle length
                 $startord = FLEXIUtilities::uniord($startletter);
                 $endord = FLEXIUtilities::uniord($endletter);
                 $range_length = $endord - $startord;
                 // ERROR CHECK: Character range has at least one character
                 if ($range_length > 50 || $range_length < 1) {
                     // A sanity check that the range is something logical and that
                     echo "Error in Alpha Index<br>letter range: " . $alpha . ", is incorrect or contains more that 50 characters<br>";
                     return '';
                 }
                 // Check if any character out of the range characters exists
                 // Meaning (There is at least on item title starting with one of the range characters)
                 $regexp = '"^(' . $startletter;
                 for ($uord = $startord + 1; $uord <= $endord; $uord++) {
                     $regexp .= '|' . FLEXIUtilities::unichr($uord);
                 }
                 $regexp .= ')"';
             } else {
                 echo "Error in Alpha Index<br>incorrect letter range: " . $alpha . "<br>";
                 return '';
             }
         }
     }
     $where = '';
     if (!empty($regexp)) {
         if ($alpha == '0') {
             $where = ' AND ( CONVERT (( i.title ) USING BINARY) REGEXP CONVERT (' . $regexp . ' USING BINARY) )';
         } elseif (!empty($alpha)) {
             $where = ' AND ( CONVERT (LOWER( i.title ) USING BINARY) REGEXP CONVERT (' . $regexp . ' USING BINARY) )';
         }
         //$alpha_term = $this->_db->escape( '^['.$alpha.']', true );
         //$where = ' AND LOWER( i.title ) RLIKE '.$this->_db->Quote( $alpha_term, false );
     }
     return $where;
 }
 // ERROR CHECK: Character range has only one minus(-)
 if (count($range) != 2) {
     echo "Error in Alpha Index<br>incorrect letter range: " . $letter . "<br>";
     continue;
 }
 // Get range characters
 $startletter = $range[0];
 $endletter = $range[1];
 // ERROR CHECK: Range START and END are single character strings
 if (JString::strlen($startletter) != 1 || JString::strlen($endletter) != 1) {
     echo "Error in Alpha Index<br>letter range: " . $letter . " start and end must be one character<br>";
     continue;
 }
 // Get ord of characters and their rangle length
 $startord = FLEXIUtilities::uniord($startletter);
 $endord = FLEXIUtilities::uniord($endletter);
 $range_length = $endord - $startord;
 // ERROR CHECK: Character range has at least one character
 if ($range_length > 200 || $range_length < 1) {
     // A sanity check that the range is something logical and that
     echo "Error in Alpha Index<br>letter range: " . $letter . ", is incorrect or contains more that 200 characters<br>";
     continue;
 }
 // Check if any character out of the range characters exists
 // Meaning (There is at least on item title starting with one of the range characters)
 for ($uord = $startord; $uord <= $endord; $uord++) {
     $uchar = FLEXIUtilities::unichr($uord);
     if (in_array($uchar, $this->alpha)) {
         $has_item = true;
         break;
     }