示例#1
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);
    $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);
}
示例#2
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);
}
示例#3
0
 /**
  * Returns addon promo status
  * @return bool
  */
 public function isPromo()
 {
     $addon_name = (string) $this->_xml->id;
     return !fn_check_addon_snapshot($addon_name);
 }
示例#4
0
             } else {
                 fn_addons_move_and_install($extract_path, Registry::get('config.dir.root'));
                 if (defined('AJAX_REQUEST')) {
                     Tygh::$app['ajax']->assign('force_redirection', fn_url('addons.manage'));
                     exit;
                 }
             }
         }
     }
     if (defined('AJAX_REQUEST')) {
         Tygh::$app['view']->display('views/addons/components/upload_addon.tpl');
         exit;
     }
 }
 if ($mode == 'update_status') {
     $is_snapshot_correct = fn_check_addon_snapshot($_REQUEST['id']);
     if (!$is_snapshot_correct) {
         $status = false;
     } else {
         $status = fn_update_addon_status($_REQUEST['id'], $_REQUEST['status']);
     }
     if ($status !== true) {
         Tygh::$app['ajax']->assign('return_status', $status);
     }
     Registry::clearCachedKeyValues();
 }
 if ($mode == 'install') {
     fn_install_addon($_REQUEST['addon']);
     Registry::clearCachedKeyValues();
 }
 if ($mode == 'uninstall') {
示例#5
0
/**
 * Initialize all enabled addons
 *
 * @return array INIT_STATUS_OK
 */
function fn_init_addons()
{
    Registry::registerCache('addons', array('addons', 'settings_objects', 'settings_vendor_values', 'settings_descriptions', 'settings_sections', 'settings_variants'), Registry::cacheLevel('static'));
    if (Registry::isExist('addons') == false) {
        $init_addons = Registry::get('settings.init_addons');
        $allowed_addons = null;
        if ($init_addons == 'none') {
            $allowed_addons = array();
        } elseif ($init_addons == 'core') {
            $allowed_addons = Snapshot::getCoreAddons();
        }
        $_addons = db_get_hash_array("SELECT addon, priority, status, unmanaged FROM ?:addons WHERE 1 ORDER BY priority", 'addon');
        foreach ($_addons as $k => $v) {
            $_addons[$k] = Settings::instance()->getValues($v['addon'], Settings::ADDON_SECTION, false);
            if (fn_check_addon_snapshot($k)) {
                $_addons[$k]['status'] = $v['status'];
            } else {
                $_addons[$k]['status'] = 'D';
            }
            if ($allowed_addons !== null && !in_array($v['addon'], $allowed_addons)) {
                $_addons[$k]['status'] = 'D';
            }
            $_addons[$k]['priority'] = $v['priority'];
            $_addons[$k]['unmanaged'] = $v['unmanaged'];
        }
        // Some addons could be disabled for vendors.
        if (fn_allowed_for('MULTIVENDOR') && Registry::get('runtime.company_id')) {
            Registry::set('addons', $_addons);
            // So, we have to parse it one more time
            foreach ($_addons as $k => $v) {
                // and check permissions schema.
                // We couldn't make it in the previous cycle because the fn_get_scheme func works only with full list of addons.
                if (!fn_check_addon_permission($k)) {
                    unset($_addons[$k]);
                }
            }
        }
        Registry::set('addons', $_addons);
    }
    foreach ((array) Registry::get('addons') as $addon_name => $data) {
        if (empty($data['status'])) {
            // FIX ME: Remove me
            error_log("ERROR: Addons initialization: Bad '{$addon_name}' addon data:" . serialize($data) . " Addons Registry:" . serialize(Registry::get('addons')));
        }
        if (!empty($data['status']) && $data['status'] == 'A') {
            fn_load_addon($addon_name);
        }
    }
    Registry::set('addons_initiated', true, true);
    return array(INIT_STATUS_OK);
}