public function write($type, $object, $message = '') { $data = array(0 => '', 1 => '', 2 => ''); if ($type == self::SKIP_PRODUCT) { $product_name = fn_substr($object['product'], 0, 20); if (strlen($object['product']) > 20) { $product_name .= "..."; } $data[0] = '[SKIP PRODUCT]'; $data[1] = $object['product_id'] . " (" . $product_name . ") - "; $data[2] = $message; } elseif ($type == self::INFO) { $data[0] = '[INFO]'; if (!is_array($object)) { $data[1] = $object; } if (!empty($message)) { $data[2] = $message; } } if (!fn_is_empty($data)) { if ($this->format == 'csv') { fwrite($this->file, $this->csv($data) . PHP_EOL); } else { fwrite($this->file, implode(' ', $data) . PHP_EOL); } } }
/** * Smarty truncate modifier plugin * * Type: modifier<br> * Name: truncate<br> * Purpose: Truncate a string to a certain length if necessary, * optionally splitting in the middle of a word, and * appending the $etc string or inserting $etc into the middle. * @link http://smarty.php.net/manual/en/language.modifier.truncate.php * truncate (Smarty online manual) * @author Monte Ohrt <monte at ohrt dot com> * @param string * @param integer * @param string * @param boolean * @param boolean * @return string */ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false) { if ($length == 0) { return ''; } if (Registry::get('runtime.customization_mode.translation') && preg_match('/(\\[lang name\\=[\\w-]+?( [pre\\-ajx]*)?\\])(.*?)(\\[\\/lang\\])/is', $string, $matches)) { list(, $pre, , $string, $post) = $matches; } else { $pre = $post = ''; } if (fn_strlen($string) > $length) { $length -= min($length, fn_strlen($etc)); if (!$break_words && !$middle) { $string = preg_replace('/\\s+?(\\S+)?$/u', '', fn_substr($string, 0, $length + 1)); } if (!$middle) { return fn_substr($string, 0, $length) . $etc; } else { return fn_substr($string, 0, $length / 2) . $etc . fn_substr($string, -$length / 2); } } else { return $string; } }
/** * Deletes all thumbnails of specified file * * @param string $filename file name * @param string $prefix path prefix * @return boolean always true */ function fn_delete_image_thumbnails($filename, $prefix = '') { $filename = fn_substr($filename, 0, strrpos($filename, '.')); if (!empty($filename)) { Storage::instance('images')->deleteByPattern($prefix . 'thumbnails/*/*/' . $filename . '*'); } return true; }
function fn_basename($path, $suffix = '', $encoding = 'UTF-8') { $basename = explode("/", $path); $basename = end($basename); if (!empty($suffix) && fn_substr($basename, 0 - fn_strlen($suffix, $encoding), fn_strlen($basename, $encoding), $encoding) == $suffix) { $basename = fn_substr($basename, 0, 0 - fn_strlen($suffix, $encoding), $encoding); } /* Remove query params Original: http://somehost.com/images/test.jpg?12345678 Bad result: test.jpg?12345678 Correct result: test.jpg */ list($basename) = explode('?', $basename); return $basename; }
function fn_send_sms_notification($body) { $access_data = fn_get_sms_auth_data(); $to = Registry::get('addons.sms_notifications.phone_number'); if (fn_is_empty($access_data) || empty($to)) { return false; } $concat = Registry::get('addons.sms_notifications.clickatel_concat'); //get the last symbol if (!empty($concat)) { $concat = intval($concat[strlen($concat) - 1]); } if (!in_array($concat, array('1', '2', '3'))) { $concat = 1; } $data = array('user' => $access_data['login'], 'password' => $access_data['password'], 'api_id' => $access_data['api_id'], 'to' => $to, 'concat' => $concat); $unicode = Registry::get('addons.sms_notifications.clickatel_unicode') == 'Y' ? 1 : 0; $sms_length = $unicode ? SMS_NOTIFICATIONS_SMS_LENGTH_UNICODE : SMS_NOTIFICATIONS_SMS_LENGTH; if ($concat > 1) { $sms_length *= $concat; $sms_length -= $concat * SMS_NOTIFICATIONS_SMS_LENGTH_CONCAT; // If a message is concatenated, it reduces the number of characters contained in each message by 7 } $body = html_entity_decode($body, ENT_QUOTES); $body = fn_substr($body, 0, $sms_length); if ($unicode) { $data['unicode'] = '1'; $body = fn_convert_encoding('UTF-8', 'UCS-2', $body); $codes = ''; for ($i = 0; $i < strlen($body); $i++) { $codes .= sprintf('%02X', ord($body[$i])); } $body = $codes; $body = urlencode($body); } $data['text'] = $body; fn_http_request('GET', 'http://api.clickatell.com/http/sendmsg', $data); }
} // gateway_fast_registration $post_data['firstname'] = $order_info['b_firstname']; $post_data['lastname'] = $order_info['b_lastname']; $post_data['pay_from_email'] = $order_info['email']; //$post_data['pay_from_email'] = rand(). "@" . rand() . ".com"; // uncomment to test hide login feature $post_data['address'] = $order_info['b_address']; $post_data['address2'] = $order_info['b_address_2']; $post_data['postal_code'] = $order_info['b_zipcode']; $post_data['city'] = $order_info['b_city']; $post_data['state'] = fn_get_state_name($order_info['b_state'], $order_info['b_country']); if (empty($post_data['state'])) { $post_data['state'] = $order_info['b_state']; } if (fn_strlen($post_data['state']) > 50) { $post_data['state'] = fn_substr($post_data['state'], 0, 47) . '...'; } $post_data['country'] = db_get_field('SELECT code_A3 FROM ?:countries WHERE code=?s', $order_info['b_country']); $post_data['phone_number'] = $order_info['phone']; if ($processor_data['processor_params']['quick_checkout'] == 'Y') { $post_data['payment_methods'] = !empty($processor_data['processor_params']['payment_methods']) ? '' : 'ACC'; $post_data['hide_login'] = '******'; } else { $post_data['payment_methods'] = 'WLT'; $post_data['hide_login'] = !empty($suffix) ? '1' : '0'; } // split_gateway if (!empty($processor_data['processor_params']['payment_methods'])) { $post_data['payment_methods'] .= (!empty($post_data['payment_methods']) ? ',' : '') . $processor_data['processor_params']['payment_methods']; } // /split_gateway
function fn_paypal_substr($str, $maxlen = MAX_PAYPAL_DESCR_LENGTH) { $str = fn_substr($str, 0, $maxlen); if (strlen($str) > $maxlen) { $str = fn_substr($str, 0, $maxlen / 2); } return $str; }
function fn_sales_repors_format_description($value, $limit, $id) { if (strlen($value) > fn_strlen($value)) { $limit /= 2; } return fn_strlen($value) > $limit ? $id . fn_substr($value, 0, $limit) . "..." : $id . $value; }
function fn_format_long_string($str, $length) { if (fn_strlen($str) <= $length) { return $str; } $length = $length - 3; return fn_substr($str, 0, $length) . '...'; }
/** * Get products as API list * @param array $params * @param integer $items_per_page * @param string $lang_code * @return array array('products' => array(), 'params' => array()) */ function fn_twg_api_get_products($params, $items_per_page = 10, $lang_code = CART_LANGUAGE) { $to_unserialize = array('extend', 'variants'); foreach ($to_unserialize as $field) { if (!empty($params[$field]) && is_string($params[$field])) { $params[$field] = unserialize($params[$field]); } } if (empty($params['extend'])) { $params['extend'] = array('description'); } if (!empty($params['pid']) && !is_array($params['pid'])) { $params['pid'] = explode(',', $params['pid']); } if (!empty($params['q'])) { // search by product code $params['ppcode'] = 'Y'; $params['subcats'] = 'Y'; $params['status'] = 'A'; $params['pshort'] = 'Y'; $params['pfull'] = 'Y'; $params['pname'] = 'Y'; $params['pkeywords'] = 'Y'; $params['search_performed'] = 'Y'; } if (isset($params['company_id']) and $params['company_id'] == 0) { unset($params['company_id']); } if (empty($params['page'])) { $params['page'] = 1; } list($products, $params) = fn_get_products($params, $items_per_page, $lang_code); fn_gather_additional_products_data($products, array('get_icon' => true, 'get_detailed' => true, 'get_options' => true, 'get_discounts' => true, 'get_features' => false)); if (empty($products)) { return array(array(), array()); } $product_ids = array(); $image_params = TwigmoSettings::get('images.catalog'); foreach ($products as $k => $v) { if (!empty($products[$k]['short_description']) || !empty($products[$k]['full_description'])) { $products[$k]['short_description'] = !empty($products[$k]['short_description']) ? strip_tags($products[$k]['short_description']) : fn_substr(strip_tags($products[$k]['full_description']), 0, TWG_MAX_DESCRIPTION_LEN); unset($products[$k]['full_description']); } else { $products[$k]['short_description'] = ''; } $product_ids[] = $v['product_id']; // Get product image data if (!empty($v['main_pair'])) { $products[$k]['icon'] = TwigmoImage::getApiImageData($v['main_pair'], 'product', 'icon', $image_params); } } $category_descr = !empty($product_ids) ? db_get_hash_array("SELECT p.product_id, p.category_id, c.category\n FROM ?:products_categories AS p, ?:category_descriptions AS c\n WHERE c.category_id = p.category_id\n AND c.lang_code = ?s\n AND p.product_id IN (?a)\n AND p.link_type = 'M'", 'product_id', $lang_code, $product_ids) : array(); foreach ($products as $key => $product) { if (!empty($product['product_id']) && !empty($category_descr[$product['product_id']])) { $products[$key]['category'] = $category_descr[$product['product_id']]['category']; $products[$key]['category_id'] = $category_descr[$product['product_id']]['category_id']; } if (!empty($product['inventory_amount']) && $product['inventory_amount'] > $product['amount']) { $products[$key]['amount'] = $product['inventory_amount']; } } $result = Api::getAsList('products', $products); return array($result, $params); }
/** * substr() with full UTF-8 support * * @param string $string The input string. * @param integer $start If start is non-negative, the returned string will start at the start 'th position in string , counting from zero. If start is negative, the returned string will start at the start 'th character from the end of string. * @param integer $length If length is given and is positive, the string returned will contain at most length characters beginning from start (depending on the length of string ). If length is given and is negative, then that many characters will be omitted from the end of string (after the start position has been calculated when a start is negative). If start denotes a position beyond this truncation, an empty string will be returned. * @param integer $encoding The encoding parameter is the character encoding. If it is omitted, UTF-8 character encoding value will be used. * @return mixed Returns the extracted part of string or false if string is less than or equal to start characters long */ function fn_substr($string, $start, $length = null, $encoding = 'UTF-8') { if (empty($encoding)) { $encoding = 'UTF-8'; } if ($length === null) { return fn_substr($string, $start, fn_strlen($string, $encoding), $encoding); } if (function_exists('iconv_substr')) { // there was strange bug in iconv_substr when use negative length parameter // so we recalculate start and length here if ($length < 0) { $length = ceil($length); $len = iconv_strlen($string, $encoding); if ($start < 0) { $start += $len; } $length += $len - $start; } return iconv_substr($string, $start, $length, $encoding); } elseif (function_exists('mb_substr')) { return mb_substr($string, $start, $length, $encoding); } else { preg_match_all('/./su', $string, $ar); return join('', array_slice($ar[0], $start, $length)); } }
function fn_basename($path, $suffix = '', $encoding = 'UTF-8') { $basename = explode("/", $path); $basename = end($basename); if (!empty($suffix) && fn_substr($basename, 0 - fn_strlen($suffix, $encoding), fn_strlen($basename, $encoding), $encoding) == $suffix) { $basename = fn_substr($basename, 0, 0 - fn_strlen($suffix, $encoding), $encoding); } return $basename; }
} } if ($mode == 'view_all') { $filter_id = !empty($_REQUEST['filter_id']) ? $_REQUEST['filter_id'] : 0; if (empty($filter_id)) { return array(CONTROLLER_STATUS_NO_PAGE); } list($filters) = fn_get_filters_products_count($_REQUEST); if (empty($filters[$filter_id])) { return array(CONTROLLER_STATUS_NO_PAGE); } fn_add_breadcrumb($filters[$filter_id]['filter']); $variants = array(); if (!empty($filters[$filter_id]['variants'])) { foreach ($filters[$filter_id]['variants'] as $variant) { $variants[fn_substr($variant['variant'], 0, 1)][] = $variant; } } ksort($variants); Registry::get('view')->assign('variants', $variants); } elseif ($mode == 'view') { $variant_data = fn_get_product_feature_variant($_REQUEST['variant_id']); Registry::get('view')->assign('variant_data', $variant_data); fn_add_breadcrumb($variant_data['variant']); // Override meta description/keywords if (!empty($variant_data['meta_description']) || !empty($variant_data['meta_keywords'])) { Registry::get('view')->assign('meta_description', $variant_data['meta_description']); Registry::get('view')->assign('meta_keywords', $variant_data['meta_keywords']); } // Override page title if (!empty($variant_data['page_title'])) {
function fn_sales_repors_format_description($value, $limit, $id) { return $limit !== null && fn_strlen($value) > $limit ? $id . fn_substr($value, 0, $limit) . "..." : $id . $value; }
function fn_rus_unisender_place_order($order_id, $action, $order_status, $cart, $auth) { if (Registry::get('addons.rus_unisender.send_sms_admin') == 'Y') { $admin_phone = Registry::get('addons.rus_unisender.admin_phone'); if (!empty($admin_phone)) { $storefront = fn_get_company_name(fn_get_company_id('orders', 'order_id', $order_id)); $text = Registry::get('addons.rus_unisender.send_sms_admin_text'); $text = str_replace('[order_id]', $order_id, $text); $text = str_replace('[storefront]', $storefront, $text); $post = array('api_key' => Registry::get('addons.rus_unisender.api_key'), 'phone' => $admin_phone, 'sender' => fn_substr(Registry::get('addons.rus_unisender.admin_sender'), 0, 11), 'text' => $text); if (!fn_unisender_api('sendSms', $post, $response)) { $email = Registry::get('settings.Company.company_site_administrator'); Mailer::sendMail(array('to' => $email, 'from' => 'company_site_administrator', 'data' => array('phone' => $admin_phone, 'error' => $response), 'tpl' => 'addons/rus_unisender/unisender.tpl', 'company_id' => fn_get_company_id('orders', 'order_id', $order_id)), 'C', CART_LANGUAGE); } } } }