Esempio n. 1
0
/**
 * Gets mobile product url
 *
 * @param $product_id
 * @param string $lang_code
 * @return bool
 */
function fn_twg_exim_get_product_mobile_url($product_id, $lang_code = '')
{
    $company_id = 0;
    $company_url = '';
    if (fn_allowed_for('ULTIMATE')) {
        if (Registry::get('runtime.company_id')) {
            $company_id = Registry::get('runtime.company_id');
        } else {
            $company_id = db_get_field('SELECT company_id FROM ?:products WHERE product_id = ?i', $product_id);
        }
        $company_url = '&company_id=' . $company_id;
    } else {
        $company_url = '';
    }
    $settings = TwigmoSettings::get('customer_connections.' . $company_id);
    $use_twg = !empty($settings['access_id']) && ($settings['use_for_phones'] == 'Y' || $settings['use_for_tablets'] == 'Y');
    if ($use_twg && fn_twg_use_https_for_customer($company_id)) {
        $protocol = 'https';
    } else {
        $protocol = 'http';
    }
    $url = fn_url('products.view?product_id=' . $product_id . $company_url, 'C', $protocol, $lang_code);
    fn_set_hook('exim_get_product_url', $url, $product_id, $options, $lang_code);
    return $url;
}
Esempio n. 2
0
function fn_twg_is_updated()
{
    $saved_version = TwigmoSettings::get('version');
    return empty($saved_version) || $saved_version == TWIGMO_VERSION;
}
 private function _setConnectTTL()
 {
     TwigmoSettings::set(array('connect_till' => TIME + self::CONNECT_REQUEST_TTL));
 }
Esempio n. 4
0
 public static function restoreSettingsAndCSS($upgrade_dirs)
 {
     // Restore langvars - for all languages except EN and RU
     $languages = Lang::getLanguages();
     $except_langs = array('en', 'ru');
     foreach ($languages as $language) {
         $backup_file = $upgrade_dirs['backup_settings'] . 'lang_' . $language['lang_code'] . '.bak';
         if (!in_array($language['lang_code'], $except_langs) and file_exists($backup_file)) {
             LanguageValues::updateLangVar(unserialize(fn_get_contents($backup_file)), $language['lang_code']);
         }
     }
     // Restore blocks
     $old_company_id = Registry::get('runtime.company_id');
     foreach ($upgrade_dirs['backup_company_settings'] as $company_id => $dir) {
         Registry::set('runtime.company_id', $company_id);
         $backup_file = $dir . 'blocks.xml';
         if (file_exists($backup_file)) {
             if (version_compare(PRODUCT_VERSION, '4.1.1', '>=')) {
                 Registry::set('runtime.layout', Layout::instance()->getDefault());
             }
             Exim::instance($company_id, fn_twg_get_default_layout_id())->importFromFile($backup_file);
         }
     }
     Registry::set('runtime.company_id', $old_company_id);
     // Restore settings if addon was connected
     $restored_settings = array('my_private_key', 'my_public_key', 'his_public_key', 'email', 'customer_connections', 'admin_connection');
     $settings = array();
     foreach ($_SESSION['twigmo_backup_settings'] as $setting => $value) {
         if (in_array($setting, $restored_settings)) {
             $settings[$setting] = $value;
         }
     }
     $settings['version'] = TWIGMO_VERSION;
     unset($_SESSION['twigmo_backup_settings']);
     TwigmoSettings::set($settings);
     $connector = new TwigmoConnector();
     if (!$connector->updateConnections(true)) {
         $connector->disconnect(array(), true);
     }
     // Restore images
     self::copyFiles($upgrade_dirs['backup_files']['media_frontend'], $upgrade_dirs['installed']['media_frontend']);
     return true;
 }
Esempio n. 5
0
 /**
  * Get blocks for the twigmo homepage
  * @param  string $dispatch        Dispatch of needed location
  * @param  array  $allowed_objects - array of blocks types
  * @return array  blocks
  */
 public static final function getBlocksForLocation($dispatch, $allowed_objects)
 {
     $allowed_page_types = array('T', 'L', 'F');
     $blocks = array();
     $location = Location::instance(fn_twg_get_default_layout_id())->get($dispatch);
     if (!$location) {
         return $blocks;
     }
     $get_cont_params = array('location_id' => $location['location_id']);
     $container = Container::getList($get_cont_params);
     if (!$container or !$container['CONTENT']) {
         return $blocks;
     }
     $grids_params = array('container_ids' => $container['CONTENT']['container_id']);
     $grids = Grid::getList($grids_params);
     if (!$grids) {
         return $blocks;
     }
     $block_grids = Block::instance()->getList(array('?:bm_snapping.*', '?:bm_blocks.*', '?:bm_blocks_descriptions.*'), Grid::getIds($grids));
     $image_params = TwigmoSettings::get('images.catalog');
     foreach ($block_grids as $block_grid) {
         foreach ($block_grid as $block) {
             if ($block['status'] != 'A' or !in_array($block['type'], $allowed_objects)) {
                 continue;
             }
             $block_data = array('block_id' => $block['block_id'], 'title' => $block['name'], 'hide_header' => isset($block['properties']['hide_header']) ? $block['properties']['hide_header'] : 'N', 'user_class' => $block['user_class']);
             $block_scheme = SchemesManager::getBlockScheme($block['type'], array());
             if ($block['type'] == 'html_block') {
                 // Html block
                 if (isset($block['content']['content']) and fn_string_not_empty($block['content']['content'])) {
                     $block_data['html'] = $block['content']['content'];
                 }
             } elseif (!empty($block_scheme['content']) and !empty($block_scheme['content']['items'])) {
                 // Products and categories: get items
                 $template_variable = 'items';
                 $field = $block_scheme['content']['items'];
                 fn_set_hook('render_block_content_pre', $template_variable, $field, $block_scheme, $block);
                 $items = RenderManager::getValue($template_variable, $field, $block_scheme, $block);
                 // Filter pages - only texts, links and forms posible
                 if ($block['type'] == 'pages') {
                     foreach ($items as $item_id => $item) {
                         if (!in_array($item['page_type'], $allowed_page_types)) {
                             unset($items[$item_id]);
                         }
                     }
                 }
                 if (empty($items)) {
                     continue;
                 }
                 $block_data['total_items'] = count($items);
                 // Images
                 if ($block['type'] == 'products' or $block['type'] == 'categories') {
                     $object_type = $block['type'] == 'products' ? 'product' : 'category';
                     foreach ($items as $items_id => $item) {
                         if (!empty($item['main_pair'])) {
                             $main_pair = $item['main_pair'];
                         } else {
                             $main_pair = fn_get_image_pairs($item[$object_type . '_id'], $object_type, 'M', true, true);
                         }
                         if (!empty($main_pair)) {
                             $items[$items_id]['icon'] = TwigmoImage::getApiImageData($main_pair, $object_type, 'icon', $image_params);
                         }
                     }
                 }
                 // Banners properties
                 if ($block['type'] == 'banners') {
                     $rotation = $block['properties']['template'] == 'addons/banners/blocks/carousel.tpl' ? 'Y' : 'N';
                     $block_data['delay'] = $rotation == 'Y' ? $block['properties']['delay'] : 0;
                     $block_data['hide_navigation'] = isset($block['properties']['navigation']) && $block['properties']['navigation'] == 'N' ? 'Y' : 'N';
                 }
                 $block_data[$block['type']] = Api::getAsList($block['type'], $items);
             }
             $blocks[$block['block_id']] = $block_data;
         }
     }
     return $blocks;
 }
Esempio n. 6
0
*                                                                          *
*   (c) 2004 Vladimir V. Kalynyak, Alexey V. Vinokurov, Ilya M. Shalnev    *
*                                                                          *
* This  is  commercial  software,  only  users  who have purchased a valid *
* license  and  accept  to the terms of the  License Agreement can install *
* and use this program.                                                    *
*                                                                          *
****************************************************************************
* PLEASE READ THE FULL TEXT  OF THE SOFTWARE  LICENSE   AGREEMENT  IN  THE *
* "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE.            *
****************************************************************************/
if (!defined('BOOTSTRAP')) {
    die('Access denied');
}
use Tygh\Registry;
use Twigmo\Core\TwigmoSettings;
if ($mode == 'block_selection' and !empty($_REQUEST['grid_id'])) {
    // Disable some block types for twigmo location
    if (!fn_twg_is_twigmo_grid($_REQUEST['grid_id'])) {
        return;
    }
    // Disable some types
    $block_types = Registry::get('view')->getTemplateVars('block_types');
    $allowed_types = TwigmoSettings::get('block_types');
    foreach ($block_types as $key => $block_type) {
        if (!in_array($key, $allowed_types)) {
            unset($block_types[$key]);
        }
    }
    Registry::get('view')->assign('block_types', $block_types);
}
Esempio n. 7
0
    die('Access denied');
}
use Tygh\Registry;
use Twigmo\Core\TwigmoSettings;
use Twigmo\Core\TwigmoConnector;
// addon version
fn_define('TWIGMO_VERSION', '3.8');
fn_define('TWIGMO_UPGRADE_DIR', Registry::get('config.dir.var') . 'twigmo/');
fn_define('TWIGMO_UA_RULES_FILE', TWIGMO_UPGRADE_DIR . 'ua_rules.txt');
fn_define('TWIGMO_UPGRADE_VERSION_FILE', 'version_info.txt');
fn_define('TWG_UA_RULES_STAT', 'http://twigmo.com/svc2/ua_meta/stat.php');
fn_define('TWG_DEFAULT_DATA_FORMAT', 'json');
fn_define('TWG_DEFAULT_API_VERSION', '2.0');
fn_define('TWG_RESPONSE_ITEMS_LIMIT', 10);
fn_define('TWG_MAX_DESCRIPTION_LEN', 200);
if (Registry::get('addons.twigmo.status') == 'A' && TwigmoSettings::dbIsInited()) {
    $settings = array();
    $settings['unsupported_payment_methods'] = array('FRIbetaling', 'PayPal Advanced', 'FuturePay');
    $settings['unsupported_shipping_methods'] = array();
    $settings['block_types'] = array('products', 'categories', 'pages', 'html_block');
    if (Registry::get('addons.banners.status') == 'A') {
        $settings['block_types'][] = 'banners';
    }
    $settings['images'] = array('cart' => array('width' => 96, 'height' => 96), 'catalog' => array('width' => 200, 'height' => 200), 'prewiew' => array('width' => 130, 'height' => 120), 'big' => array('width' => 800, 'height' => 800, 'keep_proportions' => true));
    fn_set_hook('twg_config', $settings);
    // Init twigmo settings
    TwigmoSettings::moveToRuntime($settings);
}
if (file_exists(Registry::get('config.dir.addons') . 'twigmo/local_conf.php')) {
    include Registry::get('config.dir.addons') . 'twigmo/local_conf.php';
}
Esempio n. 8
0
            fn_delete_notification('twigmo_upgrade');
        }
        if (!fn_twg_is_updated()) {
            fn_set_notification('W', __('notice'), __('twgadmin_reinstall'));
        }
        $company_id = fn_twg_get_current_company_id();
        $view = Registry::get('view');
        $view->assign('default_logo', TwigmoImage::getDefaultLogoUrl($company_id));
        $urls = TwigmoConnector::getMobileScriptsUrls();
        $view->assign('favicon', $urls['favicon']);
        $view->assign('logo_object_id', $company_id * 10 + 1);
        $view->assign('favicon_object_id', $company_id * 10 + 2);
        $tw_register['version'] = TWIGMO_VERSION;
        $view->assign('tw_register', $tw_register);
        $view->assign('next_version_info', TwigmoUpgrade::getNextVersionInfo());
        $view->assign('twg_is_connected', TwigmoConnector::anyFrontendIsConnected());
        $stores = fn_twg_get_stores();
        $platinum_stores = fn_twg_init_push_comment(fn_twg_filter_connected_platinum_stores($stores));
        $view->assign('stores', $stores);
        $view->assign('platinum_stores', $platinum_stores);
        $view->assign('max_push_length', TwigmoConnector::MAX_PUSH_LENGTH);
        $view->assign('twg_all_stores_connected', TwigmoConnector::allStoresAreConnected($stores));
        $view->assign('reset_pass_link', TwigmoConnector::getResetPassLink());
        $admin_access_id = TwigmoConnector::getAccessID('A');
        $view->assign('admin_access_id', $admin_access_id);
        $view->assign('is_disconnect_mode', isset($_REQUEST['disconnect']) && $admin_access_id);
        $view->assign('tw_settings', TwigmoSettings::get());
        $view->assign('is_on_saas', fn_twg_is_on_saas());
        $view->assign('connected_access_id', fn_twg_get_connected_access_id());
    }
}
Esempio n. 9
0
     $connector->respond($response_data);
 } elseif ($action == 'auth.app') {
     $_POST['password'] = $_REQUEST['password'];
     list($status, $user_data, $user_login, $password, $salt) = fn_auth_routines($_REQUEST, $auth);
     $redirect_to_mv_url = fn_twg_check_for_vendor_url($status, $user_data);
     if ($redirect_to_mv_url) {
         $response->setData(array('status' => 'ok'));
         $response->setData(array('redirect_to_mv_url' => $redirect_to_mv_url));
         $response->returnResponse();
     }
     $is_ok = !empty($user_data) && !empty($password) && fn_generate_salted_password($password, $salt) == $user_data['password'];
     if ($status === false || !$is_ok) {
         fn_twg_throw_error_denied($response, 'error_incorrect_login');
     }
     if ($user_data['user_type'] == 'A' && $user_data['company_id']) {
         $store_access_id = TwigmoSettings::get('customer_connections.' . $user_data['company_id'] . '.access_id');
         if (!$store_access_id || $store_access_id != $_REQUEST['access_id']) {
             fn_twg_throw_error_denied($response, 'twgadmin_auth_fail_access_id');
         }
     }
     // Regenerate session_id for security reasons
     Session::regenerateId();
     fn_login_user($user_data['user_id']);
     fn_set_session_data(AREA . '_user_id', $user_data['user_id'], COOKIE_ALIVE_TIME);
     fn_set_session_data(AREA . '_password', $user_data['password'], COOKIE_ALIVE_TIME);
     // Set last login time
     db_query("UPDATE ?:users SET ?u WHERE user_id = ?i", array('last_login' => TIME), $user_data['user_id']);
     $_SESSION['auth']['this_login'] = TIME;
     $_SESSION['auth']['ip'] = $_SERVER['REMOTE_ADDR'];
     $auth = $_SESSION['auth'];
     // Log user successful login
Esempio n. 10
0
    }
    $request = $connector->parseResponse($_REQUEST['data']);
    if (empty($request['data']) or empty($request['data']['url'])) {
        $connector->onError();
    }
    // Request is ok - check url
    if ($action == 'check.admin') {
        if ($request['data']['url'] != $connector->getAdminUrl()) {
            $connector->onError('Wrong admin url');
        }
    } else {
        $stores = fn_twg_get_stores();
        $store = reset($stores);
        $my_url = $connector->getCustomerUrl($store);
        if ($request['data']['url'] != $my_url) {
            $connector->onError('Wrong customer url');
        }
    }
    $connector->respond(array('result' => 'ok'));
} elseif ($action == 'repo.updated') {
    $connector = new TwigmoConnector();
    $stores = fn_twg_get_stores();
    $store = reset($stores);
    $all_stores = TwigmoSettings::get('customer_connections');
    if (empty($store) || empty($all_stores) || !isset($all_stores[$store['company_id']])) {
        $connector->onError('store_not_found');
    }
    $all_stores[$store['company_id']]['repo_revision'] = TIME;
    TwigmoSettings::set(array('customer_connections' => $all_stores));
    $connector->respond(array('result' => 'ok'));
}