Regex to manipulate image links - regex

I'm using the following code snippet and regex expression to add "rel=" tags to certain affiliate links. While this code works well with text links, it doesn't work with image links that follow this format: <img src="" class=""... />
Does anyone know how to update the regex to match both text and image links?
function rewrite_affiliate_links($content) {
// Don't rewrite URLs on shop page
if ( is_page( 87422 ) ) {
return $content;
}
$content = preg_replace_callback(
'/<a[^>]*href=["|\']([^"|\']*)["|\'][^>]*>([^<]*)<\/a>/i',
function($m) {
$Sponsored_URLS = explode(",","Amazon.com,amzn.to,shareasale.com,hsselite.7eer.net,tkqlhce.com,jdoqocy.com,dpbolvw.net,awltovhc.com,tqlkg.com,lduhtrp.net,anrdoezrs.net,ftjcfx.com,7eer.net,refersion.com,avantlink.com,/go/,www.sunstar.com.ph,www.alliedmarketresearch.com,www.theyucatantimes.com,rubikicks.com,superfoodprofiles.com,amplifi.com,performancelab.com");
$i = 0;
$j = count($Sponsored_URLS);
while ($i < $j) { ;
if ((strpos(strtolower($m[1]), strtolower($Sponsored_URLS[$i])) !== false)) {
$match = "yes";
}
$i++;
}
if ($match == "yes") {
return ''.$m[2].'*';
} else {
if ((strpos(strtolower($m[1]), $_SERVER['HTTP_HOST']) !== false) || (substr($m[1],0,1) == "#")) {
//return '<' . $m[0] . ' href="'.$m[1].'" rel="follow">'.$m[2].'</a>';
return $m[0];
} else {
return ''.$m[2].'';
}
}
},
$content);
return $content;
}
Thanks,
Michael

I'd just do it separately because you are "rendering" your "a" tag. May be like so
<?php
function rewrite_affiliate_links($content) {
$sponsoredLinks = [
"Amazon.com",
"amzn.to",
"shareasale.com",
"hsselite.7eer.net",
"tkqlhce.com",
"jdoqocy.com",
"dpbolvw.net",
"awltovhc.com",
"tqlkg.com",
"lduhtrp.net",
"anrdoezrs.net",
"ftjcfx.com",
"7eer.net",
"refersion.com",
"avantlink.com",
"\/go\/",
"www.sunstar.com.ph",
"www.alliedmarketresearch.com",
"www.theyucatantimes.com",
"rubikicks.com",
"superfoodprofiles.com",
"amplifi.com",
"performancelab.com",
];
$sponsoredLinksPrepared = implode('|', $sponsoredLinks);
$anchorRegex = "/<a.*?href=(?:\"|')(.*?(?:{$sponsoredLinksPrepared}).*?)(?:\"|').*?>(.*?)<\/a>/i";
$anchoreReplacement = '$2 *';
$imgRegex = "/<img.*?src=(?:\"|')(.*?(?:{$sponsoredLinksPrepared}).*?)(?:\"|') (.*?)>/i";
$imgReplacement = '<img src="$1" rel="sponsored noopener" $2>';
$content = preg_replace($anchorRegex, $anchoreReplacement, $content);
$content = preg_replace($imgRegex, $imgReplacement, $content);
return $content;
}
echo rewrite_affiliate_links('some');
echo "\n";
echo rewrite_affiliate_links('<img src="amzn.to/blah.jpg" width="234px" height="432px">');
echo "\n";
echo rewrite_affiliate_links('some non sponsored');
It's not a complete code it's just a general idea.

Related

Format AWS Transcribe Audio Identification

I've been searching for this solution, couldn't find anything reasonably to what AWS currently have on their UI, so came up with mine in laravel, and dropping it here to help anyone hopefully searching for this as well.
public function convertTextToSpeakers($response)
{
$segments = $response['results']['speaker_labels']['segments'];
$items = $response['results']['items'];
$result = [];
foreach ($items as $key => $item) {
if (!isset($item['start_time'])) {
$prev_item = $items[$key - 1];
if ($prev_item) {
$item['start_time'] = $prev_item['start_time'];
$item['end_time'] = $prev_item['end_time'];
$items[$key] = $item;
}
}
}
foreach ($segments as $key => $segment) {
$has_data = true;
$temp_key = $key;
while ($has_data) {
$temp_key++;
$next_segment = $segments[$temp_key] ?? null;
if ($next_segment && $next_segment['speaker_label'] == $segment['speaker_label']) {
$itemsData = array_merge($segment['items'], $next_segment['items']);
$segment['items'] = $itemsData;
unset($segments[$temp_key]);
$segments[$key] = $segment;
} else {
$has_data = false;
}
}
}
$items = collect($items);
$segments = collect($segments)->sortBy('start_time');
foreach ($segments as $segment) {
$text = '';
$segmentItems = collect($segment['items'])->sortBy('start_time');
foreach ($segmentItems as $seg_item) {
$words = $items->where('start_time', $seg_item['start_time'])
->where('end_time', $seg_item['end_time']);
foreach ($words as $word) {
$text .= $word['alternatives'][0]['content'];
}
$text .= " ";
}
$result[] = [
'speaker' => $segment['speaker_label'],
'text' => $text,
];
}
return $result;
}

perl regular expression to substitute content of a xml tag content

The following tags are in the same format in the file and not well formed
I want to replace the tags inside user tag with name test with my custom text.
xml parser in perl cant be used as it is not pure xml.
<user name="test">
<option name="test2">dev</option>
<option name="test3">csm></option>
</user>
<user name="test12">
<option name="test21">dev1</option>
<option name="test31">csm1></option>
</user>
this is how i managed to do it.
open(FILE,"<","menu1.xml");
open(OUT,">","menu12.xml");
my #values = split('\n', $data);
my $ind = 0;
my $arraysize = #values;
while (($input = <FILE>))
{
print OUT $input;
if($input =~ m/<menu name="">/)
{
while (defined($input = <FILE>) && ($input !~ m/<\/menu>/))
{
print OUT $input;
if ($input =~ m/.+user name="(.*)">/ && $1 eq $access_type)
{
while (defined($input = <FILE>) && ($input !~ m/<\/user>/))
{
if($ind < $arraysize)
{
$input =~ s/<(.*) name="(.*)">(.*)<\/(.*)>/$values[$ind]/;
print OUT $input;
$ind = $ind+1;
}
}
if($input =~ m/<\/user>/)
{
print OUT $input;
}
}
}
if($input =~ m/<\/menu>/)
{
print OUT $input;
}
}
}

Error occurs with while Loop PHP / MySQL NuSOAP

I have created a PHP / MySQL based web service. I wrote client.php as mentioned here
and server.php as below:
<?php
require_once("lib/nusoap.php");
$host = $_SERVER['HTTP_HOST'];
$miURL = 'http://'.$host.'/WS-Demo';
$server = new nusoap_server();
$server->configureWSDL('L3M_WebService', $miURL);
$server->wsdl->schemaTargetNamespace=$miURL;
$server->register('getDemoData',
array('fldpara' => 'xsd:Array', 'tblpara' => 'xsd:Array', 'cndpara' => 'xsd:Array'),
array('return' => 'xsd:string'),
$miURL);
function decryptRJ256($string_to_decrypt)
{
$key = 'salt_key - I';
$iv = 'salt_key - II';
$string_to_decrypt = base64_decode($string_to_decrypt);
$rtn = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $string_to_decrypt, MCRYPT_MODE_CBC, $iv);
$rtn = rtrim($rtn, "\4");
return($rtn);
}
function encryptRJ256($string_to_encrypt)
{
$key = 'salt_key - I';
$iv = 'salt_key - II';
$rtn = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $string_to_encrypt, MCRYPT_MODE_CBC, $iv);
$rtn = base64_encode($rtn);
return($rtn);
}
function getDemoData($flds, $tbls, $cnds){
$mysqli = new mysqli("localhost", "root", "", "test");
for($i=0;$i< count($flds); $i++) {
$flds[$i] = decryptRJ256($flds[$i]);
}
for($i=0;$i< count($tbls); $i++) {
$tbls[$i] = decryptRJ256($tbls[$i]);
}
for($i=0;$i< count($cnds); $i++) {
$cnds[$i] = decryptRJ256($cnds[$i]);
}
if(! empty($flds)) {
$what = implode(", ", $flds);
} else {
$what = "*";
}
if(! empty($tbls)) {
$from = implode(", ", $tbls);
}else {
$err = 1;
}
if(! empty($cnds)) {
$cond = " WHERE ";
$cond .= $cnds[0] . " = '" . $cnds[1] . "'";
} else {
$cond = "";
}
$sql = "SELECT ".$what." FROM ".$from . $cond;
$rsGetData = $mysqli->query($sql);
$responseData = '<?xml version="1.0" encoding="UTF-8"?>
<L3MDataSets>';
while($rowGetData = $rsGetData->fetch_assoc()) {
$responseData .= '<L3DataSet>';
foreach($rowGetData as $k => $v) {
$responseData .= '<' . $k . '>' . $v . '</' . $k . '>';
}
$responseData .= '</L3DataSet>';
}
$responseData .= '</L3MDataSets>';
$responseData = encryptRJ256($responseData);
$responseString = new soapval('return', 'xsd:string', $responseData );
return $responseData;
}
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
From the Above code in the getDemoData function, if I remove the while loop, it gives the proper output. But when I put back the while loop it shows me output as "-Error: Response not of type text/xml: text/html" even if the SQL query is correct. I have copied and paste the generated SQL query which works in phpMyAdmin.

How to search a substring in PHP array using regExp

$array = array(
array('foo_test1','demo_test1'),
array('foo_test2','demo_test2'),
array('blah_test1','exp_test1'),
array('blah_test2','exp_test2'),
array('foo_test3','demo_test3')
)
How to get all subarray which contains foo substring with its value using php and regExp.
Expected Output:
$array = array(
array('foo_test1','demo_test1'),
array('foo_test2','demo_test2'),
array('foo_test3','demo_test3')
)
You should be able to do it with
preg_grep($pattern,$array)
$input = array( /* your array */ );
$output = array();
foreach ( $input as $data ) {
$len = length($data);
for ( $i = 0; $i < $len; ++$i ) {
if ( strpos($data[$i], 'foo') > -1 ) {
$output[] = $data;
break;
}
}
}
$array = array(
array('foo_test1','demo_test1'),
array('foo_test2','demo_test2'),
array('blah_test1','exp_test1'),
array('blah_test2','exp_test2'),
array('foo_test3','demo_test3')
);
$search = 'foo';
$res = array();
foreach ($array as $arr) {
foreach ($arr as $value) {
if (preg_match('~'.preg_quote($search,'~').'~',$value)) {
// if one of the values in that array
// has the search word in it...
$res[] = $arr; break;
// push it into the $res and break
// the inner foreach loop
}
}
}
print_r($res);

opencart site upgrade from version1.4.x to 1.5.x

I have upgrade my opencart site version 1.4.9.2 to version1.5.X,
I upgrade the database but don't know how to upgrade the files.
If there is any script regarding this please send me.
I use the script to update the table:-
<?php
# Upgrade Script Beta v2
// Run full install if config doesn't exist
if (!file_exists('../config.php')) {
header('Location: ./index.php');
exit;
}
set_error_handler("myErrorHandler");
// Configuration
require_once('../config.php');
// Startup
require_once(DIR_SYSTEM . 'startup.php');
// Get Path & Url
$errors = array();
$baseurl=(isset($_SERVER['HTTPS']) ? 'https' :'http'). '://' . $_SERVER['HTTP_HOST'] . str_replace('/install','',dirname($_SERVER['REQUEST_URI']));
chdir('..');
$basepath=getcwd();
chdir(dirname(__FILE__));
if (!$link = #mysql_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD)) {
$errors[] = 'Could not connect to the database server using the username and password provided.';
} else {
if (!#mysql_select_db(DB_DATABASE, $link)) {
$errors[] = 'The database could selected, check you have permissions, and check it exists on the server.';
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Installation</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>OpenCart 1.x Upgrade Script (BETA)</h1>
<div id="container">
<?php
function myErrorHandler($errno, $errstr, $errfile, $errline) {
echo "LINE $errline: [$errno] $errstr<br/>";
return;
}
if (empty($errors)) {
// Run upgrade script
$file='upgrade-14x-to-15x.no-opt.sql';
if (!file_exists($file)) {
$errors[] = 'Upgrade SQL file '.$file.' could not be found.';
} else {
mysql_query('set character set utf8', $link);
if ($sql=file($file)) {
$query = '';
foreach($sql as $line) {
// Hacks for compatibility (needs to be improved)
$line = str_replace("oc_", DB_PREFIX, $line);
$line = str_replace(" order ", " `order` ", $line);
$line = str_replace(" ssl ", " `ssl` ", $line);
$line = str_replace("NOT NULL DEFAULT ''", "NOT NULL", $line);
$line = str_replace("NOT NULL DEFAULT NULL", "NOT NULL", $line);
$line = str_replace("NOT NULL DEFAULT 0 COMMENT '' auto_increment", "NOT NULL COMMENT '' auto_increment", $line);
$line = trim($line);
//$line = str_replace(";", "", $line);
if ((substr(trim($line), 0, 2) == '--') || (substr(trim($line), 0, 1) == '#')) { continue; }
if (preg_match('/^ALTER TABLE (.+?) ADD PRIMARY KEY/', $line, $matches)) {
$res = mysql_query(sprintf("SHOW KEYS FROM %s",$matches[1]), $link);
$info = mysql_fetch_assoc(mysql_query(sprintf("SHOW KEYS FROM %s",$matches[1]), $link));
if ($info['Key_name'] == 'PRIMARY') { continue; }
}
if (preg_match('/^ALTER TABLE (.+?) ADD (.+?) /', $line, $matches)) {
if (mysql_num_rows(#mysql_query(sprintf("SHOW COLUMNS FROM %s LIKE '%s'", $matches[1],str_replace('`', '', $matches[2])), $link)) > 0) { continue; }
}
if (preg_match('/^ALTER TABLE (.+?) DROP (.+?) /', $line, $matches)) {
if (mysql_num_rows(#mysql_query(sprintf("SHOW COLUMNS FROM %s LIKE '%s'", $matches[1],str_replace('`', '', $matches[2])), $link)) <= 0) { continue; }
}
if (preg_match('/INNER JOIN (.+?) /', $line, $matches)) {
$xx = #mysql_query(sprintf("SHOW TABLES LIKE '%s'", str_replace('`', '', $matches[1])), $link);
if ($xx && mysql_num_rows($xx) <= 0) { continue; }
}
if (preg_match('/^DROP TABLE (.+?);/', $line, $matches)) {
if (preg_match('/^DROP TABLE IF EXISTS (.+?);/', $line, $matches2)) {
//if (mysql_num_rows(#mysql_query(sprintf("DESC %s", str_replace('`', '', $matches2[1])), $link)) <= 0) { continue; }
} else {
if (mysql_num_rows(#mysql_query(sprintf("SHOW TABLES LIKE '%s'", str_replace('`', '', $matches[1])), $link)) <= 0) { continue; }
}
}
if (strpos($line, 'ALTER TABLE') !== FALSE && strpos($line, 'DROP') !== FALSE && strpos($line, 'PRIMARY') === FALSE) {
$params = explode(' ', $line);
if ($params[3] == 'DROP') {
if (mysql_num_rows(#mysql_query("SHOW COLUMNS FROM $params[2] LIKE '$params[4]'", $link)) <= 0) { continue; }
}
}
if (preg_match('/^ALTER TABLE ([^\s]+) DEFAULT (.+?) /', $line, $matches)) {
if (mysql_num_rows(#mysql_query(sprintf("SHOW TABLES LIKE '%s'", str_replace('`', '', $matches[1])), $link)) <= 0) { continue; }
}
if (preg_match('/^ALTER TABLE (.+?) MODIFY (.+?) /', $line, $matches)) {
if (mysql_num_rows(#mysql_query(sprintf("SHOW COLUMNS FROM %s LIKE '%s'", $matches[1],str_replace('`', '', $matches[2])), $link)) <= 0) { continue; }
}
if (preg_match('/^ALTER TABLE (.+?) CHANGE (.+?) (.+?) /', $line, $matches)) {
if (mysql_num_rows(#mysql_query(sprintf("SHOW COLUMNS FROM %s LIKE '%s'", $matches[1],str_replace('`', '', $matches[2])), $link)) <= 0) {
continue;
}
// if it does exist, be sure the new name doesn't also exist. If so, then just delete it.
if (mysql_num_rows(#mysql_query(sprintf("SHOW COLUMNS FROM %s LIKE '%s'", $matches[1],str_replace('`', '', $matches[3])), $link)) > 0) {
#mysql_query(sprintf("ALTER TABLE %s DROP %s", $matches[1], str_replace('`', '', $matches[2])), $link); //Drop the column if it was supposed to be changed to a column that already exists
continue;
}
}
if (preg_match('/^DELETE FROM (.+?) WHERE (.+?) /', $line, $matches)) {
if (preg_match('~ WHERE (.*);$~', $line, $matches2)) {
if (preg_match_all('~`([^`]+)`~', $matches2[1], $matched)) {
$notfound = 0;
foreach ($matched[1] as $m) {
if (mysql_num_rows(#mysql_query(sprintf("SHOW COLUMNS FROM %s LIKE '%s'", $matches[1],str_replace('`', '', $m)), $link)) <= 0) {
$notfound++;
}
}
if ($notfound) { continue; }
}
}
}
if (preg_match('/^INSERT INTO (.+?) \(([^)]+)\) /', $line, $matches)) {
$parts = explode(",", str_replace("`", "", $matches[2]));
$notfound = 0;
foreach ($parts as $m) {
if (mysql_num_rows(#mysql_query(sprintf("SHOW COLUMNS FROM %s LIKE '%s'", $matches[1], trim($m)), $link)) <= 0) {
$notfound++;
}
}
if ($notfound) { continue; }
}
if (preg_match('/^INSERT INTO (.+?) \(([^)]+)\) SELECT ([^FROM]+) FROM `([^`]+)`/', $line, $matches)) {
$parts = explode(",", str_replace("`", "", $matches[3]));
$notfound = 0;
foreach ($parts as $m) {
if (mysql_num_rows(#mysql_query(sprintf("SHOW COLUMNS FROM %s LIKE '%s'", $matches[4], trim($m)), $link)) <= 0) {
$notfound++;
}
}
if ($notfound) { continue; }
}
//if (preg_match('/^ALTER TABLE (.+?) DEFAULT (.+?) /',$line,$matches)) {
// if (mysql_num_rows(#mysql_query(sprintf("SHOW COLUMNS FROM %s LIKE '%s'",$matches[1],str_replace('`','',$matches[2])), $link)) <= 0) { continue; }
//}
//if (preg_match('/^ALTER TABLE (.+?) ALTER (.+?) /',$line,$matches)) {
// if (mysql_num_rows(#mysql_query(sprintf("SHOW COLUMNS FROM %s LIKE '%s'",$matches[1],str_replace('`','',$matches[2])), $link)) <= 0) { continue; }
//}
if (!empty($line)) {
$query .= $line;
if (preg_match('/;\s*$/', $line)) {
if (mysql_query($query, $link) === false) {
$errors[] = 'Could not execute this query: ' . $query . ' ' . mysql_error($link);
}
$query = '';
}
}
}
}
}
}
// Check if there are any products associated with a store (pre-1.4.1)
$info = mysql_fetch_assoc(mysql_query("SELECT * FROM " . DB_PREFIX . "product_to_store", $link));
// If not, then add them all to the default
if (!$info) {
$resource = mysql_query("SELECT product_id FROM " . DB_PREFIX . "product", $link);
$data = array();
$i = 0;
while ($result = mysql_fetch_assoc($resource)) {
$data[$i] = $result;
$i++;
}
foreach ($data as $product) {
mysql_query("INSERT INTO " . DB_PREFIX . "product_to_store SET product_id = '".$product['product_id']."', store_id = '0'", $link);
}
}
// Check if there are any informations associated with a store (pre-1.4.1)
$info = mysql_fetch_assoc(mysql_query("SELECT * FROM " . DB_PREFIX . "information_to_store", $link));
// If not, then add them all to the default
if (!$info) {
$resource = mysql_query("SELECT information_id FROM " . DB_PREFIX . "information", $link);
$data = array();
$i = 0;
while ($result = mysql_fetch_assoc($resource)) {
$data[$i] = $result;
$i++;
}
foreach ($data as $information) {
mysql_query("INSERT INTO " . DB_PREFIX . "information_to_store SET information_id = '".$information['information_id']."', store_id = '0'", $link);
}
}
// Check if there are any categories associated with a store (pre-1.4.1)
$info = mysql_fetch_assoc(mysql_query("SELECT * FROM " . DB_PREFIX . "category_to_store", $link));
// If not, then add them all to the default
if (!$info) {
$resource = mysql_query("SELECT category_id FROM " . DB_PREFIX . "category", $link);
$data = array();
$i = 0;
while ($result = mysql_fetch_assoc($resource)) {
$data[$i] = $result;
$i++;
}
foreach ($data as $category) {
mysql_query("INSERT INTO " . DB_PREFIX . "category_to_store SET category_id = '".$category['category_id']."', store_id = '0'", $link);
}
}
// Check if there are any manufacturers associated with a store (pre-1.4.1)
$info = mysql_fetch_assoc(mysql_query("SELECT * FROM " . DB_PREFIX . "manufacturer_to_store", $link));
// If not, then add them all to the default
if (!$info) {
$resource = mysql_query("SELECT manufacturer_id FROM " . DB_PREFIX . "manufacturer", $link);
$data = array();
$i = 0;
while ($result = mysql_fetch_assoc($resource)) {
$data[$i] = $result;
$i++;
}
foreach ($data as $manufacturer) {
mysql_query("INSERT INTO " . DB_PREFIX . "manufacturer_to_store SET manufacturer_id = '".$manufacturer['manufacturer_id']."', store_id = '0'", $link);
}
}
######################################
# START 1.5.x UPGRADE CODE
######################################
/**
* Convert Store table to Setting table
*/
$sql = "SELECT * FROM " . DB_PREFIX . "store";
$resource = mysql_query($sql, $link);
if ($resource) {
if (is_resource($resource)) {
$i = 0;
$data = array();
while ($result = mysql_fetch_assoc($resource)) {
$data[$i] = $result;
$i++;
}
mysql_free_result($resource);
}
}
// Only run if coming from 1.4.x to 1.5.x. Skip if coming from another 1.5.x version
if ($data && isset($data[0]['zone_id'])) {
$storedata = array();
foreach ($data as $d) {
$storedata[$d['store_id']] = $d;
unset($storedata[$d['store_id']]['store_id']);
}
foreach ($storedata as $store_id => $value) {
// Verify the store id doesn't already exist
$qry = mysql_fetch_assoc(mysql_query("SELECT * FROM " . DB_PREFIX . "setting WHERE store_id = '" . (int)$store_id . "'", $link));
if ($qry) { continue; }
// New store fields
if (!isset($value['address'])) { $value['address'] = '' ;}
if (!isset($value['email'])) { $value['email'] = '' ;}
if (!isset($value['telephone'])) { $value['telephone'] = '' ;}
if (!isset($value['fax'])) { $value['fax'] = '' ;}
if (!isset($value['layout'])) { $value['layout'] = '' ;}
if (!isset($value['image_compare_height'])) { $value['image_compare_height'] = '' ;}
if (!isset($value['image_compare_width'])) { $value['image_compare_width'] = '' ;}
if (!isset($value['image_manufacturer_height'])) { $value['image_manufacturer_height'] = '' ;}
if (!isset($value['image_manufacturer_width'])) { $value['image_manufacturer_width'] = '' ;}
if (!isset($value['image_wishlist_height'])) { $value['image_wishlist_height'] = '' ;}
if (!isset($value['image_wishlist_width'])) { $value['image_wishlist_width'] = '' ;}
// special case
if (!isset($value['use_ssl'])) { $value['use_ssl'] = $value['ssl'] ;}
if (!isset($value['ssl'])) {
if ($value['use_ssl']) {
$value['ssl'] = str_replace('http://', 'https://', $value['url']);
} else {
$value['ssl'] = $value['url'];
}
mysql_query("INSERT INTO " . DB_PREFIX . "store SET `ssl` = '" . $value['ssl'] . "' WHERE store_id = '" . (int)$store_id . "', `group` = 'config'", $link);
}
foreach ($value as $k => $v) {
mysql_query("INSERT INTO " . DB_PREFIX . "setting SET `key` = 'config_" . $k . "', `value` = '" . $v . "', store_id = '" . (int)$store_id . "', `group` = 'config'", $link);
}
}
$sql = "ALTER TABLE `" . DB_PREFIX . "store`
DROP `title`,
DROP `meta_description`,
DROP `template`,
DROP `country_id`,
DROP `zone_id`,
DROP `language`,
DROP `currency`,
DROP `tax`,
DROP `customer_group_id`,
DROP `customer_price`,
DROP `customer_approval`,
DROP `guest_checkout`,
DROP `account_id`,
DROP `checkout_id`,
DROP `stock_display`,
DROP `stock_check`,
DROP `stock_checkout`,
DROP `order_status_id`,
DROP `logo`,
DROP `icon`,
DROP `image_thumb_width`,
DROP `image_thumb_height`,
DROP `image_popup_width`,
DROP `image_popup_height`,
DROP `image_category_width`,
DROP `image_category_height`,
DROP `image_product_width`,
DROP `image_product_height`,
DROP `image_additional_width`,
DROP `image_additional_height`,
DROP `image_related_width`,
DROP `image_related_height`,
DROP `image_cart_width`,
DROP `image_cart_height`,
DROP `catalog_limit`,
DROP `cart_weight`,
AUTO_INCREMENT=1;";
mysql_query($sql, $link);
}
/**
* Convert Options to Global Options
*/
/*
# Convert options over.. big job
ALTER TABLE `oc_order_option`
ADD `product_option_id` int(11) NOT NULL DEFAULT 0 COMMENT '' AFTER order_product_id,
ADD `type` varchar(32) NOT NULL DEFAULT '' COMMENT '' COLLATE utf8_bin AFTER value,
MODIFY `value` text NOT NULL DEFAULT '' COMMENT '' COLLATE utf8_bin,
DROP `price`,
DROP `prefix`;
ALTER TABLE `oc_product_option`
ADD `option_id` int(11) NOT NULL DEFAULT 0 COMMENT '' AFTER product_id,
ADD `option_value` text NOT NULL DEFAULT '' COMMENT '' COLLATE utf8_bin AFTER option_id,
ADD `required` int(1) NOT NULL DEFAULT 0 COMMENT '' AFTER option_value,
DROP `sort_order`;
DROP TABLE `oc_product_option_description`;
ALTER TABLE `oc_product_option_value`
ADD `option_id` int(11) NOT NULL DEFAULT 0 COMMENT '' AFTER product_id,
ADD `option_value_id` int(11) NOT NULL DEFAULT 0 COMMENT '' AFTER option_id,
ADD `price_prefix` varchar(1) NOT NULL DEFAULT '' COMMENT '' COLLATE utf8_bin AFTER price,
ADD `points` int(8) NOT NULL DEFAULT 0 COMMENT '' AFTER price_prefix,
ADD `points_prefix` varchar(1) NOT NULL DEFAULT '' COMMENT '' COLLATE utf8_bin AFTER points,
ADD `weight` decimal(15,8) NOT NULL DEFAULT '' COMMENT '' AFTER points_prefix,
ADD `weight_prefix` varchar(1) NOT NULL DEFAULT '' COMMENT '' COLLATE utf8_bin AFTER weight,
MODIFY `quantity` int(3) NOT NULL DEFAULT 0 COMMENT '',
ALTER `subtract` DROP DEFAULT,
DROP `prefix`,
DROP `sort_order`;
DROP TABLE `oc_product_option_value_description`;
write this back to the config.php
// HTTP
define('HTTP_SERVER', 'http://localhost/v150/');
define('HTTP_IMAGE', 'http://localhost/v150/image/');
define('HTTP_ADMIN', 'http://localhost/v150/admin/');
// HTTPS
define('HTTPS_SERVER', 'http://localhost/v150/');
define('HTTPS_IMAGE', 'http://localhost/v150/image/');
*/
if (!empty($errors)) { //has to be a separate if
?>
<p>The following errors occured:</p>
<?php foreach ($errors as $error) {?>
<div class="warning"><?php echo $error;?></div><br />
<?php } ?>
<p>The above errors occurred because the script could not properly determine the existing state of those db elements. Your store may not need those changes. Please post any errors on the forums to ensure that they can be addressed in future versions!</p>
</div>
<?php } else { ?>
<h2>SUCCESS!!! Click here to goto your store</h2>
<?php } ?>
<div class="center">OpenCart.com</div>
</body>
</html>
Please try this script. Instructions also available. http://forum.opencart.com/viewtopic.php?t=50292
I dont know a script that is able to update the Opencart files. You simply need to empty your FTP and upload the 1.5.x package. If you're using any (custom) modules, you'll need to re-install them. But be carefull, because modules developed for 1.4.x are not automatically compatible with 1.5.x.