Beispiel #1
0
        $func = 'fn_settings_actions_addons_' . $_REQUEST['id'];
        if (function_exists($func)) {
            $func($new_status, $old_status);
        }
        if ($old_status != $new_status) {
            db_query("UPDATE ?:addons SET status = ?s WHERE addon = ?s", $_REQUEST['status'], $_REQUEST['id']);
            fn_set_notification('N', fn_get_lang_var('notice'), fn_get_lang_var('status_changed'));
        } else {
            $ajax->assign('return_status', $old_status);
        }
    }
    exit;
} elseif ($mode == 'manage') {
    $all_addons = fn_get_dir_contents(DIR_ADDONS, true, false);
    $installed_addons = db_get_hash_array("SELECT a.addon, a.status, d.description as name, b.description, LENGTH(a.options) as has_options, d.object_id, d.object_type FROM ?:addons as a LEFT JOIN ?:addon_descriptions as d ON d.addon = a.addon AND d.object_id = '' AND d.object_type = 'A' AND d.lang_code = ?s LEFT JOIN ?:addon_descriptions as b ON b.addon = a.addon AND b.object_id = '' AND b.object_type = 'D' AND b.lang_code = ?s ORDER BY d.description ASC", 'addon', CART_LANGUAGE, CART_LANGUAGE);
    fn_update_lang_objects('installed_addons', $installed_addons);
    $addons_list = array();
    foreach ($all_addons as $addon) {
        if (!empty($installed_addons[$addon])) {
            $addons_list[$addon] = $installed_addons[$addon];
        } else {
            if (file_exists(DIR_ADDONS . $addon . '/addon.xml')) {
                $xml = simplexml_load_file(DIR_ADDONS . $addon . '/addon.xml');
                $addons_list[$addon] = array('status' => 'N', 'name' => (string) $xml->name);
            }
        }
    }
    $view->assign('addons_list', fn_sort_array_by_key($addons_list, 'name', SORT_ASC));
}
/**
 * Update addon options
Beispiel #2
0
        unset($_REQUEST['redirect_url']);
        fn_clear_cache();
        return array(CONTROLLER_STATUS_REDIRECT, $redirect_url);
    }
    return array(CONTROLLER_STATUS_OK, 'settings' . $_suffix . '?section_id=' . Settings::instance()->getSectionTextId($section_id));
}
//
// OUPUT routines
//
if ($mode == 'manage') {
    $subsections = Settings::instance()->getSectionTabs($section_id, CART_LANGUAGE);
    $options = Settings::instance()->getList($section_id);
    fn_update_lang_objects('subsections', $subsections);
    // [Page sections]
    if (!empty($subsections)) {
        Registry::set('navigation.tabs.main', array('title' => __('main'), 'js' => true));
        foreach ($subsections as $k => $v) {
            Registry::set('navigation.tabs.' . $k, array('title' => $v['description'], 'js' => true));
        }
    }
    // [/Page sections]
    // Set navigation menu
    $sections = Registry::get('navigation.static.top.settings.items');
    fn_update_lang_objects('sections', $sections);
    Registry::set('navigation.dynamic.sections', $sections);
    Registry::set('navigation.dynamic.active_section', Settings::instance()->getSectionTextId($section_id));
    Tygh::$app['view']->assign('options', $options);
    Tygh::$app['view']->assign('subsections', $subsections);
    Tygh::$app['view']->assign('section_id', Settings::instance()->getSectionTextId($section_id));
    Tygh::$app['view']->assign('settings_title', Settings::instance()->getSectionName($section_id));
}
/**
 * Gets addons list
 *
 * @param array $params search params
 * @param int $items_per_page items per page for pagination
 * @param string $lang_code language code
 * @return array addons list and filtered search params
 */
function fn_get_addons($params, $items_per_page = 0, $lang_code = CART_LANGUAGE)
{
    $params = LastView::instance()->update('addons', $params);
    $default_params = array('type' => 'any');
    $params = array_merge($default_params, $params);
    $addons = array();
    $sections = Settings::instance()->getAddons();
    $all_addons = fn_get_dir_contents(Registry::get('config.dir.addons'), true, false);
    $installed_addons = db_get_hash_array('SELECT a.addon, a.status, b.name as name, b.description as description, a.separate, a.unmanaged, a.has_icon ' . 'FROM ?:addons as a LEFT JOIN ?:addon_descriptions as b ON b.addon = a.addon AND b.lang_code = ?s' . 'ORDER BY b.name ASC', 'addon', $lang_code);
    foreach ($installed_addons as $key => $addon) {
        $installed_addons[$key]['has_sections'] = Settings::instance()->sectionExists($sections, $addon['addon']);
        $installed_addons[$key]['has_options'] = $installed_addons[$key]['has_sections'] ? Settings::instance()->optionsExists($addon['addon'], 'ADDON') : false;
        // Check add-on snaphot
        if (!fn_check_addon_snapshot($key)) {
            $installed_addons[$key]['status'] = 'D';
            $installed_addons[$key]['snapshot_correct'] = false;
        } else {
            $installed_addons[$key]['snapshot_correct'] = true;
        }
    }
    foreach ($all_addons as $addon) {
        $addon_scheme = SchemesManager::getScheme($addon);
        if (in_array($params['type'], array('any', 'installed', 'active', 'disabled'))) {
            $search_status = $params['type'] == 'active' ? 'A' : ($params['type'] == 'disabled' ? 'D' : '');
            if (!empty($installed_addons[$addon])) {
                // exclude unmanaged addons from the list
                if ($installed_addons[$addon]['unmanaged'] == true) {
                    continue;
                }
                if (!empty($search_status) && $installed_addons[$addon]['status'] != $search_status) {
                    continue;
                }
                $addons[$addon] = $installed_addons[$addon];
                if ($addon_scheme != false && !$addon_scheme->getUnmanaged()) {
                    $addons[$addon]['originals'] = $addon_scheme->getOriginals();
                }
                fn_update_lang_objects('installed_addon', $addons[$addon]);
                // Generate custom description
                $func = 'fn_addon_dynamic_description_' . $addon;
                if (function_exists($func)) {
                    $addons[$addon]['description'] = $func($addons[$addon]['description']);
                }
            }
        }
        if (empty($installed_addons[$addon]) && empty($params['for_company']) && in_array($params['type'], array('any', 'not_installed'))) {
            if ($addon_scheme != false && !$addon_scheme->getUnmanaged()) {
                $addons[$addon] = array('status' => 'N', 'name' => $addon_scheme->getName(), 'snapshot_correct' => fn_check_addon_snapshot($addon), 'description' => $addon_scheme->getDescription(), 'has_icon' => $addon_scheme->hasIcon());
            }
        }
    }
    if (!empty($params['q'])) {
        foreach ($addons as $addon => $addon_data) {
            if (!preg_match('/' . preg_quote($params['q'], '/') . '/ui', $addon_data['name'], $m)) {
                unset($addons[$addon]);
            }
        }
    }
    $addons = fn_sort_array_by_key($addons, 'name', SORT_ASC);
    return array($addons, $params);
}
Beispiel #4
0
 /**
  * Function retuns variants for setting objects
  *
  * Usage (examples):
  *  // Addons
  *  Settings::instance->get_variants('affiliate', 'payment_period');
  *
  *  // Core same as addons but if $section_tab_name is empty it will be setted to 'main'
  *  Settings::instance->get_variants('general', 'feedback_type');
  *
  *  // Return variants only by setting id, but function not check custom variant functions
  *  Settings::instance->get_variants('', '', '', 40);
  *
  *  // Return variants only by setting id, and checks custom variant functions
  *  Settings::instance->get_variants('affiliate', 'payment_period', '', 40);
  *
  * @param  string $section_name     Setting name
  * @param  string $setting_name     Section name
  * @param  string $section_tab_name Section tab name
  * @param  int    $object_id        Id of setting in setting_objects table
  * @param  string $lang_code        2 letters language code
  * @return array  Array of variants or empty array if this setting have no variants
  */
 public function getVariants($section_name, $setting_name, $section_tab_name = '', $object_id = null, $lang_code = CART_LANGUAGE)
 {
     fn_get_schema('settings', 'variants.functions', 'php', true);
     $variants = array();
     // Generate custom variants
     $addon_variant_func = 'fn_settings_variants_addons_' . fn_strtolower($section_name) . '_' . fn_strtolower($setting_name);
     $core_variant_func = 'fn_settings_variants_' . fn_strtolower($section_name) . '_' . ($section_tab_name != 'main' ? fn_strtolower($section_tab_name) . '_' : '') . fn_strtolower($setting_name);
     if (function_exists($addon_variant_func)) {
         $variants = $addon_variant_func();
     } elseif (function_exists($core_variant_func)) {
         $variants = $core_variant_func();
     } else {
         // If object id is 0 try to get it from section name and setting name
         if ($object_id === null || $object_id === 0) {
             $object_id = $this->getId($setting_name, $section_name);
         }
         if ($object_id !== null && $object_id !== 0 || $object_id == 'all') {
             if ($object_id == 'all') {
                 $object_condition = '';
             } else {
                 $object_condition = db_quote('?:settings_variants.object_id = ?i AND', $object_id);
             }
             $_variants = db_get_array("SELECT ?:settings_variants.*, ?:settings_descriptions.value, ?:settings_descriptions.object_type " . "FROM ?:settings_variants " . "INNER JOIN ?:settings_descriptions " . "ON ?:settings_descriptions.object_id = ?:settings_variants.variant_id AND object_type = ?s " . "WHERE ?p ?:settings_descriptions.lang_code = ?s ORDER BY ?:settings_variants.position", Settings::VARIANT_DESCRIPTION, $object_condition, $lang_code);
             fn_update_lang_objects('variants', $_variants);
             foreach ($_variants as $variant) {
                 if ($object_id == 'all') {
                     $variants[$variant['name']] = array('value' => $variant['value']);
                 } else {
                     $variants[$variant['name']] = $variant['value'];
                 }
             }
         } else {
             if (Debugger::isActive() || fn_is_development()) {
                 $message = str_replace("[option_id]", $setting_name, __('setting_has_no_variants'));
                 fn_set_notification('E', __('error'), $message);
             }
             return $variants;
         }
     }
     return $variants;
 }
Beispiel #5
0
/**
 * Gets addons list
 *
 * @param array $params search params
 * @param int $items_per_page items per page for pagination
 * @param string $lang_code language code
 * @return array addons list and filtered search params
 */
function fn_get_addons($params, $items_per_page = 0, $lang_code = CART_LANGUAGE)
{
    $params = LastView::instance()->update('addons', $params);
    $addons_counter = array('installed' => 0, 'activated' => 0, 'core' => 0, 'other' => 0);
    $default_params = array('type' => 'any');
    $params = array_merge($default_params, $params);
    $addons = array();
    $sections = Settings::instance()->getAddons();
    $all_addons = fn_get_dir_contents(Registry::get('config.dir.addons'), true, false);
    $installed_addons = db_get_hash_array('SELECT a.addon, a.status, b.name as name, b.description as description, a.separate, a.unmanaged, a.has_icon, a.install_datetime ' . 'FROM ?:addons as a LEFT JOIN ?:addon_descriptions as b ON b.addon = a.addon AND b.lang_code = ?s' . 'ORDER BY b.name ASC', 'addon', $lang_code);
    $addons_counter['installed'] = count($installed_addons);
    foreach ($installed_addons as $key => $addon) {
        $installed_addons[$key]['has_sections'] = Settings::instance()->sectionExists($sections, $addon['addon']);
        $installed_addons[$key]['has_options'] = $installed_addons[$key]['has_sections'] ? Settings::instance()->optionsExists($addon['addon'], 'ADDON') : false;
        // Check add-on snaphot
        if (!fn_check_addon_snapshot($key)) {
            $installed_addons[$key]['status'] = 'D';
            $installed_addons[$key]['snapshot_correct'] = false;
        } else {
            $installed_addons[$key]['snapshot_correct'] = true;
        }
        if ($installed_addons[$key]['status'] == 'A') {
            $addons_counter['activated']++;
        }
    }
    foreach ($all_addons as $addon) {
        $addon_scheme = SchemesManager::getScheme($addon);
        // skip addons with broken or missing scheme
        if (!$addon_scheme) {
            continue;
        }
        if ($addon_scheme->isCoreAddon()) {
            $addons_counter['core']++;
        } else {
            $addons_counter['other']++;
        }
        if (in_array($params['type'], array('any', 'installed', 'active', 'disabled'))) {
            $search_status = $params['type'] == 'active' ? 'A' : ($params['type'] == 'disabled' ? 'D' : '');
            if (!empty($installed_addons[$addon])) {
                // exclude unmanaged addons from the list
                if ($installed_addons[$addon]['unmanaged'] == true) {
                    continue;
                }
                if (!empty($search_status) && $installed_addons[$addon]['status'] != $search_status) {
                    continue;
                }
                $addons[$addon] = $installed_addons[$addon];
                $addons[$addon]['supplier'] = $addon_scheme->getSupplier();
                $addons[$addon]['supplier_link'] = $addon_scheme->getSupplierLink();
                $addons[$addon]['version'] = $addon_scheme->getVersion();
                $addons[$addon]['is_core_addon'] = $addon_scheme->isCoreAddon();
                $addons[$addon]['delete_url'] = '';
                $addons[$addon]['url'] = fn_url("addons.update?addon={$addon}&return_url=" . urlencode(Registry::get('config.current_url')));
                if (!Registry::get('runtime.company_id')) {
                    $addons[$addon]['delete_url'] = fn_url("addons.uninstall?addon={$addon}&redirect_url=" . urlencode(Registry::get('config.current_url')));
                }
                if ($addon_scheme != false && !$addon_scheme->getUnmanaged()) {
                    $addons[$addon]['originals'] = $addon_scheme->getOriginals();
                }
                fn_update_lang_objects('installed_addon', $addons[$addon]);
                if (is_file(Registry::get('config.dir.addons') . $addon . '/func.php')) {
                    require_once Registry::get('config.dir.addons') . $addon . '/func.php';
                    if (is_file(Registry::get('config.dir.addons') . $addon . '/config.php')) {
                        require_once Registry::get('config.dir.addons') . $addon . '/config.php';
                    }
                    // Generate custom description
                    $func = 'fn_addon_dynamic_description_' . $addon;
                    if (function_exists($func)) {
                        $addons[$addon]['description'] = $func($addons[$addon]['description']);
                    }
                    //Generate custom url
                    $url_func = 'fn_addon_dynamic_url_' . $addon;
                    if (function_exists($url_func)) {
                        list($addons[$addon]['url'], $addons[$addon]['delete_url']) = $url_func($addons[$addon]['url'], $addons[$addon]['delete_url']);
                    }
                }
            }
        }
        if (empty($installed_addons[$addon]) && empty($params['for_company']) && in_array($params['type'], array('any', 'not_installed'))) {
            if ($addon_scheme != false && !$addon_scheme->getUnmanaged()) {
                $addons[$addon] = array('status' => 'N', 'name' => $addon_scheme->getName(), 'version' => $addon_scheme->getVersion(), 'supplier' => $addon_scheme->getSupplier(), 'supplier_link' => $addon_scheme->getSupplierLink(), 'snapshot_correct' => fn_check_addon_snapshot($addon), 'description' => $addon_scheme->getDescription(), 'has_icon' => $addon_scheme->hasIcon(), 'is_core_addon' => $addon_scheme->isCoreAddon(), 'install_datetime' => null);
            }
        }
    }
    if (!empty($params['q'])) {
        foreach ($addons as $addon => $addon_data) {
            if (!preg_match('/' . preg_quote($params['q'], '/') . '/ui', $addon_data['name'] . $addon_data['supplier'], $m)) {
                unset($addons[$addon]);
            }
        }
    }
    if (!empty($params['source'])) {
        $is_core_addon = $params['source'] == 'core';
        foreach ($addons as $addon => $addon_data) {
            if ($is_core_addon != $addon_data['is_core_addon']) {
                unset($addons[$addon]);
            }
        }
    }
    $addons = fn_sort_array_by_key($addons, 'name', SORT_ASC);
    return array($addons, $params, $addons_counter);
}
Beispiel #6
0
        Registry::clearCachedKeyValues();
    }
    if ($mode == 'uninstall') {
        fn_uninstall_addon($_REQUEST['addon']);
    }
    return array(CONTROLLER_STATUS_OK, 'addons.manage');
}
if ($mode == 'update') {
    $addon_name = addslashes($_REQUEST['addon']);
    $section = Settings::instance()->getSectionByName($_REQUEST['addon'], Settings::ADDON_SECTION);
    if (empty($section)) {
        return array(CONTROLLER_STATUS_NO_PAGE);
    }
    $subsections = Settings::instance()->getSectionTabs($section['section_id'], CART_LANGUAGE);
    $options = Settings::instance()->getList($section['section_id']);
    fn_update_lang_objects('sections', $subsections);
    fn_update_lang_objects('options', $options);
    Tygh::$app['view']->assign('options', $options);
    Tygh::$app['view']->assign('subsections', $subsections);
    $addon = db_get_row('SELECT a.addon, a.status, b.name as name, b.description as description, a.separate ' . 'FROM ?:addons as a LEFT JOIN ?:addon_descriptions as b ON b.addon = a.addon AND b.lang_code = ?s WHERE a.addon = ?s' . 'ORDER BY b.name ASC', CART_LANGUAGE, $_REQUEST['addon']);
    if ($addon['separate'] == true || !defined('AJAX_REQUEST')) {
        Tygh::$app['view']->assign('separate', true);
        Tygh::$app['view']->assign('addon_name', $addon['name']);
    }
} elseif ($mode == 'manage') {
    $params = $_REQUEST;
    $params['for_company'] = (bool) Registry::get('runtime.company_id');
    list($addons, $search) = fn_get_addons($params);
    Tygh::$app['view']->assign('search', $search);
    Tygh::$app['view']->assign('addons_list', $addons);
}
 function assign($tpl_var, $value = null, $escape = true)
 {
     fn_update_lang_objects($tpl_var, $value);
     if (is_array($tpl_var)) {
         $this->trigger_error("Assigning by array is not implemented");
     } else {
         if ($tpl_var != '') {
             $this->_tpl_vars[$tpl_var] = $escape ? fn_html_escape($value) : $value;
         }
     }
 }