function cp_get_thumb_url($url, $options = array()) { if (!empty($options)) { $url_part = '/'; foreach ($options as $k => $v) { $url_part .= substr($k, 0, 1) . "{$v}-"; } $url_part = trim($url_part, '-'); $url = $url_part . '/' . trim($url, '/'); $url = '/' . basename(IMG_CACHE_PATH) . $url . '?' . cp_thumb_url_hash($url); } return $url; }
define('BASE_PATH', dirname(dirname(dirname(__FILE__)))); define('IMG_CACHE_PATH', BASE_PATH . '/resize'); include BASE_PATH . '/lib/BitrixHelperLib/common_lib.php'; error_reporting(E_ALL); ini_set('display_error', 'On'); try { $path_string = trim(str_replace(array('..', '\\'), '', urldecode($_REQUEST['__path'])), '/'); $path = explode('/', $path_string); $temp = array_diff_key($_REQUEST, array('__path' => '')); if (!is_array($temp)) { throw new Exception('Protection code not found'); } if (!($hash = key($temp))) { throw new Exception('Protection code not found'); } $checkHash = cp_thumb_url_hash($_REQUEST['__path']); if ($checkHash != $hash) { throw new Exception('Wrong protection code'); } $excepted_params = array('w', 'h', 't', 'm', 's', 'e', 'b', 'd'); $params = array(); $temp = explode('-', $path[0]); foreach ($temp as $k) { $key = substr($k, 0, 1); if (!in_array($key, $excepted_params)) { throw new Exception('Unexpected param: ' . $key); } $params[$key] = substr($k, 1); } if (!empty($params)) { array_shift($path);
function cp_get_thumb_url($url, $options = array()) { $initialUrl = $url; if (!empty($options)) { $url_part = '/'; foreach ($options as $k => $v) { $url_part .= substr($k, 0, 1) . "{$v}-"; } $url_part = trim($url_part, '-'); $url = $url_part . '/' . trim($url, '/'); $url = '/' . basename(IMG_CACHE_PATH) . $url . '?' . cp_thumb_url_hash($url); } if (defined('CP_GET_THUMB_URL_GENERATE') && CP_GET_THUMB_URL_GENERATE) { cp_generate_thumb($initialUrl, $url, $options); } return $url; }