Skip to content

Commit

Permalink
Moved all non-store related function to there proper location.
Browse files Browse the repository at this point in the history
  • Loading branch information
rasseljandavid committed Jul 22, 2011
1 parent 8f3031f commit 0913837
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 36 deletions.
29 changes: 29 additions & 0 deletions framework/core/subsystems/expString.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

class expString {

static function convertUTF($string) {
return $string = str_replace('?', '', htmlspecialchars($string, ENT_IGNORE, 'UTF-8'));
}

static function validUTF($string) {
if(!mb_check_encoding($string, 'UTF-8') OR !($string === mb_convert_encoding(mb_convert_encoding($string, 'UTF-32', 'UTF-8' ), 'UTF-8', 'UTF-32'))) {
return false;
}
return true;
}

static function onlyReadables($string) {
for ($i=0;$i<strlen($string);$i++) {
$chr = $string{$i};
$ord = ord($chr);
if ($ord<32 or $ord>126) {
$chr = "~";
$string{$i} = $chr;
}
}
return str_replace("~", "", $string);
}

}
?>
45 changes: 9 additions & 36 deletions framework/modules/ecommerce/controllers/storeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ class storeController extends expController {
'showallUncategorized'=>'View all uncategorized products',
'nonUnicodeProducts'=>'View all non-unicode charset products',
'cleanNonUnicodeProducts'=>'Clean all non-unicode charset products',
'_convertUTF'=>'Convert to UTF products',
'_validUTF'=>'isValid UTF products',
'_onlyreadables'=>'Process only readables format',
'uploadModelAliases'=>'Upload model aliases',
'processModelAliases'=>'Process uploaded model aliases',
'saveModelAliases'=>'Save uploaded model aliases',
Expand Down Expand Up @@ -1950,11 +1947,11 @@ function nonUnicodeProducts() {

foreach($columns as $column) {
if($column != 'body' && $column != 'summary' && $column != 'featured_body') {
if(!$this->_validUTF($item->$column) || strrpos($item->$column, '?')) {
if(!expString::validUTF($item->$column) || strrpos($item->$column, '?')) {
$affected_fields[] = $column;
}
} else {
if(!$this->_validUTF($item->$column)) {
if(!expString::validUTF($item->$column)) {
$affected_fields[] = $column;
}
}
Expand Down Expand Up @@ -1987,12 +1984,12 @@ function cleanNonUnicodeProducts() {
//TO Improved
foreach($columns as $column) {
if($column != 'body' && $column != 'summary' && $column != 'featured_body') {
if(!$this->_validUTF($item->$column) || strrpos($item->$column, '?')) {
$item->$column = $this->_convertUTF($item->$column);
if(!expString::validUTF($item->$column) || strrpos($item->$column, '?')) {
$item->$column = expString::convertUTF($item->$column);
}
} else {
if(!$this->_validUTF($item->$column)) {
$item->$column = $this->_convertUTF($item->$column);
if(!expString::validUTF($item->$column)) {
$item->$column = expString::convertUTF($item->$column);
}
}
}
Expand All @@ -2003,17 +2000,6 @@ function cleanNonUnicodeProducts() {
redirect_to(array('controller'=>'store', 'action'=>'nonUnicodeProducts'));
}

function _convertUTF($content) {
return $content = str_replace('?', '', htmlspecialchars($content, ENT_IGNORE, 'UTF-8'));
}

function _validUTF($content) {
if(!mb_check_encoding($content, 'UTF-8') OR !($content === mb_convert_encoding(mb_convert_encoding($content, 'UTF-32', 'UTF-8' ), 'UTF-8', 'UTF-32'))) {
return false;
}
return true;
}

//This function is being used in the uploadModelaliases page for showing the form upload
function uploadModelAliases() {
global $db;
Expand Down Expand Up @@ -2055,10 +2041,9 @@ function uploadModelAliases() {
$db->delete('model_aliases_tmp');
while (($data = fgetcsv($handle, 10000, ",")) !== FALSE) {

$tmp->field1 = $this->_onlyreadables($data[0]);
$tmp->field2 = $this->_onlyreadables($data[1]);
$tmp->field1 = expString::onlyReadables($data[0]);
$tmp->field2 = expString::onlyReadables($data[1]);
$db->insertObject($tmp,'model_aliases_tmp');
// eDebug($tmp);
}
redirect_to(array('controller'=>'store','action'=>'processModelAliases'));
echo "Done!";
Expand Down Expand Up @@ -2243,18 +2228,6 @@ function delete_model_alias() {

expHistory::back();
}

function _onlyreadables($string) {
for ($i=0;$i<strlen($string);$i++) {
$chr = $string{$i};
$ord = ord($chr);
if ($ord<32 or $ord>126) {
$chr = "~";
$string{$i} = $chr;
}
}
return str_replace("~", "", $string);
}
}

?>
?>

0 comments on commit 0913837

Please sign in to comment.