Esempio n. 1
0
 /**
  * Output filter: Transforms URLs to the appropriate format for the embedded mode
  * @param  string                    $content  template content
  * @param  \Smarty_Internal_Template $template template instance
  * @return string                    template content
  */
 public static function outputEmbeddedUrl($content, \Smarty_Internal_Template $template)
 {
     $path = Registry::get('config.current_host') . Registry::get('config.current_path');
     // Transform 'href' attribute values of the 'a' elements, which:
     // - have 'href' attribute
     // - the 'href' value contains current path and host, or its a relative url
     // - do not have class attribute starting with 'cm-' prefix
     $pattern = '{' . '<(?:a)\\s+' . '(?=[^>]*\\bhref="([^"]*//' . $path . '[^"]*|(?!//)(?!https?)[^"]*)")' . '(?![^>]*\\bclass="[^"]*cm-[^"]*")' . '[^>]*>' . '}Usi';
     $content = preg_replace_callback($pattern, function ($matches) {
         return str_replace($matches[1], Embedded::resolveUrl($matches[1]), $matches[0]);
     }, $content);
     // Transform relative 'src'attribute values
     $pattern = '{<[^>]+\\bsrc="((?!//)(?!https?)[^"]+)"[^>]*>}Usi';
     $content = preg_replace_callback($pattern, function ($matches) {
         return str_replace($matches[1], Url::resolve($matches[1], Registry::get('config.current_location')), $matches[0]);
     }, $content);
     $area = Registry::get('view')->getArea();
     if ($area[1] == 'mail') {
         // Transform URLs in the text
         $pattern = '{\\bhttps?://' . $path . '[^\\s<>"\']*(?=[^>]*<)}s';
         $content = preg_replace_callback($pattern, function ($matches) {
             return Embedded::resolveUrl($matches[0]);
         }, $content);
     }
     return $content;
 }
Esempio n. 2
0
 /**
  * Resolves URL to the format appropriate for widget mode
  *
  * @param string $url URL
  */
 public static function resolveUrl($url)
 {
     $url = str_replace('&amp;', '&', $url);
     if (parse_url($url, PHP_URL_SCHEME) == '' && strpos($url, '//') !== 0) {
         $url = Url::resolve($url, Registry::get('config.current_location'));
     }
     $path = Registry::get('config.current_host') . Registry::get('config.current_path');
     if (false !== ($pos = strpos($url, $path))) {
         $query = urlencode(substr($url, $pos + strlen($path)));
         $params = self::getParams();
         if (!empty($params['fb_app_id']) && !empty($params['fb_page_id'])) {
             $url = sprintf("https://www.facebook.com/pages/~/%s?sk=app_%s&app_data=%s", $params['fb_page_id'], $params['fb_app_id'], $query);
         } else {
             $url = self::getUrl() . "#!{$query}";
         }
     }
     return $url;
 }
Esempio n. 3
0
function fn_exim_get_image_url($product_id, $object_type, $pair_type, $get_icon, $get_detailed, $lang_code)
{
    $image_pair = fn_get_image_pairs($product_id, $object_type, $pair_type, true, true, $lang_code);
    $image_data = fn_image_to_display($image_pair, Registry::get('settings.Thumbnails.product_details_thumbnail_width'), Registry::get('settings.Thumbnails.product_details_thumbnail_height'));
    if (!empty($image_data['image_path'])) {
        $url = new Url($image_data['image_path']);
        $url->setProtocol(fn_get_storefront_protocol());
        return $url->build($url->getIsEncoded());
    }
    return '';
}
function fn_update_company($company_data, $company_id = 0, $lang_code = CART_LANGUAGE)
{
    $can_update = true;
    /**
     * Update company data (running before fn_update_company() function)
     *
     * @param array   $company_data Company data
     * @param int     $company_id   Company identifier
     * @param string  $lang_code    Two-letter language code (e.g. 'en', 'ru', etc.)
     * @param boolean $can_update   Flag, allows addon to forbid to create/update company
     */
    fn_set_hook('update_company_pre', $company_data, $company_id, $lang_code, $can_update);
    if ($can_update == false) {
        return false;
    }
    if (fn_allowed_for('MULTIVENDOR') && Registry::get('runtime.company_id')) {
        unset($company_data['comission'], $company_data['comission_type'], $company_data['categories'], $company_data['shippings']);
    } elseif (fn_allowed_for('ULTIMATE') && Registry::get('runtime.company_id')) {
        unset($company_data['storefront'], $company_data['secure_storefront']);
    }
    if (fn_allowed_for('ULTIMATE') && !Registry::get('runtime.company_id')) {
        if (isset($company_data['storefront'])) {
            if (empty($company_data['storefront'])) {
                fn_set_notification('E', __('error'), __('storefront_url_not_defined'));
                return false;
            } else {
                if (empty($company_data['secure_storefront'])) {
                    $company_data['secure_storefront'] = $company_data['storefront'];
                }
                $company_data['storefront'] = Url::clean($company_data['storefront']);
                $company_data['secure_storefront'] = Url::clean($company_data['secure_storefront']);
            }
        }
    }
    unset($company_data['company_id']);
    $_data = $company_data;
    if (fn_allowed_for('MULTIVENDOR')) {
        // Check if company with same email already exists
        $is_exist = db_get_field("SELECT email FROM ?:companies WHERE company_id != ?i AND email = ?s", $company_id, $_data['email']);
        if (!empty($is_exist)) {
            $_text = 'error_vendor_exists';
            fn_set_notification('E', __('error'), __($_text));
            return false;
        }
    }
    if (fn_allowed_for('ULTIMATE') && !empty($company_data['storefront'])) {
        // Check if company with the same Storefront URL already exists
        $http_exist = db_get_row('SELECT company_id, storefront FROM ?:companies WHERE storefront = ?s', $company_data['storefront']);
        $https_exist = db_get_row('SELECT company_id, secure_storefront FROM ?:companies WHERE secure_storefront = ?s', $company_data['secure_storefront']);
        if (!empty($http_exist) || !empty($https_exist)) {
            if (empty($company_id)) {
                if (!empty($http_exist)) {
                    fn_set_notification('E', __('error'), __('storefront_url_already_exists'));
                } else {
                    fn_set_notification('E', __('error'), __('secure_storefront_url_already_exists'));
                }
                return false;
            } elseif (!empty($http_exist) && $company_id != $http_exist['company_id'] || !empty($https_exist) && $company_id != $https_exist['company_id']) {
                if (!empty($http_exist) && $company_id != $http_exist['company_id']) {
                    fn_set_notification('E', __('error'), __('storefront_url_already_exists'));
                    unset($_data['storefront']);
                } else {
                    fn_set_notification('E', __('error'), __('secure_storefront_url_already_exists'));
                    unset($_data['secure_storefront']);
                }
                return false;
            }
        }
    }
    if (isset($company_data['shippings'])) {
        $_data['shippings'] = empty($company_data['shippings']) ? '' : fn_create_set($company_data['shippings']);
    }
    if (!empty($_data['countries_list'])) {
        $_data['countries_list'] = implode(',', $_data['countries_list']);
    } else {
        $_data['countries_list'] = '';
    }
    // add new company
    if (empty($company_id)) {
        // company title can't be empty
        if (empty($company_data['company'])) {
            fn_set_notification('E', __('error'), __('error_empty_company_name'));
            return false;
        }
        $_data['timestamp'] = TIME;
        $company_id = db_query("INSERT INTO ?:companies ?e", $_data);
        if (empty($company_id)) {
            return false;
        }
        $_data['company_id'] = $company_id;
        foreach (fn_get_translation_languages() as $_data['lang_code'] => $_v) {
            db_query("INSERT INTO ?:company_descriptions ?e", $_data);
        }
        $action = 'add';
        // update company information
    } else {
        if (isset($company_data['company']) && empty($company_data['company'])) {
            unset($company_data['company']);
        }
        if (!empty($_data['status'])) {
            $status_from = db_get_field("SELECT status FROM ?:companies WHERE company_id = ?i", $company_id);
        }
        db_query("UPDATE ?:companies SET ?u WHERE company_id = ?i", $_data, $company_id);
        if (isset($status_from) && $status_from != $_data['status']) {
            fn_companies_change_status($company_id, $_data['status'], '', $status_from, true);
        }
        // unset data lang code as it determines company main language not description language
        unset($_data['lang_code']);
        db_query("UPDATE ?:company_descriptions SET ?u WHERE company_id = ?i AND lang_code = ?s", $_data, $company_id, $lang_code);
        $action = 'update';
    }
    /**
     * Update company data (running after fn_update_company() function)
     *
     * @param array  $company_data Company data
     * @param int    $company_id   Company integer identifier
     * @param string $lang_code    Two-letter language code (e.g. 'en', 'ru', etc.)
     * @param string $action       Flag determines if company was created (add) or just updated (update).
     */
    fn_set_hook('update_company', $company_data, $company_id, $lang_code, $action);
    $logo_ids = array();
    if ($action == 'add') {
        $theme_name = !empty($company_data['theme_name']) ? $company_data['theme_name'] : Registry::get('config.base_theme');
        if (fn_allowed_for('ULTIMATE')) {
            $clone_from = !empty($company_data['clone_from']) && $company_data['clone_from'] != 'all' ? $company_data['clone_from'] : null;
            if (!is_null($clone_from)) {
                $theme_name = fn_get_theme_path('[theme]', 'C', $clone_from);
            }
        }
        if (fn_allowed_for('ULTIMATE')) {
            $logo_ids = fn_install_theme($theme_name, $company_id, false);
        } else {
            $logo_ids = fn_create_theme_logos_by_layout_id($theme_name, 0, $company_id, true);
        }
    }
    fn_attach_image_pairs('logotypes', 'logos', 0, $lang_code, $logo_ids);
    return $company_id;
}
Esempio n. 5
0
/**
 * @deprecated
 *
 * Cleans storefront URL removing scheme, trailing slash and etc.
 *
 * @param string $url URL for cleaning
 * @return string cleaned URL
 */
function fn_clean_url($url)
{
    return Url::clean($url);
}
Esempio n. 6
0
/**
 * Remove parameter from the URL query part
 *
 * @param string ... query
 * @param string ... parameters to remove
 * @return string modified query
 */
function fn_query_remove()
{
    $args = func_get_args();
    $url = array_shift($args);
    if (!empty($args)) {
        $url_object = new Url($url);
        $url_object->removeParams($args);
        $url = $url_object->build($url_object->getIsEncoded());
    }
    return $url;
}
Esempio n. 7
0
 public function formatEmails($emails)
 {
     $result = array();
     foreach ((array) $emails as $email) {
         $email = str_replace(';', ',', $email);
         $res = explode(',', $email);
         foreach ($res as &$v) {
             $v = trim($v);
         }
         $result = array_merge($result, $res);
     }
     $result = array_unique($result);
     foreach ($result as $k => $email) {
         $result[$k] = Url::normalizeEmail($email);
         if (!$result[$k]) {
             unset($result[$k]);
         }
     }
     return $result;
 }
Esempio n. 8
0
 /**
  * Fixes vars in SERVER superglobal array
  * @param  array $server SERVER array
  * @return array fixed SERVER array
  */
 public static function fixServerVars($server)
 {
     if (!isset($server['HTTP_HOST'])) {
         $server['HTTP_HOST'] = 'localhost';
     }
     if (empty($server['HTTP_USER_AGENT'])) {
         $server['HTTP_USER_AGENT'] = '';
     }
     if (isset($server['HTTP_X_REWRITE_URL'])) {
         // for isapi_rewrite
         $server['REQUEST_URI'] = $server['HTTP_X_REWRITE_URL'];
     }
     if (!empty($server['QUERY_STRING'])) {
         $server['QUERY_STRING'] = defined('QUOTES_ENABLED') ? stripslashes($server['QUERY_STRING']) : $server['QUERY_STRING'];
         $server['QUERY_STRING'] = str_replace(array('"', "'"), array('', ''), $server['QUERY_STRING']);
     }
     // resolve symbolic links
     if (!empty($server['SCRIPT_FILENAME'])) {
         $server['SCRIPT_FILENAME'] = realpath($server['SCRIPT_FILENAME']);
     } else {
         $debug_backtrace = debug_backtrace();
         $debug_backtrace = end($debug_backtrace);
         if (isset($debug_backtrace['file'])) {
             $server['SCRIPT_FILENAME'] = realpath($debug_backtrace['file']);
         }
     }
     if (!isset($server['SCRIPT_NAME']) && isset($server['SCRIPT_FILENAME'])) {
         $server['SCRIPT_NAME'] = $server['SCRIPT_FILENAME'];
     }
     if (!empty($server['HTTP_ORIGIN'])) {
         $url = new Url($server['HTTP_ORIGIN']);
         $server['HTTP_ORIGIN'] = $url->build(false, true);
     }
     if (!empty($server['HTTP_REFERER'])) {
         $url = new Url($server['HTTP_REFERER']);
         $server['HTTP_REFERER'] = $url->build(false, true);
     }
     // PHP_AUTH_USER and PHP_AUTH_PW not available when using FastCGI (https://bugs.php.net/bug.php?id=35752)
     $http_auth = '';
     if (!empty($server['REDIRECT_HTTP_AUTHORIZATION'])) {
         $http_auth = base64_decode(substr($server['REDIRECT_HTTP_AUTHORIZATION'], 6));
     } elseif (!empty($server['HTTP_AUTHORIZATION'])) {
         $http_auth = base64_decode(substr($server['HTTP_AUTHORIZATION'], 6));
     }
     if (!empty($http_auth) && (empty($server['PHP_AUTH_USER']) || empty($server['PHP_AUTH_PW']))) {
         list($server['PHP_AUTH_USER'], $server['PHP_AUTH_PW']) = explode(':', $http_auth);
     }
     if (self::isWindows()) {
         foreach (array('PHP_SELF', 'SCRIPT_FILENAME', 'SCRIPT_NAME') as $var) {
             if (isset($server[$var])) {
                 $server[$var] = str_replace('\\', '/', $server[$var]);
             }
         }
     }
     return $server;
 }
Esempio n. 9
0
 /**
  * Return addon supplier link
  * @return null|string http://example.com
  */
 public function getSupplierLink()
 {
     $url = isset($this->_xml->supplier_link) ? (string) $this->_xml->supplier_link : '';
     if (!empty($url) && Url::isValid($url)) {
         return $url;
     }
     return null;
 }
Esempio n. 10
0
 /**
  * Checks whether given URL is a subpart of the current URL by matching their paths.
  *
  * @param \Tygh\Tools\Url $url URL to check against
  *
  * @TODO: Write unit-tests
  *
  * @return bool Whether current URL path contains given URL path along with their hostnames do match.
  */
 public function containsAsSubpath(self $url)
 {
     return $this->getHost() == $url->getHost() && (trim($this->getPath(), '/') === trim($url->getPath(), '/') || strpos($this->getPath(), rtrim($url->getPath(), '/') . '/') === 0);
 }
Esempio n. 11
0
 /**
  * Updates company urls
  *
  * @param  string $url        store url
  * @param  string $secure_url secure store url
  * @param  int    $company_id company identifier
  * @return bool   Always true
  */
 private function _updateCompanyURL($url, $secure_url, $company_id)
 {
     $company_data = array('storefront' => Url::clean($url), 'secure_storefront' => Url::clean($secure_url));
     db_query('UPDATE ?:companies SET ?u WHERE company_id = ?i', $company_data, $company_id);
     return true;
 }