Jump to content



Photo
- - - - -

Need help to resolve problem in general.php


This topic has been archived. This means that you cannot reply to this topic.
26 replies to this topic

#21   geoffreywalton

geoffreywalton

    Available for Hire

  • Community Sponsor
  • 8,203 posts

Posted 14 January 2012 - 08:50

If you reverse the edit do you regain the ability to put part in the basket?

G
Need help installing add ons/contributions, cleaning a hacked site or a bespoke development, check my profile

Virus Threat Scanner
My Contributions
Basic install answers.
Click here for Contributions / Add Ons.
UK your site.
Site Move.
Basic design info.

For links mentioned in old answers that are no longer here follow this link Useful Threads.

If this post was useful, click the Like This button over there ======>>>>>.

#22   Mort-lemur

Mort-lemur
  • Members
  • 1,939 posts

Posted 14 January 2012 - 10:45

You may very well get errors if you only change one line of code - you will need to do all the changes to the file before trying it.

The way I do this is to comment out the old code with // rather than deleting it, and add the new code underneath. That way if you need to revert the code back at some stage it is easier.

Alo make sure that you have copied ALL the nnew lines of code correctly, as I remember some of the new bits of code are "hidden" in the read-me files and you have to scroll down to see the entire change within the code box.

Now running on a fully modded 2.3.4 Store with the Excellent MTS installed - See my profile for the mods installed ..... So much thanks for all the help given along the way by forum members.


#23   ce7

ce7
  • Members
  • 244 posts

Posted 17 July 2012 - 05:13

Hi all,

I am new to oscommerce, been trying few different addons these two months.
Has no coding knowledge, but now very good at copy and paste LOL....

I have installed Better Image Upload Features for 2.3.1
and this is part of the code in admin/categories.php
 if (is_uploaded_file($HTTP_POST_FILES['products_image']['tmp_name'])) {

// require necessary files
require_once(DIR_FS_ADMIN . DIR_WS_CLASSES . 'image.php');

// create image object
$oImage = new TiM_image($HTTP_POST_FILES['products_image']['tmp_name']);

// resample image
if (PRODUCT_IMAGE_RESAMPLING == 'SMALL_IMAGE' || PRODUCT_IMAGE_RESAMPLING == 'BIG_IMAGE') {
$oImage->resample((PRODUCT_IMAGE_RESAMPLING == 'BIG_IMAGE') ? BIG_IMAGE_WIDTH : SMALL_IMAGE_WIDTH, (PRODUCT_IMAGE_RESAMPLING == 'BIG_IMAGE') ? BIG_IMAGE_HEIGHT : SMALL_IMAGE_HEIGHT, (PRODUCT_IMAGE_WHITESPACING == 'true') ? 'FIT_USE_WHITESPACING' : 'FIT', defined(PRODUCT_IMAGE_WHITESPACE_COLOR) ? PRODUCT_IMAGE_WHITESPACE_COLOR : '255,255,255');
}
// set extension
switch(PRODUCT_IMAGE_FORMAT) {
case 'gif':
$image_extension = '.gif';
break;
case 'jpg':
case 'jpeg':
$image_extension = '.jpg';
break;
case 'png':
$image_extension = '.png';
break;
default:
$image_extension = '.' . pathinfo($HTTP_POST_FILES['products_image']['name'], PATHINFO_EXTENSION);
if (!in_array($image_extension, array('.gif', '.png', '.jpg'))) $image_extension = '.jpg';
}

// set basename
switch(PRODUCT_IMAGE_FILENAME_TYPE) {

// set name i.e. products/originalname.jpg
case 'Standard':
$image_basename = 'products/' . pathinfo($HTTP_POST_FILES['products_image']['name'], PATHINFO_FILENAME) . $image_extension;
break;

// set name i.e. products/CB8002.jpg
case 'products_model':
$image_basename = 'products/' . $HTTP_POST_VARS['products_model'] . $image_extension;
break;

// set seo name i.e. products/451-iPod_nano.jpg
case 'SEO friendly':
default:
// prepare image seo name
$image_basename = $HTTP_POST_VARS['products_name'][$languages_id];
$image_basename = mb_convert_encoding($image_basename, 'HTML-ENTITIES', CHARSET); // convert character encoding
$image_basename = preg_replace(array('/\'/', '/\./', '/ /', '/?/', '/&(..)lig;/', '/&([aouAOU])uml;/', '/&(.)[^;]*;/'), array('', '', '_', 'ss', "$1", "$1".'e', "$1"), $image_basename); // translate foreign characters
$image_basename = 'products/' . $products_id . '-' . $image_basename . $image_extension;
break;
}

// create products folder if not exists
if (!file_exists(DIR_FS_CATALOG_IMAGES . 'products/')) {
if (!mkdir(DIR_FS_CATALOG_IMAGES . 'products/', 0777)) die('Failed creating folder '. DIR_FS_CATALOG_IMAGES . 'products/');
}

// if image target already exists
if (file_exists(DIR_FS_CATALOG_IMAGES . $image_basename)) {
$flag_image_conflict = false;

// check if target is safe to delete
if (tep_db_num_rows(tep_db_query("select products_id from ". TABLE_PRODUCTS ." where products_image = '". $image_basename ."' and products_id != '". (int)$products_id ."'")) > 0) $flag_image_conflict = true;
if (tep_db_num_rows(tep_db_query("select id from ". TABLE_PRODUCTS_IMAGES ." where image = '". $image_basename ."'")) > 0) $flag_image_conflict = true;

// safe to delete target, so delete it
if (!$flag_image_conflict) unlink(DIR_FS_CATALOG_IMAGES . $image_basename);
}


// make sure there are no physical conflicts
if (!$flag_image_conflict) {

// save image
$oImage->write(DIR_FS_CATALOG_IMAGES . $image_basename);

// update database
tep_db_perform(TABLE_PRODUCTS, array('products_image' => tep_db_prepare_input($image_basename)), 'update', "products_id = '" . (int)$products_id . "'");

// warn about conflicts
} else {
$messageStack->add_session('There is a conflict with the image filename: '. $image_basename, 'error');
}

}


this addon works fine in configuration/images, the only problem is that I can create products but I can not insert products image anymore as the error occurs and I don't know what to do?

Sorry if I post it in the wrong place but the error is similar as preg_replace(),
ok the error message is as below:

Warning: preg_replace() [function.preg-replace]: Compilation failed: nothing to repeat at offset 0
in /admin/categories.php on line 430
Warning: Cannot modify header information - headers already sent by (output started at
/admin/categories.php:430) in /admin/includes/functions/general.php on line 34

thank you very much in advance.

Lyn

#24   ce7

ce7
  • Members
  • 244 posts

Posted 17 July 2012 - 05:15

BTW, Line 430 is

$image_basename = preg_replace(array('/\'/', '/\./', '/ /', '/?/', '/&(..)lig;/', '/&([aouAOU])uml;/', '/&(.)[^;]*;/'), array('', '', '_', 'ss', "$1", "$1".'e', "$1"), $image_basename); // translate foreign characters


#25   ce7

ce7
  • Members
  • 244 posts

Posted 17 July 2012 - 05:26

Hi all again,

I just comment out that line, and it seems working now, thanks!

#26   MrPhil

MrPhil
  • Members
  • 5,157 posts

Posted 17 July 2012 - 13:53

Did you ever get this working? Heather's fix was wrong.

Here is the code: $string = preg_replace(' +', ' ', trim($string));

I tried put a / in and around the ' +' but nothing worked so far.


It should be
$string = preg_replace('/ +/', '', trim($string));
The search pattern (regular expression) delimiters / go around the whole pattern, not just the non-blank part!!!!!!

Actually, since you're using a fixed pattern, regexp isn't even needed. Try
$string = str_replace(' +', '', trim($string));


#27   MrPhil

MrPhil
  • Members
  • 5,157 posts

Posted 17 July 2012 - 14:27

You didn't fix anything, but merely hid the problem and lost functionality.
$image_basename = preg_replace(array('/\'/', '/\./', '/ /', '/?/', '/&(..)lig;/', '/&([aouAOU])uml;/', '/&(.)[^;]*;/'), array('', '', '_', 'ss', "$1", "$1".'e', "$1"), $image_basename); // translate foreign characters
could be rewritten in an easier to understand form:
$image_basename = preg_replace(
  array("/'/", "/\./", "/ /", "/\?/", "/&(..)lig;/", "/&([aouAOU])uml;/", "/&(.)[^;]*;/"),
  array("",	"",	 "_",  "ss",  "$1",		   "$1e",					   "$1"),
  $image_basename); // translate foreign characters
(Sorry if the spacing is bizarre. The editor and display previewer used in this forum is a piece of crap.)
? has special meaning in a regular expression (and may have caused your error), so I escaped it. I don't think it's strictly necessary to escape the &'s, but you might try that if it still has an error.

' and . are removed. A blank becomes an underscore _. ? becomes 'ss'. Any HTML ligature entity simply becomes the two characters (e.g., æ becomes 'ae'). A, O, and U with umlauts (upper or lower case) become the letter followed by an e. Note that for uppercase letters it should really be an E, so you need to split this one in two:
... "/&([aou])uml;/", "/&([AOU])uml;/" ...
... "$1e",  "$1E", ...