Exemplo n.º 1
0
 /**
  * Change style id for specified layout
  *
  * @param  int    $layout_id Layout ID
  * @param  string $style_id  Style name (Like: "satori", "ocean", etc)
  * @return true   if updated
  */
 public function setStyle($layout_id, $style_id)
 {
     $result = db_query('UPDATE ?:bm_layouts SET style_id = ?s WHERE layout_id = ?i AND theme_name = ?s', $style_id, $layout_id, $this->theme_name);
     if ((fn_allowed_for('ULTIMATE') && !empty($this->company_id) || fn_allowed_for('MULTIVENDOR')) && !empty($layout_id) && !empty($style_id) && !empty($this->theme_name)) {
         $logos = fn_get_logos($this->company_id, $layout_id, $style_id);
         $logo_types = fn_get_logo_types(false);
         $have_missed = array_diff_key($logo_types, $logos);
         if (!empty($have_missed)) {
             fn_create_theme_logos_by_layout_id($this->theme_name, $layout_id, $this->company_id, false, $style_id);
         }
     }
     return $result;
 }
Exemplo n.º 2
0
     if (!empty($from_default_layout) && !empty($layout_id)) {
         $repo_dest = fn_get_theme_path('[themes]/' . $from_default_layout['theme_name'], 'C');
         $layout_path = fn_normalize_path($repo_dest . '/layouts/' . $from_default_layout['filename']);
         $exim = Exim::instance(Registry::get('runtime.company_id'), $layout_id, fn_get_theme_path('[theme]', 'C'));
         $structure = $exim->getStructure($layout_path);
         if (!empty($structure)) {
             foreach ($layout_data as $key => $val) {
                 if (!empty($structure->layout->{$key})) {
                     $structure->layout->{$key} = $val;
                 }
             }
             if (!isset($layout_data['is_default'])) {
                 $structure->layout->is_default = 0;
             }
             $exim->import($structure, array('import_style' => 'update'));
             fn_create_theme_logos_by_layout_id($layout_data['theme_name'], $layout_id, Registry::get('runtime.company_id'), false, Styles::factory($layout_data['theme_name'])->getDefault());
         }
     }
     fn_clear_cache('assets', 'design/');
     return array(CONTROLLER_STATUS_OK, fn_url('block_manager.manage?s_layout=' . $layout_id));
 }
 if ($mode == 'update_block') {
     $description = array();
     if (!empty($_REQUEST['block_data']['description'])) {
         $_REQUEST['block_data']['description']['lang_code'] = DESCR_SL;
         $description = $_REQUEST['block_data']['description'];
     }
     if (!empty($_REQUEST['block_data']['content_data'])) {
         $_REQUEST['block_data']['content_data']['lang_code'] = DESCR_SL;
         if (isset($_REQUEST['block_data']['content'])) {
             $_REQUEST['block_data']['content_data']['content'] = $_REQUEST['block_data']['content'];
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
/**
 * Installs theme
 *
 * @param int $layout_id layout ID to create logo for
 * @param string $theme_name theme name
 * @param int $company_id company ID
 * @return boolean always true
 */
function fn_install_theme($theme_name, $company_id = null, $install_layouts = true)
{
    // Copy files
    fn_install_theme_files($theme_name, $theme_name, true);
    Settings::instance()->updateValue('theme_name', $theme_name, '', true, $company_id);
    $repo_dest = fn_get_theme_path('[themes]/' . $theme_name, 'C', $company_id, false);
    $logo_ids = array();
    // Import theme layout
    $layouts = fn_get_dir_contents($repo_dest . '/layouts/', false, true, '.xml');
    // FIXME: Backward compability for layouts
    if (empty($layouts) && file_exists($repo_dest . '/layouts.xml')) {
        $layouts = array('../layouts.xml');
    }
    if (!empty($layouts) && $install_layouts) {
        foreach ($layouts as $layout_name) {
            $layout_path = fn_normalize_path($repo_dest . '/layouts/' . $layout_name);
            if (file_exists($layout_path)) {
                $layout_id = Exim::instance($company_id, 0, $theme_name)->importFromFile($layout_path, array('override_by_dispatch' => true, 'clean_up' => true, 'import_style' => 'create'));
                if (empty($layout_id)) {
                    continue;
                }
                $layout_data = Layout::instance()->get($layout_id);
                $_o_ids = fn_create_theme_logos_by_layout_id($theme_name, $layout_id, $company_id, false, $layout_data['style_id']);
                $logo_ids = array_merge($logo_ids, $_o_ids);
            }
        }
    } else {
        $params = array('theme_name' => $theme_name);
        $exists = Layout::instance($company_id)->getList($params);
        if (empty($exists)) {
            $layout_id = Layout::instance($company_id)->update(array('name' => __('main'), 'theme_name' => $theme_name, 'is_default' => 1));
            $layout_data = Layout::instance()->get($layout_id);
            $logo_ids = fn_create_theme_logos_by_layout_id($theme_name, $layout_id, $company_id, false, $layout_data['style_id']);
        }
    }
    return $logo_ids;
}
Exemplo n.º 5
0
 /**
  * Creates logos of missing logo types for given layout and style.
  *
  * @param int    $layout_id Layout ID
  * @param string $style_id  Style ID
  */
 public function createMissedLogoTypesForLayout($layout_id, $style_id)
 {
     if ((fn_allowed_for('ULTIMATE') && !empty($this->company_id) || fn_allowed_for('MULTIVENDOR')) && !empty($layout_id) && !empty($style_id) && !empty($this->theme_name)) {
         $logos = fn_get_logos($this->company_id, $layout_id, $style_id);
         $logo_types = fn_get_logo_types(false);
         $missed_logo_types = array_diff_key($logo_types, $logos);
         if (!empty($missed_logo_types)) {
             fn_create_theme_logos_by_layout_id($this->theme_name, $layout_id, $this->company_id, false, $style_id, array_keys($missed_logo_types));
         }
     }
 }
Exemplo n.º 6
0
     fn_put_contents(Registry::get('config.dir.layouts') . $filename, $content);
     fn_set_notification('N', __('notice'), __('text_exim_data_exported'));
     // Direct download
     if ($_REQUEST['output'] == 'D') {
         return array(CONTROLLER_STATUS_REDIRECT, 'block_manager.manage?meta_redirect_url=block_manager.get_file%26filename=' . $_REQUEST['filename']);
         // Output to screen
     } elseif ($_REQUEST['output'] == 'C') {
         return array(CONTROLLER_STATUS_REDIRECT, 'block_manager.get_file?to_screen=Y&filename=' . $_REQUEST['filename']);
     }
 }
 if ($mode == 'import_layout') {
     $data = fn_filter_uploaded_data('filename');
     if (!empty($data[0]['path'])) {
         $result = Exim::instance()->importFromFile($data[0]['path'], $_REQUEST);
         $layout_data = Layout::instance()->get($result);
         fn_create_theme_logos_by_layout_id($layout_data['theme_name'], $result, isset($layout_data['company_id']) ? $layout_data['company_id'] : 0, false, $layout_data['style_id']);
         if ($result) {
             fn_set_notification('N', __('notice'), __('text_exim_data_imported_clear'));
         }
     }
 }
 if ($mode == 'update_status') {
     $type = empty($_REQUEST['type']) ? 'block' : $_REQUEST['type'];
     if ($type == 'block') {
         Block::instance()->updateStatus($_REQUEST);
     } elseif ($type == 'grid') {
         Grid::update($_REQUEST);
     } elseif ($type == 'container') {
         Container::update($_REQUEST);
     }
     fn_set_notification('N', __('notice'), __('text_changes_saved'));