Kerm Posted October 7, 2014 Share Posted October 7, 2014 (edited) Prestashop 1.6.0.10 have changes in file AdminImportController.php, we see here new function http_build_url, but i have problem with that when import products with images, i have this error: "Call to undefined function http_build_url". After i saw this error i go search in google across this problem and find some info about, some ppl say need to install pecl_http on server for fix this problem, but not all have this on server and some shared hosting cant have this. I have php-fpm with nginx on server, after i try install pecl_http i still see this error, i try use function: if (!function_exists('http_build_url')) { define('HTTP_URL_REPLACE', 1); // Replace every part of the first URL when there's one of the second URL define('HTTP_URL_JOIN_PATH', 2); // Join relative paths define('HTTP_URL_JOIN_QUERY', 4); // Join query strings define('HTTP_URL_STRIP_USER', 8); // Strip any user authentication information define('HTTP_URL_STRIP_PASS', 16); // Strip any password authentication information define('HTTP_URL_STRIP_AUTH', 32); // Strip any authentication information define('HTTP_URL_STRIP_PORT', 64); // Strip explicit port numbers define('HTTP_URL_STRIP_PATH', 128); // Strip complete path define('HTTP_URL_STRIP_QUERY', 256); // Strip query string define('HTTP_URL_STRIP_FRAGMENT', 512); // Strip any fragments (#identifier) define('HTTP_URL_STRIP_ALL', 1024); // Strip anything but scheme and host // Build an URL // The parts of the second URL will be merged into the first according to the flags argument. // // @param mixed (Part(s) of) an URL in form of a string or associative array like parse_url() returns // @param mixed Same as the first argument // @param int A bitmask of binary or'ed HTTP_URL constants (Optional)HTTP_URL_REPLACE is the default // @param array If set, it will be filled with the parts of the composed url like parse_url() would return function http_build_url($url, $parts=array(), $flags=HTTP_URL_REPLACE, &$new_url=false) { $keys = array('user','pass','port','path','query','fragment'); // HTTP_URL_STRIP_ALL becomes all the HTTP_URL_STRIP_Xs if ($flags & HTTP_URL_STRIP_ALL) { $flags |= HTTP_URL_STRIP_USER; $flags |= HTTP_URL_STRIP_PASS; $flags |= HTTP_URL_STRIP_PORT; $flags |= HTTP_URL_STRIP_PATH; $flags |= HTTP_URL_STRIP_QUERY; $flags |= HTTP_URL_STRIP_FRAGMENT; } // HTTP_URL_STRIP_AUTH becomes HTTP_URL_STRIP_USER and HTTP_URL_STRIP_PASS else if ($flags & HTTP_URL_STRIP_AUTH) { $flags |= HTTP_URL_STRIP_USER; $flags |= HTTP_URL_STRIP_PASS; } // Parse the original URL $parse_url = parse_url($url); // Scheme and Host are always replaced if (isset($parts['scheme'])) $parse_url['scheme'] = $parts['scheme']; if (isset($parts['host'])) $parse_url['host'] = $parts['host']; // (If applicable) Replace the original URL with it's new parts if ($flags & HTTP_URL_REPLACE) { foreach ($keys as $key) { if (isset($parts[$key])) $parse_url[$key] = $parts[$key]; } } else { // Join the original URL path with the new path if (isset($parts['path']) && ($flags & HTTP_URL_JOIN_PATH)) { if (isset($parse_url['path'])) $parse_url['path'] = rtrim(str_replace(basename($parse_url['path']), '', $parse_url['path']), '/') . '/' . ltrim($parts['path'], '/'); else $parse_url['path'] = $parts['path']; } // Join the original query string with the new query string if (isset($parts['query']) && ($flags & HTTP_URL_JOIN_QUERY)) { if (isset($parse_url['query'])) $parse_url['query'] .= '&' . $parts['query']; else $parse_url['query'] = $parts['query']; } } // Strips all the applicable sections of the URL // Note: Scheme and Host are never stripped foreach ($keys as $key) { if ($flags & (int)constant('HTTP_URL_STRIP_' . strtoupper($key))) unset($parse_url[$key]); } $new_url = $parse_url; return .((isset($parse_url['user'])) ? $parse_url['user'] . ((isset($parse_url['pass'])) ? ':' . $parse_url['pass'] : '') .'@' : '') .((isset($parse_url['host'])) ? $parse_url['host'] : '') .((isset($parse_url['port'])) ? ':' . $parse_url['port'] : '') .((isset($parse_url['path'])) ? $parse_url['path'] : '') .((isset($parse_url['query'])) ? '?' . $parse_url['query'] : '') .((isset($parse_url['fragment'])) ? '#' . $parse_url['fragment'] : '') ; } } and this is work! Hope its help to some one. P.S.: This function need to place in top of AdminImportController.php file. Edited October 7, 2014 by Kerm (see edit history) 1 Link to comment Share on other sites More sharing options...
Kerm Posted October 7, 2014 Author Share Posted October 7, 2014 Also need change code in file AdminImportController.php on this: if (isset($parced_url['path'])) { $url_path = ltrim($parced_url['path'], '/'); $parts = explode('/', $url_path); foreach ($parts as &$part) $part = urlencode ($part); unset($part); $parced_url['path'] = implode('/', $parts); } Btw: for what some one change this: $url = str_replace(' ', '%20', trim($url)); on this: $url = urldecode(trim($url)); $parced_url = parse_url($url); if (isset($parced_url['path'])) { $url_path = ltrim($parced_url['path'], '/'); $parts = explode('/', $url_path); foreach ($parts as &$part) $part = urlencode ($part); unset($part); $parced_url['path'] = implode('/', $parts); } if (isset($parced_url['query'])) { $query_parts = array(); parse_str($parced_url['query'], $query_parts); $parced_url['query'] = http_build_query($query_parts); } $url = http_build_url('', $parced_url); ?This code remove from link hash, login, passwords and some characters as i see...but for what? Link to comment Share on other sites More sharing options...
tuk66 Posted October 9, 2014 Share Posted October 9, 2014 Are you sure that PrestaShop 1.6.0.10 really changed AdminImportController.php file? I haven't seen any use of http_build_url function. There is only 1 change in this file, comparing to PS 1.6.0.8. Link to comment Share on other sites More sharing options...
Kerm Posted October 9, 2014 Author Share Posted October 9, 2014 (edited) Watch here: https://github.com/PrestaShop/PrestaShop/blob/1.6/controllers/admin/AdminImportController.phpBut they alrdy fix that problem on github with that code: if (isset($parced_url['query'])) { $query_parts = array(); parse_str($parced_url['query'], $query_parts); if (!function_exists('http_build_url')) require_once(_PS_TOOL_DIR_.'http_build_query/http_build_query.php'); $parced_url['query'] = http_build_query($query_parts); } Lol they made file http_build_query.php with my code) nice Edited October 9, 2014 by Kerm (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts