Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Need help to resolve problem in general.php


ecgbyme

Recommended Posts

Can't seem to get this working. Need help to resolve code problem in catalog/includes/functions/general.php

 

To work in new PHP 5.3 former code "ereg" needs to be changed to "preg-match".

 

Changed 2 of the three lines:

 

Here is the code:

 

if ($type == 'mixed') {

if (preg_match('^[a-z0-9]$', $char)) $rand_value .= $char;

} elseif ($type == 'chars') {

if (preg_match('^[a-z]$', $char)) $rand_value .= $char;

} elseif ($type == 'digits') {

if (eregi('^[0-9]$', $char)) $rand_value .= $char;

}

}

 

But when I change the 3rd one which is "eregi" with the extra "i" to "preg_match" which is suppose to be changed the same change as "ereg"

I get this error:

 

Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in /includes/functions/general.php on line 1043

 

Appreciate any help to resolve this.

Link to comment
Share on other sites

can you post your modified code ?

Now running on a fully modded, Mobile Friendly 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.

Link to comment
Share on other sites

ereg becomes preg

eregi becomes preg_match

Now running on a fully modded, Mobile Friendly 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.

Link to comment
Share on other sites

or try this:

 

    if (preg_match('/^[a-z0-9]$/i', $char)) $rand_value .= $char;

Now running on a fully modded, Mobile Friendly 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.

Link to comment
Share on other sites

sorry, ignore my last post - posted the wrong line - these are the 3 modified lines:

 

    if (preg_match('/^[a-z0-9]$/i', $char)) $rand_value .= $char;
  } elseif ($type == 'chars') {
    if (preg_match('/^[a-z]$/i', $char)) $rand_value .= $char;
  } elseif ($type == 'digits') {
    if (preg_match('/^[0-9]$/', $char)) $rand_value .= $char;

Now running on a fully modded, Mobile Friendly 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.

Link to comment
Share on other sites

sorry, ignore my last post - posted the wrong line - these are the 3 modified lines:

 

	if (preg_match('/^[a-z0-9]$/i', $char)) $rand_value .= $char;
  } elseif ($type == 'chars') {
	if (preg_match('/^[a-z]$/i', $char)) $rand_value .= $char;
  } elseif ($type == 'digits') {
	if (preg_match('/^[0-9]$/', $char)) $rand_value .= $char;

 

Thank youi so much Heather! That did it!

Link to comment
Share on other sites

No Problem - I went through the same thing a few days ago - see my post on the subject probably on the 2nd or 3rd page of general support by now - I documented the changes as I made them

Now running on a fully modded, Mobile Friendly 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.

Link to comment
Share on other sites

Trying to complete check out. Maybe you can help me with this one.

 

The error I get is: Warning: preg_replace() [function.preg-replace]: No ending delimiter '+' found in /includes/functions/general.php on line 61

 

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

 

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

Link to comment
Share on other sites

Trying to complete check out. Maybe you can help me with this one.

 

The error I get is: Warning: preg_replace() [function.preg-replace]: No ending delimiter '+' found in /includes/functions/general.php on line 61

 

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

 

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

 

Try

$string = preg_replace(' /+/', ' ', trim($string));

Now running on a fully modded, Mobile Friendly 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.

Link to comment
Share on other sites

I think you need to read the previous post I made on my crisis with PHP 5.3 - Dunweb posted a link to me of all the changes needed for the "Core" Rc2.2 files - general php is covered in that

Now running on a fully modded, Mobile Friendly 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.

Link to comment
Share on other sites

Try

$string = preg_replace(' /+/', ' ', trim($string));

 

Now the error changed still the same line: Warning: preg_replace() [function.preg-replace]: Compilation failed: nothing to repeat at offset 0 in /includes/functions/general.php on line 61

 

In the dark as to waht that may mean.

Link to comment
Share on other sites

Maybe something to do with the next line:

 

function tep_sanitize_string($string) {

$string = preg_replace(' /+/', ' ', trim($string));

 

return preg_replace("/[<>]/", '_', $string);

}

Link to comment
Share on other sites

This is the link to my thread - go to the link posted on Dunwebs first answer.

 

http://www.oscommerce.com/forums/topic/382628-osc-22rc2a-php-52-php-53-crisis/

 

A lot of what you are asking is covered

Now running on a fully modded, Mobile Friendly 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.

Link to comment
Share on other sites

Hi Heather

 

I already downloaded and install the drop in update PHPs.

I have 2 stores and the one I did the drop in updates, I cannot load anything into the shopping cart at all, nothing appears, it remains empty.

I have no idea if these updates are the cause but the other store is getting close to processing. Items appear in the cart. So far the checkout does not

recognize me a s a customer. I'v went through and read your posts a page or 2 back.

 

I still have this error: as in my last post: Warning: preg_replace() [function.preg-replace]: Compilation failed: nothing to repeat at offset 0 in /includes/functions/general.php on line 61

 

Appreciate any help

Link to comment
Share on other sites

Did you just drop in the complete files or amend the specific lines?

 

If you replaced entire files, any changes already made will be lost and things will stop working.

 

Restore the files and just change the lines that need to be replaced.

 

HTH

 

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 ======>>>>>.

Link to comment
Share on other sites

Hi,

 

Use the Read Me section of the contribution and do the changes line by line

Now running on a fully modded, Mobile Friendly 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.

Link to comment
Share on other sites

I get it now. Thanks! I changed an error line in languages.php using the new code line in the update.

Now I'm unable to add anything to the cart just as in the other store.

Any ideas as what to do would be appreciated!

Link to comment
Share on other sites

Did you just drop in the complete files or amend the specific lines?

 

If you replaced entire files, any changes already made will be lost and things will stop working.

 

Restore the files and just change the lines that need to be replaced.

 

Restore the files to the state before you dropped in the files, ifthat makes sense

 

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 ======>>>>>.

Link to comment
Share on other sites

Restore the files to the state before you dropped in the files, ifthat makes sense

 

G

 

Hi Geoffery

I never dropped the files into the 2nd store as a precaution to see what would happen. The cart was working until I changed the one line:

 

Warning: preg_replace() [function.preg-replace]: Compilation failed: nothing to repeat at offset 0 in /includes/functions/general.php on line 61

 

I only changed 1 line copied out of the update general.php file and lost my cart ability to put products in it.

Could admin files have anything to do with it as I don't think I've edited any of those yet.

Link to comment
Share on other sites

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 ======>>>>>.

Link to comment
Share on other sites

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, Mobile Friendly 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.

Link to comment
Share on other sites

  • 6 months later...

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

Link to comment
Share on other sites

BTW, Line 430 is

 

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

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...