/**
 * Set hook to use by addons
 *
 * @param mixed $argN argument, passed to addon
 * @return boolean always true
 */
function fn_set_hook($arg0 = NULL, &$arg1 = NULL, &$arg2 = NULL, &$arg3 = NULL, &$arg4 = NULL, &$arg5 = NULL, &$arg6 = NULL, &$arg7 = NULL, &$arg8 = NULL, &$arg9 = NULL, &$arg10 = NULL, &$arg11 = NULL, &$arg12 = NULL, &$arg13 = NULL, &$arg14 = NULL, &$arg15 = NULL)
{
    $hooks = Registry::get('hooks');
    $test = $arg0;
    static $loaded_addons;
    static $callable_functions;
    static $hooks_already_sorted;
    for ($args = array(), $i = 0; $i < 16; $i++) {
        $name = 'arg' . $i;
        if ($i < func_num_args()) {
            $args[$i] =& ${$name};
        }
        unset(${$name}, $name);
    }
    //    if($test=="calculate_cart_items"){
    //        //var_dump($callback['func']); echo" ==== ";
    //        var_dump($args); echo"<br/>______________________________<br/>";
    //    }
    $hook_name = array_shift($args);
    // Check for the core functions
    $core_func = 'fn_core_' . $hook_name;
    if (is_callable($core_func)) {
        call_user_func_array($core_func, $args);
    }
    $edition_acronym = fn_get_edition_acronym(PRODUCT_EDITION);
    if (!empty($edition_acronym)) {
        $edition_hook_func = "fn_{$edition_acronym}_{$hook_name}";
        if (function_exists($edition_hook_func)) {
            call_user_func_array($edition_hook_func, $args);
        }
    }
    if (isset($hooks[$hook_name])) {
        // cache hooks sorting
        if (!isset($hooks_already_sorted[$hook_name])) {
            $hooks[$hook_name] = fn_sort_array_by_key($hooks[$hook_name], 'priority');
            $hooks_already_sorted[$hook_name] = true;
            Registry::set('hooks', $hooks, true);
        }
        foreach ($hooks[$hook_name] as $callback) {
            //cache loaded addon
            if (!isset($loaded_addons[$callback['addon']])) {
                // FIXME: duplicate with cache in fn_load_addon
                fn_load_addon($callback['addon']);
                $loaded_addons[$callback['addon']] = true;
            }
            // cache if hook function callable
            if (!isset($callable_functions[$callback['func']])) {
                if (!is_callable($callback['func'])) {
                    throw new DeveloperException("Hook {$callback['func']} is not callable");
                }
                $callable_functions[$callback['func']] = true;
            }
            call_user_func_array($callback['func'], $args);
        }
    }
    return true;
}
Example #2
0
/**
 * Set hook to use by addons
 *
 * @param mixed $argN argument, passed to addon
 * @return boolean always true
 */
function fn_set_hook($hook_name = NULL, &$arg1 = NULL, &$arg2 = NULL, &$arg3 = NULL, &$arg4 = NULL, &$arg5 = NULL, &$arg6 = NULL, &$arg7 = NULL, &$arg8 = NULL, &$arg9 = NULL, &$arg10 = NULL, &$arg11 = NULL, &$arg12 = NULL, &$arg13 = NULL, &$arg14 = NULL, &$arg15 = NULL)
{
    static $callable_functions;
    static $hooks_already_sorted;
    static $edition_acronym;
    static $hooks = null;
    static $addons_initiated = false;
    if (!$addons_initiated) {
        $addons_initiated = Registry::get('addons_initiated');
    }
    if ($hooks === null || !$addons_initiated || defined('DISABLE_HOOK_CACHE')) {
        $hooks = Registry::get('hooks');
    }
    $arg_count = func_num_args();
    if ($arg_count === 1) {
        $args = array();
    } elseif ($arg_count === 2) {
        $args = array(&$arg1);
    } elseif ($arg_count === 3) {
        $args = array(&$arg1, &$arg2);
    } elseif ($arg_count === 4) {
        $args = array(&$arg1, &$arg2, &$arg3);
    } elseif ($arg_count === 5) {
        $args = array(&$arg1, &$arg2, &$arg3, &$arg4);
    } elseif ($arg_count === 6) {
        $args = array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5);
    } elseif ($arg_count === 7) {
        $args = array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6);
    } elseif ($arg_count === 8) {
        $args = array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, &$arg7);
    } elseif ($arg_count === 9) {
        $args = array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, &$arg7, &$arg8);
    } elseif ($arg_count === 10) {
        $args = array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, &$arg7, &$arg8, &$arg9);
    } elseif ($arg_count === 11) {
        $args = array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, &$arg7, &$arg8, &$arg9, &$arg10);
    } elseif ($arg_count === 12) {
        $args = array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, &$arg7, &$arg8, &$arg9, &$arg10, &$arg11);
    } elseif ($arg_count === 13) {
        $args = array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, &$arg7, &$arg8, &$arg9, &$arg10, &$arg11, &$arg12);
    } elseif ($arg_count === 14) {
        $args = array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, &$arg7, &$arg8, &$arg9, &$arg10, &$arg11, &$arg12, &$arg13);
    } elseif ($arg_count === 15) {
        $args = array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, &$arg7, &$arg8, &$arg9, &$arg10, &$arg11, &$arg12, &$arg13, &$arg14);
    } elseif ($arg_count === 16) {
        $args = array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, &$arg7, &$arg8, &$arg9, &$arg10, &$arg11, &$arg12, &$arg13, &$arg14, &$arg15);
    }
    // Check for the core functions
    if (is_callable('fn_core_' . $hook_name)) {
        call_user_func_array('fn_core_' . $hook_name, $args);
    }
    $edition_acronym = fn_get_edition_acronym(PRODUCT_EDITION);
    if (!empty($edition_acronym) && function_exists("fn_{$edition_acronym}_{$hook_name}")) {
        call_user_func_array("fn_{$edition_acronym}_{$hook_name}", $args);
    }
    if (isset($hooks[$hook_name])) {
        // cache hooks sorting
        if (!isset($hooks_already_sorted[$hook_name])) {
            $hooks[$hook_name] = fn_sort_array_by_key($hooks[$hook_name], 'priority');
            $hooks_already_sorted[$hook_name] = true;
            Registry::set('hooks', $hooks, true);
        }
        foreach ($hooks[$hook_name] as $callback) {
            // cache if hook function callable
            if (!isset($callable_functions[$callback['func']])) {
                if (!is_callable($callback['func'])) {
                    throw new DeveloperException("Hook {$callback['func']} is not callable");
                }
                $callable_functions[$callback['func']] = true;
            }
            call_user_func_array($callback['func'], $args);
        }
    }
    return true;
}
Example #3
0
 public static function checkEditionMapping($store_data)
 {
     if (in_array($store_data['product_version'], array('4.0.1', '4.0.2', '4.0.3', '4.1.1', '4.1.2', '4.1.3', '4.1.4', '4.1.5', '4.2.1'))) {
         return false;
     }
     $mapping = array('4' => array('ult_ult', 'mve_mve'), '3' => array('pro_ult', 'ult_ult', 'mve_mve'), '2' => array('pro_pro', 'mve_mve', 'pro_ult'));
     if (!empty($store_data)) {
         $orig_edition = fn_get_edition_acronym($store_data['product_edition']);
         $orig_version = substr($store_data['product_version'], 0, 1);
         $edition_str = $orig_edition . '_' . fn_get_edition_acronym(PRODUCT_EDITION);
         if (in_array(strtolower($edition_str), $mapping[$orig_version])) {
             return true;
         }
     }
     return false;
 }
Example #4
0
/**
 * Set hook to use by addons
 *
 * @param mixed $argN argument, passed to addon
 * @return boolean always true
 */
function fn_set_hook($hook_name = NULL, &$arg1 = NULL, &$arg2 = NULL, &$arg3 = NULL, &$arg4 = NULL, &$arg5 = NULL, &$arg6 = NULL, &$arg7 = NULL, &$arg8 = NULL, &$arg9 = NULL, &$arg10 = NULL, &$arg11 = NULL, &$arg12 = NULL, &$arg13 = NULL, &$arg14 = NULL, &$arg15 = NULL)
{
    /**
     * @var bool[]|null $callable_functions Cache of validations that hook's function is callable groupped by func name.
     */
    static $callable_functions;
    /**
     * @var array $hooks_already_sorted Cache of hook lists ordered by addon priority and groupped by hook name.
     */
    static $hooks_already_sorted = array();
    /**
     * @var array|null $hooks Function's local cache of hooks that have been registered by addons.
     */
    static $hooks = null;
    /**
     * @var bool $addons_initiated Function's local cache of addons' initialization state.
     */
    static $addons_initiated = false;
    // We use local hooks cache that was filled at previous fn_set_hook() call
    // only if addons were already initiated at that call.
    if ($addons_initiated) {
        $update_hooks_cache = false;
    } else {
        $update_hooks_cache = true;
        // Update local cache of addons' init state
        $addons_initiated = Registry::get('addons_initiated');
    }
    if ($hooks === null || $update_hooks_cache || defined('DISABLE_HOOK_CACHE')) {
        // Updating local hooks cache
        $hooks = Registry::get('hooks');
        $hooks_already_sorted = array();
    }
    $arg_count = func_num_args();
    if ($arg_count === 1) {
        $args = array();
    } elseif ($arg_count === 2) {
        $args = array(&$arg1);
    } elseif ($arg_count === 3) {
        $args = array(&$arg1, &$arg2);
    } elseif ($arg_count === 4) {
        $args = array(&$arg1, &$arg2, &$arg3);
    } elseif ($arg_count === 5) {
        $args = array(&$arg1, &$arg2, &$arg3, &$arg4);
    } elseif ($arg_count === 6) {
        $args = array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5);
    } elseif ($arg_count === 7) {
        $args = array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6);
    } elseif ($arg_count === 8) {
        $args = array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, &$arg7);
    } elseif ($arg_count === 9) {
        $args = array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, &$arg7, &$arg8);
    } elseif ($arg_count === 10) {
        $args = array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, &$arg7, &$arg8, &$arg9);
    } elseif ($arg_count === 11) {
        $args = array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, &$arg7, &$arg8, &$arg9, &$arg10);
    } elseif ($arg_count === 12) {
        $args = array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, &$arg7, &$arg8, &$arg9, &$arg10, &$arg11);
    } elseif ($arg_count === 13) {
        $args = array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, &$arg7, &$arg8, &$arg9, &$arg10, &$arg11, &$arg12);
    } elseif ($arg_count === 14) {
        $args = array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, &$arg7, &$arg8, &$arg9, &$arg10, &$arg11, &$arg12, &$arg13);
    } elseif ($arg_count === 15) {
        $args = array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, &$arg7, &$arg8, &$arg9, &$arg10, &$arg11, &$arg12, &$arg13, &$arg14);
    } elseif ($arg_count === 16) {
        $args = array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, &$arg7, &$arg8, &$arg9, &$arg10, &$arg11, &$arg12, &$arg13, &$arg14, &$arg15);
    }
    // Check for the core functions
    if (is_callable('fn_core_' . $hook_name)) {
        call_user_func_array('fn_core_' . $hook_name, $args);
    }
    $edition_acronym = fn_get_edition_acronym(PRODUCT_EDITION);
    if (!empty($edition_acronym) && function_exists("fn_{$edition_acronym}_{$hook_name}")) {
        call_user_func_array("fn_{$edition_acronym}_{$hook_name}", $args);
    }
    if (isset($hooks[$hook_name])) {
        // cache hooks sorting
        if (!isset($hooks_already_sorted[$hook_name])) {
            $hooks[$hook_name] = fn_sort_array_by_key($hooks[$hook_name], 'priority');
            $hooks_already_sorted[$hook_name] = true;
            Registry::set('hooks', $hooks, true);
        }
        foreach ($hooks[$hook_name] as $callback) {
            // cache if hook function callable
            if (!isset($callable_functions[$callback['func']])) {
                if (!is_callable($callback['func'])) {
                    throw new DeveloperException("Hook {$callback['func']} is not callable");
                }
                $callable_functions[$callback['func']] = true;
            }
            call_user_func_array($callback['func'], $args);
        }
    }
    return true;
}
Example #5
0
 /**
  * Returns current edtition acronym
  *
  * @return string Edtition acronym
  */
 private function _getCurrentEdition()
 {
     if (empty($this->_current_edition)) {
         $this->_current_edition = strtoupper(fn_get_edition_acronym(PRODUCT_EDITION));
     }
     return $this->_current_edition . ':';
 }
Example #6
0
 /**
  * Imports nessesared languages
  *
  * @return bool true on success, false otherwise
  */
 public function setupLanguages($demo)
 {
     $languages = $this->_cart_settings['languages'];
     if (!empty($languages)) {
         foreach ($languages as $lang_code) {
             $pack_path = Registry::get('config.dir.install') . App::DB_LANG . "/{$lang_code}/{$lang_code}.po";
             $edition_pack_path = Registry::get('config.dir.install') . App::DB_LANG . "/{$lang_code}/{$lang_code}" . '_' . fn_get_edition_acronym(PRODUCT_EDITION) . '.po';
             if (!file_exists($pack_path)) {
                 App::instance()->setNotification('W', 'Missing language pack', 'Unable to find: ' . $pack_path . ' (skipped)', true);
                 continue;
             }
             $this->_parseSql(Registry::get('config.dir.install') . App::DB_LANG . "/{$lang_code}/" . App::DB_LANG_DATA, 'text_installing_additional_language', array('lang_code' => $lang_code));
             if ($demo) {
                 $this->_parseSql(Registry::get('config.dir.install') . App::DB_LANG . "/{$lang_code}/" . App::DB_LANG_DEMO, 'text_installing_additional_language', array('lang_code' => $lang_code));
             }
             // Install language variables from PO files
             $params = array('lang_code' => $lang_code);
             $_langs = Languages::get($params);
             $is_exists = count($_langs) > 0 ? true : false;
             Languages::installLanguagePack($pack_path, array('reinstall' => $is_exists));
             if (file_exists($edition_pack_path)) {
                 Languages::installLanguagePack($edition_pack_path, array('reinstall' => true));
             }
         }
         // share all additional languages
         if (fn_allowed_for('ULTIMATE')) {
             db_query("REPLACE INTO ?:ult_objects_sharing (`share_company_id`, `share_object_id`, `share_object_type`) " . "SELECT ?:companies.company_id, ?:languages.lang_id, 'languages' " . "FROM ?:languages INNER JOIN ?:companies;");
         }
         $languages = db_get_hash_array("SELECT * FROM ?:languages", 'lang_code');
         Registry::set('languages', $languages);
         return true;
     } else {
         return false;
     }
 }