Exemplo n.º 1
0
     Tygh::$app['view']->assign('locations', $locations);
     // Set tabs content
     if (!empty($locations)) {
         foreach ($locations as $location => $_location) {
             Registry::set("navigation.tabs.location_" . $_location['location_id'], array('title' => $_location['name'], 'href' => "block_manager.manage?selected_location=" . $_location['location_id']));
         }
     }
 }
 Tygh::$app['view']->assign('location', $selected_location);
 if (!empty($_REQUEST['dynamic_object'])) {
     Tygh::$app['view']->assign('dynamic_object', $_REQUEST['dynamic_object']);
 }
 if (!empty($selected_location['dispatch'])) {
     Tygh::$app['view']->assign('dynamic_object_scheme', SchemesManager::getDynamicObject($selected_location['dispatch'], 'C'));
 }
 $theme = Themes::factory(fn_get_theme_path('[theme]', 'C'));
 Tygh::$app['view']->assign('theme_manifest', $theme->getManifest());
 $params = array('theme_name' => $theme->getThemeName());
 Tygh::$app['view']->assign('layouts', Layout::instance()->getList($params));
 Tygh::$app['view']->assign('all_layouts', Layout::instance()->getList());
 Tygh::$app['view']->assign('default_layouts_sources', fn_get_default_layouts_sources('responsive'));
 Tygh::$app['view']->assign('themes', fn_get_available_themes($theme->getThemeName()));
 $http_url = fn_get_storefront_url('http');
 $https_url = fn_get_storefront_url('https');
 Tygh::$app['view']->assign('widget_http_url', urlencode($http_url));
 Tygh::$app['view']->assign('widget_https_url', urlencode($https_url));
 if ($mode == 'manage') {
     Tygh::$app['view']->assign('layout_data', Layout::instance()->get(Registry::get('runtime.layout.layout_id')));
 } else {
     Tygh::$app['view']->display('views/block_manager/manage_in_tab.tpl');
     exit;
Exemplo n.º 2
0
/**
 * Updates addon status
 * @param string $addon Addon to update status for
 * @param string $status Status to change to
 * @param bool $show_notification Display notification if set to true
 * @param bool $on_install If status was changed on after ionstall process
 * @return bool|string True on success, old status ID if status was not changed
 */
function fn_update_addon_status($addon, $status, $show_notification = true, $on_install = false)
{
    $old_status = db_get_field("SELECT status FROM ?:addons WHERE addon = ?s", $addon);
    $new_status = $status;
    $scheme = SchemesManager::getScheme($addon);
    // Unmanaged addons can be enabled/disabled via console only
    if ($scheme->getUnmanaged() && !defined('CONSOLE')) {
        return false;
    }
    if ($old_status != $new_status) {
        // Check if addon can be enabled
        $conflicts = db_get_fields("SELECT addon FROM ?:addons WHERE status = 'A' AND FIND_IN_SET(?s, conflicts)", $addon);
        if ($new_status == 'A' && !empty($conflicts)) {
            $scheme = SchemesManager::getScheme($addon);
            fn_set_notification('W', __('warning'), __('text_addon_cannot_enable', array('[addons]' => implode(', ', SchemesManager::getNames($conflicts)), '[addon_name]' => $scheme->getName())));
            return $old_status;
        }
        fn_get_schema('settings', 'actions.functions', 'php', true);
        $func = 'fn_settings_actions_addons_' . $addon;
        if (function_exists($func)) {
            $func($new_status, $old_status, $on_install);
        }
        // If status change is allowed, update it
        if ($old_status != $new_status) {
            if ($new_status != 'D') {
                // Check that addon have conflicts
                $scheme = SchemesManager::getScheme($addon);
                $conflicts = db_get_field("SELECT conflicts FROM ?:addons WHERE addon = ?s", $addon);
                if (!empty($conflicts)) {
                    $conflicts = explode(',', $conflicts);
                    $lang_var = 'text_addon_confclicts_on_install';
                    if (!$on_install) {
                        foreach ($conflicts as $conflict) {
                            fn_disable_addon($conflict, $scheme->getName(), $show_notification);
                        }
                        $lang_var = 'text_addon_confclicts';
                    }
                    fn_set_notification('W', __('warning'), __($lang_var, array('[addons]' => implode(', ', SchemesManager::getNames($conflicts)), '[addon_name]' => $scheme->getName())));
                    // On install we cannot enable addon with conflicts automaticly
                    if ($on_install) {
                        return $old_status;
                    }
                }
            }
            db_query("UPDATE ?:addons SET status = ?s WHERE addon = ?s", $status, $addon);
            $func = 'fn_settings_actions_addons_post_' . $addon;
            if (function_exists($func)) {
                $func($status);
            }
            if ($show_notification == true) {
                fn_set_notification('N', __('notice'), __('status_changed'));
            }
            // Enable/disable tabs for addon
            ProductTabs::instance()->updateAddonTabStatus($addon, $new_status);
            Registry::set('addons.' . $addon . '.status', $status);
        } else {
            return $old_status;
        }
    }
    // Clean cache
    fn_clear_cache();
    if ($status == 'A') {
        foreach (fn_get_installed_themes() as $theme_name) {
            $theme = Themes::factory($theme_name);
            $theme_manifest = $theme->getManifest();
            // Precompile addon LESS files if the theme has been converted to CSS
            if (!empty($theme_manifest['converted_to_css']) && !$theme->convertAddonToCss($addon)) {
                fn_update_addon_status($addon, 'D', $show_notification, $on_install);
                return $old_status;
            }
        }
    }
    return true;
}
Exemplo n.º 3
0
function fn_theme_editor($params, $lang_code = CART_LANGUAGE)
{
    $view = Tygh::$app['view'];
    $theme_name = Registry::get('runtime.layout.theme_name');
    $layout_id = Registry::get('runtime.layout.layout_id');
    if (!Registry::get('runtime.layout.style_id')) {
        $default_style_id = Styles::factory($theme_name)->getDefault();
        db_query('UPDATE ?:bm_layouts SET style_id = ?s WHERE layout_id = ?i', $default_style_id, $layout_id);
        Registry::set('runtime.layout.style_id', $default_style_id);
    }
    $style_id = Registry::get('runtime.layout.style_id');
    // Backward presets compatibility
    Registry::set('runtime.layout.preset_id', $style_id);
    // get current style
    $current_style = Styles::factory($theme_name)->get($style_id, array('parse' => true));
    // get all styles
    $styles_list = Styles::factory($theme_name)->getList();
    $schema = Styles::factory($theme_name)->getSchema();
    $sections = array('te_general' => 'theme_editor.general', 'te_logos' => 'theme_editor.logos', 'te_colors' => 'theme_editor.colors', 'te_fonts' => 'theme_editor.fonts', 'te_backgrounds' => 'theme_editor.backgrounds', 'te_css' => 'theme_editor.css');
    foreach ($sections as $section_id => $section) {
        if ($section_id == 'te_logos') {
            // Logos is hardcoded section, no need to define it in schema
            continue;
        }
        $section_id = str_replace('te_', '', $section_id);
        if (!isset($schema[$section_id])) {
            unset($sections['te_' . $section_id]);
        }
    }
    if (empty($params['selected_section']) || !isset($sections[$params['selected_section']])) {
        reset($sections);
        $params['selected_section'] = key($sections);
    }
    $theme = Themes::factory($theme_name);
    $theme_manifest = $theme->getManifest();
    if (!empty($theme_manifest['converted_to_css'])) {
        if (empty($params['selected_css_file'])) {
            $params['selected_css_file'] = Themes::$compiled_less_filename;
        }
        $view->assign('selected_css_file', $params['selected_css_file']);
        $view->assign('css_files_list', $theme->getCssFilesList());
        $view->assign('css_content', $theme->getCssContents($params['selected_css_file']));
    }
    $view->assign('cse_logo_types', fn_get_logo_types());
    $view->assign('cse_logos', fn_get_logos(Registry::get('runtime.company_id')));
    $view->assign('selected_section', $params['selected_section']);
    $view->assign('te_sections', $sections);
    $view->assign('current_style', $current_style);
    $view->assign('props_schema', $schema);
    $view->assign('theme_patterns', Patterns::instance()->get($style_id));
    $view->assign('styles_list', $styles_list);
    // FIXME: Backward compatibility
    $view->assign('presets_list', $styles_list);
    $view->assign('current_preset', $current_style);
    $view->assign('manifest', Styles::factory($theme_name)->getManifest());
    $view->assign('theme_manifest', $theme_manifest);
    $view->assign('layouts', Layout::instance()->getList(array('theme_name' => $theme_name)));
    $view->assign('layout_data', Layout::instance()->get($layout_id));
    $view->assign('theme_url', fn_url(empty($params['theme_url']) ? '' : $params['theme_url']));
}
Exemplo n.º 4
0
 /**
  * Validate specified data by schema
  *
  * @param  array $schema  Incoming validator schema
  * @param  array $request Request data
  *
  * @return array Validation result and Data to be displayed
  */
 public function check($schema, $request)
 {
     $data = array();
     $show_notifications = !empty($request['change_ftp_settings']);
     if (!empty($schema['files'])) {
         $repo_files = array();
         $repo_path = str_replace($this->config['dir']['root'] . '/', '', $this->config['dir']['themes_repository']);
         // Process themes_repository
         foreach ($schema['files'] as $file_path => $file_data) {
             if (strpos($file_path, $repo_path) !== false) {
                 $path = str_replace($repo_path, '', $file_path);
                 $path = explode('/', $path);
                 $theme_name = array_shift($path);
                 $repo_files[$theme_name][implode('/', $path)] = $file_data;
             }
         }
         $themes = fn_get_dir_contents($this->config['dir']['root'] . '/design/themes/');
         foreach ($themes as $theme_name) {
             $manifest = Themes::factory($theme_name)->getManifest();
             $parent_theme = empty($manifest['parent_theme']) ? 'basic' : $manifest['parent_theme'];
             if (!empty($repo_files[$parent_theme])) {
                 foreach ($repo_files[$parent_theme] as $file_path => $file_data) {
                     $schema['files']['design/themes/' . $theme_name . '/' . $file_path] = $file_data;
                 }
             }
         }
         foreach ($schema['files'] as $file_path => $file_data) {
             $result = true;
             $original_path = $this->config['dir']['root'] . '/' . $file_path;
             switch ($file_data['status']) {
                 case 'changed':
                     if (file_exists($original_path)) {
                         if (!$this->isWritable($original_path)) {
                             $result = $this->correctPermissions($original_path, $show_notifications);
                         }
                     } else {
                         $file_path = $this->getParentDir($file_path);
                         if (!$this->isWritable($this->config['dir']['root'] . '/' . $file_path)) {
                             $result = $this->correctPermissions($original_path, $show_notifications);
                         }
                     }
                     break;
                 case 'deleted':
                     if (file_exists($original_path)) {
                         if (!$this->isWritable($original_path)) {
                             $result = $this->correctPermissions($original_path, $show_notifications);
                         }
                     }
                     if ($result) {
                         $file_path = $this->getParentDir($file_path);
                         if (!$this->isWritable($this->config['dir']['root'] . '/' . $file_path)) {
                             $result = $this->correctPermissions($this->config['dir']['root'] . '/' . $file_path, $show_notifications);
                         }
                     }
                     break;
                 case 'new':
                     if (file_exists($original_path) && !$this->isWritable($original_path)) {
                         $result = $this->correctPermissions($original_path, $show_notifications);
                         $file_path = dirname($file_path);
                     } else {
                         $file_path = $this->getParentDir($file_path);
                         if (!$this->isWritable($this->config['dir']['root'] . '/' . $file_path)) {
                             $result = $this->correctPermissions($this->config['dir']['root'] . '/' . $file_path, $show_notifications);
                         }
                     }
                     break;
             }
             if (!$result) {
                 $data[] = $file_path;
             }
         }
     }
     $backups_writable = $this->checkDirectoryIsWritable($this->config['dir']['backups'], $show_notifications);
     if (!$backups_writable) {
         $data[] = $this->config['dir']['backups'];
     }
     $upgrades_dir = $this->config['dir']['root'] . '/upgrades';
     $upgrades_writable = $this->checkDirectoryIsWritable($upgrades_dir, $show_notifications);
     if (!$upgrades_writable) {
         $data[] = $upgrades_dir;
     }
     // Exclude duplicates
     $data = array_unique($data);
     if ($show_notifications && empty($data)) {
         return array(false, 'ok');
     } else {
         return array(empty($data), $data);
     }
 }
Exemplo n.º 5
0
/**
 * Merges css and less files
 *
 * @param array $files Array with style files
 * @param string $styles Style code
 * @param string $prepend_prefix Prepend prefix
 * @param array $params additional params
 */
function fn_merge_styles($files, $styles = '', $prepend_prefix = '', $params = array(), $area = AREA)
{
    $prefix = !empty($prepend_prefix) ? 'embedded' : 'standalone';
    $make_rtl = false;
    if (fn_is_rtl_language()) {
        $prefix .= '-rtl';
        $make_rtl = true;
    }
    $output = '';
    $less_output = '';
    $less_reflection = array();
    $compiled_less = '';
    $compiled_css = '';
    $relative_path = fn_get_theme_path('[relative]/[theme]/css', $area);
    $hashes = array();
    $names = array_map(function ($v) {
        return !empty($v['relative']) ? $v['relative'] : false;
    }, $files);
    // Check file changes
    if (Development::isEnabled('compile_check') || Debugger::isActive()) {
        $dir_root = Registry::get('config.dir.root');
        foreach ($names as $index => $name) {
            if (file_exists($dir_root . '/' . $name)) {
                $hashes[] = $name . filemtime($dir_root . '/' . $name);
            }
        }
    }
    $hashes[] = md5(implode('|', $names));
    $hashes[] = md5($styles);
    if ($area == 'C') {
        $hashes[] = Registry::get('runtime.layout.layout_id');
        $hashes[] = Registry::get('runtime.layout.style_id');
    }
    arsort($hashes);
    $hash = md5(implode(',', $hashes) . PRODUCT_VERSION) . fn_get_storage_data('cache_id');
    $filename = $prefix . '.' . $hash . '.css';
    $theme_manifest = Themes::factory(fn_get_theme_path('[theme]', 'C'))->getManifest();
    if (!Storage::instance('assets')->isExist($relative_path . '/' . $filename)) {
        Debugger::checkpoint('Before styles compilation');
        foreach ($files as $src) {
            $m_prefix = '';
            $m_suffix = '';
            if (!empty($src['media'])) {
                $m_prefix = "\n@media " . $src['media'] . " {\n";
                $m_suffix = "\n}\n";
            }
            if (strpos($src['file'], '.css') !== false) {
                $output .= "\n" . $m_prefix . fn_get_contents($src['file']) . $m_suffix;
            } elseif ($area != 'C' || empty($theme_manifest['converted_to_css'])) {
                $less_output_chunk = '';
                if (file_exists($src['file'])) {
                    if ($area == 'C' && (empty($theme_manifest['parent_theme']) || $theme_manifest['parent_theme'] == 'basic')) {
                        $less_output_chunk = "\n" . $m_prefix . fn_get_contents($src['file']) . $m_suffix;
                    } else {
                        $less_output_chunk = "\n" . $m_prefix . '@import "' . str_replace($relative_path . '/', '', $src['relative']) . '";' . $m_suffix;
                    }
                }
                if (!empty($params['reflect_less'])) {
                    if (preg_match('{/addons/([^/]+)/}is', $src['relative'], $m)) {
                        $less_reflection['output']['addons'][$m[1]] .= $less_output_chunk;
                    } else {
                        $less_reflection['output']['main'] .= $less_output_chunk;
                    }
                }
                $less_output .= $less_output_chunk;
            }
        }
        $header = str_replace('[files]', implode("\n", $names), Registry::get('config.js_css_cache_msg'));
        if (!empty($styles)) {
            $less_output .= $styles;
        }
        // Prepend all styles with prefix
        if (!empty($prepend_prefix)) {
            $less_output = $output . "\n" . $less_output;
            $output = '';
        }
        if (!empty($output)) {
            $compiled_css = Less::parseUrls($output, Storage::instance('assets')->getAbsolutePath($relative_path), fn_get_theme_path('[themes]/[theme]/media', $area));
        }
        if (!empty($theme_manifest['converted_to_css']) && $area == 'C') {
            $theme_css_path = fn_get_theme_path('[themes]/[theme]', $area) . '/css';
            $pcl_filepath = $theme_css_path . '/' . Themes::$compiled_less_filename;
            if (file_exists($pcl_filepath)) {
                $compiled_css .= fn_get_contents($pcl_filepath);
            }
            list($installed_addons) = fn_get_addons(array('type' => 'active'));
            foreach ($installed_addons as $addon) {
                $addon_pcl_filpath = $theme_css_path . "/addons/{$addon['addon']}/" . Themes::$compiled_less_filename;
                if (file_exists($pcl_filepath)) {
                    $compiled_css .= fn_get_contents($addon_pcl_filpath);
                }
            }
        }
        if (!empty($less_output)) {
            $less = new Less();
            if (!empty($params['compressed'])) {
                $less->setFormatter('compressed');
            }
            $less->setImportDir($relative_path);
            try {
                $compiled_less = $less->customCompile($less_output, Storage::instance('assets')->getAbsolutePath($relative_path), array(), $prepend_prefix, $area);
            } catch (Exception $e) {
                $skip_save = true;
                $shift = 4;
                $message = '<div style="border: 2px solid red; padding: 5px;">LESS ' . $e->getMessage();
                if (preg_match("/line: (\\d+)/", $message, $m)) {
                    $lo = explode("\n", $less_output);
                    $message .= '<br /><br /><pre>' . implode("\n", array_splice($lo, intval($m[1]) - $shift, $shift * 2)) . '</pre>';
                }
                $message .= '</div>';
                fn_set_notification('E', __('error'), $message);
            }
        }
        if (empty($skip_save)) {
            $compiled_content = $compiled_css . "\n" . $compiled_less;
            // Move all @import links to the Top of the file.
            if (preg_match_all('/@import url.*?;/', $compiled_content, $imports)) {
                $compiled_content = preg_replace('/@import url.*?;/', '', $compiled_content);
                foreach ($imports[0] as $import_link) {
                    $compiled_content = $import_link . "\n" . $compiled_content;
                }
            }
            if ($make_rtl) {
                $compiled_content = \CSSJanus::transform($compiled_content);
                $compiled_content = "body {\ndirection: rtl;\n}\n" . $compiled_content;
            }
            Storage::instance('assets')->put($relative_path . '/' . $filename, array('contents' => $header . $compiled_content, 'compress' => false, 'caching' => true));
            if (!empty($params['use_scheme'])) {
                fn_put_contents(fn_get_cache_path(false) . 'theme_editor/' . $filename, $output . '#LESS#' . $less_output);
            }
            if (!empty($params['reflect_less'])) {
                $less_reflection['import_dirs'] = array($relative_path);
                fn_put_contents(fn_get_cache_path(false) . 'less_reflection.json', json_encode($less_reflection));
            }
        }
        Debugger::checkpoint('After styles compilation');
    }
    $url = Storage::instance('assets')->getUrl($relative_path . '/' . $filename);
    return $url;
}
Exemplo n.º 6
0
 /**
  * Copies theme files from the theme_repository to design folder
  *
  * @param  array $schema UC package schema
  * @return array List of processed files
  */
 protected function processThemesFiles($schema)
 {
     if (empty($schema['files'])) {
         return array();
     }
     $repo_files = array();
     $repo_path = str_replace($this->config['dir']['root'] . '/', '', $this->config['dir']['themes_repository']);
     // Process themes_repository
     foreach ($schema['files'] as $file_path => $file_data) {
         if (strpos($file_path, $repo_path) !== false) {
             $path = str_replace($repo_path, '', $file_path);
             $path = explode('/', $path);
             $theme_name = array_shift($path);
             $repo_files[$theme_name][] = implode('/', $path);
         }
     }
     $themes = fn_get_dir_contents($this->config['dir']['root'] . '/design/themes/');
     foreach ($themes as $theme_name) {
         $manifest = Themes::factory($theme_name)->getManifest();
         $parent_theme = empty($manifest['parent_theme']) ? 'basic' : $manifest['parent_theme'];
         if (!empty($repo_files[$parent_theme])) {
             foreach ($repo_files[$parent_theme] as $file_path) {
                 // Check if we need to create folders path before copying
                 $dir_path = dirname($this->config['dir']['root'] . '/design/themes/' . $theme_name . '/' . $file_path);
                 fn_mkdir($dir_path);
                 fn_copy($this->config['dir']['themes_repository'] . $parent_theme . '/' . $file_path, $this->config['dir']['root'] . '/design/themes/' . $theme_name . '/' . $file_path);
             }
         }
     }
     return $repo_files;
 }
Exemplo n.º 7
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;
    }
    SecurityHelper::sanitizeObjectData('company', $company_data);
    if (Registry::get('runtime.company_id')) {
        if (fn_allowed_for('MULTIVENDOR')) {
            unset($company_data['shippings']);
        } elseif (fn_allowed_for('ULTIMATE')) {
            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_change_company_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');
        $install_layouts = true;
        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 (!empty($company_data['clone']['layouts']) && $company_data['clone']['layouts'] == 'Y') {
                    $install_layouts = false;
                }
            }
        }
        if (fn_allowed_for('ULTIMATE')) {
            $logo_ids = fn_install_theme($theme_name, $company_id, $install_layouts);
            // Set theme settings
            Themes::factory($theme_name)->overrideSettings(null, $company_id);
        } 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.º 8
0
/**
 * Updates addon status
 *
 * @param string $addon             Addon to update status for
 * @param string $status            Status to change to
 * @param bool   $show_notification Display notification if set to true
 * @param bool   $on_install        If status was changed right after install process
 * @param bool   $allow_unmanaged   Whether to allow change status for unmanaged addons in non-console environment
 *
 * @return bool|string True on success, old status ID if status was not changed
 */
function fn_update_addon_status($addon, $status, $show_notification = true, $on_install = false, $allow_unmanaged = false)
{
    $old_status = db_get_field("SELECT status FROM ?:addons WHERE addon = ?s", $addon);
    $new_status = $status;
    $scheme = SchemesManager::getScheme($addon);
    // Unmanaged addons can be enabled/disabled via console only
    if ($scheme->getUnmanaged() && !($allow_unmanaged || defined('CONSOLE'))) {
        return false;
    }
    /**
     * Hook is executed before changing add-on status (i.e. before add-on enabling or disabling).
     *
     * @param string                  $addon             Add-on name
     * @param string                  $status            New addon status - "A" for enabled, "D" for disabled
     * @param bool                    $show_notification Display notification if set to true
     * @param bool                    $on_install        If status was changed right after install process
     * @param bool                    $allow_unmanaged   Whether to allow change status for unmanaged addons in non-console environment
     * @param string                  $old_status        Previous addon status - "A" for enabled, "D" for disabled
     * @param \Tygh\Addons\AXmlScheme $scheme            Add-on scheme
     */
    fn_set_hook('update_addon_status_pre', $addon, $status, $show_notification, $on_install, $allow_unmanaged, $old_status, $scheme);
    if ($old_status != $new_status) {
        // Check if addon can be enabled
        $conflicts = db_get_fields("SELECT addon FROM ?:addons WHERE status = 'A' AND FIND_IN_SET(?s, conflicts)", $addon);
        if ($new_status == 'A' && !empty($conflicts)) {
            $scheme = SchemesManager::getScheme($addon);
            fn_set_notification('W', __('warning'), __('text_addon_cannot_enable', array('[addons]' => implode(', ', SchemesManager::getNames($conflicts)), '[addon_name]' => $scheme->getName())));
            return $old_status;
        }
        fn_get_schema('settings', 'actions.functions', 'php', true);
        $func = 'fn_settings_actions_addons_' . $addon;
        if (function_exists($func)) {
            $func($new_status, $old_status, $on_install);
        }
        // If status change is allowed, update it
        if ($old_status != $new_status) {
            if ($new_status != 'D') {
                // Check that addon have conflicts
                $scheme = SchemesManager::getScheme($addon);
                $conflicts = db_get_field("SELECT conflicts FROM ?:addons WHERE addon = ?s", $addon);
                if (!empty($conflicts)) {
                    $conflicts = explode(',', $conflicts);
                    $conflicted_addons = db_get_fields("SELECT addon FROM ?:addons WHERE addon IN (?a) AND status = 'A'", $conflicts);
                    if (!empty($conflicted_addons)) {
                        $lang_var = 'text_addon_confclicts_on_install';
                        if (!$on_install) {
                            foreach ($conflicts as $conflict) {
                                fn_disable_addon($conflict, $scheme->getName(), $show_notification);
                            }
                            $lang_var = 'text_addon_confclicts';
                        }
                        fn_set_notification('W', __('warning'), __($lang_var, array('[addons]' => implode(', ', SchemesManager::getNames($conflicts)), '[addon_name]' => $scheme->getName())));
                        // On install we cannot enable addon with conflicts automaticly
                        if ($on_install) {
                            return $old_status;
                        }
                    }
                }
            }
            db_query("UPDATE ?:addons SET status = ?s WHERE addon = ?s", $status, $addon);
            $func = 'fn_settings_actions_addons_post_' . $addon;
            if (function_exists($func)) {
                $func($status);
            }
            if ($show_notification == true) {
                fn_set_notification('N', __('notice'), __('status_changed'));
            }
            // Enable/disable tabs for addon
            ProductTabs::instance()->updateAddonTabStatus($addon, $new_status);
            Registry::set('addons.' . $addon . '.status', $status);
        } else {
            return $old_status;
        }
    }
    // Clean cache
    fn_clear_cache();
    if ($status == 'A') {
        foreach (fn_get_installed_themes() as $theme_name) {
            $theme = Themes::factory($theme_name);
            $theme_manifest = $theme->getManifest();
            // Precompile addon LESS files if the theme has been converted to CSS
            if (!empty($theme_manifest['converted_to_css']) && !$theme->convertAddonToCss($addon)) {
                fn_update_addon_status($addon, 'D', $show_notification, $on_install);
                return $old_status;
            }
        }
    }
    /**
     * Hook is executed after changing add-on status (i.e. after add-on enabling or disabling).
     *
     * @param string                  $addon             Add-on name
     * @param string                  $status            New addon status - "A" for enabled, "D" for disabled
     * @param bool                    $show_notification Display notification if set to true
     * @param bool                    $on_install        If status was changed right after install process
     * @param bool                    $allow_unmanaged   Whether to allow change status for unmanaged addons in non-console environment
     * @param string                  $old_status        Previous addon status - "A" for enabled, "D" for disabled
     * @param \Tygh\Addons\AXmlScheme $scheme            Add-on scheme
     */
    fn_set_hook('update_addon_status_post', $addon, $status, $show_notification, $on_install, $allow_unmanaged, $old_status, $scheme);
    return true;
}
Exemplo n.º 9
0
 public static function checkDesignChanges($store_data)
 {
     $result = true;
     foreach (fn_get_installed_themes() as $theme_name) {
         $theme = Themes::factory($theme_name);
         $theme_manifest = $theme->getManifest();
         if (!empty($theme_manifest['converted_to_css']) && $theme_manifest['converted_to_css'] == true) {
             $result = false;
             break;
         }
     }
     return $result;
 }
Exemplo n.º 10
0
    if (fn_allowed_for('ULTIMATE') && !Registry::get('runtime.company_id')) {
        return array(CONTROLLER_STATUS_OK);
    }
    $available_themes = fn_get_available_themes(Registry::get('settings.theme_name'));
    if (!empty($available_themes['repo']) && !empty($available_themes['installed'])) {
        $available_themes['repo'] = array_diff_key($available_themes['repo'], $available_themes['installed']);
    }
    Tygh::$app['view']->assign('themes_prefix', fn_get_theme_path('[relative]', 'C'));
    Tygh::$app['view']->assign('repo_prefix', fn_get_theme_path('[repo]', 'C'));
    Registry::set('navigation.tabs', array('installed_themes' => array('title' => __('installed_themes'), 'js' => true), 'browse_all_available_themes' => array('title' => __('browse_all_available_themes'), 'js' => true)));
    $theme_name = fn_get_theme_path('[theme]', 'C');
    $layout = Layout::instance()->getDefault($theme_name);
    $style = Styles::factory($theme_name)->get($layout['style_id']);
    $layout['style_name'] = empty($style['name']) ? '' : $style['name'];
    Tygh::$app['view']->assign('layout', $layout);
    foreach ($available_themes['installed'] as $theme_id => $theme) {
        $layouts_params = array('theme_name' => $theme_id);
        $available_themes['installed'][$theme_id]['layouts'] = Layout::instance()->getList($layouts_params);
        if ($theme_id == $theme_name) {
            $available_themes['current']['layouts'] = $available_themes['installed'][$theme_id]['layouts'];
        }
    }
    if (isset($_REQUEST['show_conflicts']) && isset($_REQUEST['theme_name']) && isset($available_themes['installed'][$_REQUEST['theme_name']])) {
        $requested_theme_name = $available_themes['installed'][$_REQUEST['theme_name']]['title'];
        $conflicts = Themes::factory($_REQUEST['theme_name'])->getSettingsOverrides();
        Tygh::$app['view']->assign('requested_theme_name', $requested_theme_name);
        Tygh::$app['view']->assign('conflicts', $conflicts);
    }
    Tygh::$app['view']->assign('available_themes', $available_themes);
    Tygh::$app['view']->assign('dev_modes', Development::get());
}