/** * The UI to edit a configuration page. * * @return tempcode The UI */ function config_category() { require_javascript('javascript_validation'); /*$GLOBALS['HELPER_PANEL_PIC']='pagepics/config'; $GLOBALS['HELPER_PANEL_TUTORIAL']='tut_adv_configuration';*/ $page = get_param('id'); $title = get_page_title(do_lang_tempcode('CONFIG_CATEGORY_' . $page), false); $post_url = build_url(array('page' => '_SELF', 'type' => 'set', 'id' => $page, 'redirect' => get_param('redirect', NULL)), '_SELF'); $category_description = do_lang_tempcode('CONFIG_CATEGORY_DESCRIPTION__' . $page); $rows = $GLOBALS['SITE_DB']->query_select('config', array('*'), array('the_page' => $page)); // Addin special ones if ($page == 'SITE') { $rows[] = array('the_name' => 'timezone', 'human_name' => 'TIME_ZONE', 'config_value' => '', 'the_type' => 'special', 'eval' => '', 'the_page' => 'SITE', 'section' => 'GENERAL', 'explanation' => '', 'shared_hosting_restricted' => 0); } /*global $M_SORT_KEY; This is a lame sort - it doesn't preserve internal order $M_SORT_KEY='section'; usort($rows,'multi_sort');*/ // Better sort $all_known_groups = array(); foreach ($rows as $myrow) { $_group = do_lang($myrow['section'], NULL, NULL, NULL, NULL, false); if (is_null($_group)) { $_group = $myrow['section']; } $_group = strtolower(trim(preg_replace('#(&.*;)|[^\\w\\d\\s]#U', '', $_group))); if (array_key_exists($_group, $all_known_groups) && $all_known_groups[$_group] != $myrow['section']) { $_group = 'std_' . $myrow['section']; } // If cat names translate to same things or are in non-latin characters like Cyrillic $all_known_groups[$_group] = $myrow['section']; } $old_rows = $rows; $rows = array(); ksort($all_known_groups); foreach ($all_known_groups as $group_codename) { foreach ($old_rows as $myrow) { if ($myrow['section'] == $group_codename) { $rows[] = $myrow; } } } // Move advanced group options to the end $rows2 = array(); foreach ($rows as $i => $row) { if ($row['section'] == 'ADVANCED') { $rows2[] = $row; unset($rows[$i]); } } $rows = array_merge($rows, $rows2); // UI hooks $ui_hooks = find_all_hooks('modules', 'admin_config'); $upload_max_filesize = ini_get('upload_max_filesize') == '0' ? do_lang('NA') : clean_file_size(php_return_bytes(ini_get('upload_max_filesize'))); $post_max_size = ini_get('post_max_size') == '0' ? do_lang('NA') : clean_file_size(php_return_bytes(ini_get('post_max_size'))); $groups = new ocp_tempcode(); require_code('form_templates'); $current_group = ''; $out = ''; $_groups = array(); foreach ($rows as $myrow) { if ($myrow['eval'] != '' && $myrow['the_name'] != 'detect_lang_forum') { if (defined('HIPHOP_PHP')) { require_code('hooks/systems/config_default/' . $myrow['the_name']); $hook = object_factory('Hook_config_default_' . $myrow['the_name']); if (is_null($hook->get_default())) { continue; } } else { $GLOBALS['REQUIRE_LANG_LOOP'] = 10; // LEGACY Workaround for corrupt webhost installers if (is_null(@eval($myrow['eval'] . ';'))) { continue; } // @'d in case default is corrupt, don't want it to give errors forever $GLOBALS['REQUIRE_LANG_LOOP'] = 0; // LEGACY } } $_group = do_lang($myrow['section'], NULL, NULL, NULL, NULL, false); $name = do_lang($myrow['human_name'], NULL, NULL, NULL, NULL, false); $_group_tempcode = is_null($_group) ? make_string_tempcode($myrow['section']) : do_lang_tempcode($myrow['section']); $name_tempcode = is_null($name) ? make_string_tempcode($myrow['human_name']) : do_lang_tempcode($myrow['human_name']); if (get_forum_type() == 'ocf' && $myrow['explanation'] == 'CONFIG_OPTION_forum_in_portal') { $exp_string = $myrow['explanation'] . '__ocf'; } else { $exp_string = $myrow['explanation']; } $_explanation = do_lang($exp_string, NULL, NULL, NULL, NULL, false); if (is_null($_explanation)) { $_explanation = do_lang('CONFIG_GROUP_DEFAULT_DESCRIP_' . $myrow['section'], NULL, NULL, NULL, NULL, false); if (is_null($_explanation)) { $explanation = new ocp_tempcode(); } else { $explanation = do_lang_tempcode('CONFIG_GROUP_DEFAULT_DESCRIP_' . $myrow['section']); } } else { $explanation = do_lang_tempcode($exp_string); } if ($myrow['shared_hosting_restricted'] == 1 && !is_null($GLOBALS['CURRENT_SHARE_USER'])) { continue; } if ($myrow['section'] != $current_group && $current_group != '') { $_current_group = do_lang_tempcode($current_group); $_group_description = do_lang('CONFIG_GROUP_DESCRIP_' . $current_group, escape_html($post_max_size), escape_html($upload_max_filesize), NULL, NULL, false); if (is_null($_group_description)) { $group_description = new ocp_tempcode(); } else { $group_description = do_lang_tempcode('CONFIG_GROUP_DESCRIP_' . $current_group, escape_html($post_max_size), escape_html($upload_max_filesize)); } $group = do_template('CONFIG_GROUP', array('_GUID' => 'af4c31daa1bc39714ab83b11bd6d3e51', 'GROUP_DESCRIPTION' => $group_description, 'GROUP_NAME' => $current_group, 'GROUP' => $out, 'CURRENT_GROUP' => $_current_group)); $groups->attach($group->evaluate()); $out = ''; } $_groups[$myrow['section']] = $_group_tempcode; switch ($myrow['the_type']) { case 'special': switch ($myrow['the_name']) { case 'timezone': $list = ''; $timezone = get_site_timezone(); foreach (get_timezone_list() as $_timezone => $timezone_nice) { $list .= static_evaluate_tempcode(form_input_list_entry($_timezone, $_timezone == $timezone, $timezone_nice)); } $out .= static_evaluate_tempcode(form_input_list(do_lang_tempcode('TIME_ZONE'), do_lang_tempcode('DESCRIPTION_TIMEZONE_SITE'), 'timezone', make_string_tempcode($list))); break; default: require_code('hooks/modules/admin_config/' . filter_naughty_harsh($myrow['the_name'])); $hook_ob = object_factory('Hook_admin_config_' . filter_naughty_harsh($myrow['the_name'])); $out .= static_evaluate_tempcode($hook_ob->run($myrow)); break; } break; case 'integer': $out .= static_evaluate_tempcode(form_input_integer($name_tempcode, $explanation, $myrow['the_name'], intval(get_option($myrow['the_name'])), false)); break; case 'line': if (strpos($myrow['the_name'], 'colour') !== false && substr(get_option($myrow['the_name']), 0, 1) == '#') { $out .= static_evaluate_tempcode(form_input_colour($name_tempcode, $explanation, $myrow['the_name'], get_option($myrow['the_name']), false, NULL, true)); } elseif ($myrow['the_name'] == 'currency') { $list = ''; require_code('currency'); $currencies = array_keys(get_currency_map()); foreach ($currencies as $currency) { $list .= static_evaluate_tempcode(form_input_list_entry($currency, $currency == get_option($myrow['the_name']))); } $out .= static_evaluate_tempcode(form_input_list($name_tempcode, $explanation, $myrow['the_name'], make_string_tempcode($list))); } elseif ($myrow['the_name'] == 'payment_gateway') { $list = ''; $all_via = find_all_hooks('systems', 'ecommerce_via'); foreach (array_keys($all_via) as $via) { $list .= static_evaluate_tempcode(form_input_list_entry($via, $via == get_option($myrow['the_name']))); } $out .= static_evaluate_tempcode(form_input_list($name_tempcode, $explanation, $myrow['the_name'], make_string_tempcode($list))); } else { /*if (strpos($myrow['the_name'],'password')!==false) password fields can't take defaults $out.=static_evaluate_tempcode(form_input_password($name_tempcode,$explanation,$myrow['the_name'],get_option($myrow['the_name']),false)); else */ $out .= static_evaluate_tempcode(form_input_line($name_tempcode, $explanation, $myrow['the_name'], get_option($myrow['the_name']), false)); } break; case 'list': $list = ''; $_value = get_option($myrow['the_name']); $values = explode('|', $myrow['c_data']); foreach ($values as $value) { $_option_text = do_lang('CONFIG_OPTION_' . $myrow['the_name'] . '_VALUE_' . $value, NULL, NULL, NULL, NULL, false); if (!is_null($_option_text)) { $option_text = do_lang_tempcode('CONFIG_OPTION_' . $myrow['the_name'] . '_VALUE_' . $value); } else { $option_text = make_string_tempcode($value); } $list .= static_evaluate_tempcode(form_input_list_entry($value, $_value == $value, $option_text)); } $out .= static_evaluate_tempcode(form_input_list($name_tempcode, $explanation, $myrow['the_name'], make_string_tempcode($list), NULL, false, false)); break; case 'transline': $out .= static_evaluate_tempcode(form_input_line($name_tempcode, $explanation, $myrow['the_name'], get_option($myrow['the_name']), false)); break; case 'text': $out .= static_evaluate_tempcode(form_input_text($name_tempcode, $explanation, $myrow['the_name'], get_option($myrow['the_name']), false, NULL, true)); break; case 'transtext': $out .= static_evaluate_tempcode(form_input_text($name_tempcode, $explanation, $myrow['the_name'], get_option($myrow['the_name']), false, NULL, true)); break; case 'float': $out .= static_evaluate_tempcode(form_input_float($name_tempcode, $explanation, $myrow['the_name'], floatval(get_option($myrow['the_name'])), false)); break; case 'tick': $out .= static_evaluate_tempcode(form_input_tick($name_tempcode, $explanation, $myrow['the_name'], get_option($myrow['the_name']) == '1')); break; case 'date': $out .= static_evaluate_tempcode(form_input_date($name_tempcode, $explanation, $myrow['the_name'], false, false, false, intval(get_option($myrow['the_name'])), 40, intval(date('Y')) - 20, NULL, false)); break; case 'forum': case '?forum': if (get_forum_type() == 'ocf' && addon_installed('ocf_forum')) { $current_setting = get_option($myrow['the_name']); if (!is_numeric($current_setting)) { $_current_setting = $GLOBALS['FORUM_DB']->query_value_null_ok('f_forums', 'id', array('f_name' => $current_setting)); if (is_null($_current_setting)) { if ($myrow['the_type'] == '?forum') { $current_setting = NULL; } else { $current_setting = strval(db_get_first_id()); attach_message(do_lang_tempcode('FORUM_CURRENTLY_UNSET', $name_tempcode), 'notice'); } } else { $current_setting = strval($_current_setting); } } $out .= static_evaluate_tempcode(form_input_tree_list($name_tempcode, $explanation, $myrow['the_name'], NULL, 'choose_forum', array(), false, $current_setting)); } else { $out .= static_evaluate_tempcode(form_input_line($name_tempcode, $explanation, $myrow['the_name'], get_option($myrow['the_name']), false)); } break; case 'category': if (get_forum_type() == 'ocf') { $tmp_value = $GLOBALS['FORUM_DB']->query_value_null_ok('f_categories', 'id', array('c_title' => get_option($myrow['the_name']))); require_code('ocf_forums2'); $_list = ocf_nice_get_categories(NULL, $tmp_value); $out .= static_evaluate_tempcode(form_input_list($name_tempcode, $explanation, $myrow['the_name'], $_list)); } else { $out .= static_evaluate_tempcode(form_input_line($name_tempcode, $explanation, $myrow['the_name'], get_option($myrow['the_name']), false)); } break; case 'usergroup': if (get_forum_type() == 'ocf') { $tmp_value = $GLOBALS['FORUM_DB']->query_value_null_ok('f_groups g LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON t.id=g.g_name', 'g.id', array('text_original' => get_option($myrow['the_name']))); require_code('ocf_groups'); $_list = ocf_nice_get_usergroups($tmp_value); $out .= static_evaluate_tempcode(form_input_list($name_tempcode, $explanation, $myrow['the_name'], $_list)); } else { $out .= static_evaluate_tempcode(form_input_line($name_tempcode, $explanation, $myrow['the_name'], get_option($myrow['the_name']), false)); } break; } $current_group = $myrow['section']; } if ($out != '') { $_group_description = do_lang('CONFIG_GROUP_DESCRIP_' . $current_group, escape_html($post_max_size), escape_html($upload_max_filesize), NULL, NULL, false); if (is_null($_group_description)) { $group_description = new ocp_tempcode(); } else { $group_description = do_lang_tempcode('CONFIG_GROUP_DESCRIP_' . $current_group, escape_html($post_max_size), escape_html($upload_max_filesize)); } $group = do_template('CONFIG_GROUP', array('_GUID' => '84c0db86002a33a383a7c2e195dd3913', 'GROUP_DESCRIPTION' => $group_description, 'GROUP_NAME' => $current_group, 'GROUP' => $out, 'CURRENT_GROUP' => $_group_tempcode)); $groups->attach($group->evaluate()); } list($warning_details, $ping_url) = handle_conflict_resolution(); breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('CONFIGURATION')))); breadcrumb_set_self(do_lang_tempcode('CONFIG_CATEGORY_' . $page)); return do_template('CONFIG_CATEGORY_SCREEN', array('_GUID' => 'd01b28b71c38bbb52b6aaf877c7f7b0e', 'CATEGORY_DESCRIPTION' => $category_description, '_GROUPS' => $_groups, 'PING_URL' => $ping_url, 'WARNING_DETAILS' => $warning_details, 'TITLE' => $title, 'URL' => $post_url, 'GROUPS' => $groups, 'SUBMIT_NAME' => do_lang_tempcode('SAVE'))); }
/** * Standard modular install function. * * @param ?integer What version we're upgrading from (NULL: new install) * @param ?integer What hack version we're upgrading from (NULL: new-install/not-upgrading-from-a-hacked-version) */ function install($upgrade_from = NULL, $upgrade_from_hack = NULL) { if (!is_null($upgrade_from) && $upgrade_from < 3) { $GLOBALS['SITE_DB']->alter_table_field('transactions', 'currency', 'ID_TEXT', 't_currency'); } if (!is_null($upgrade_from) && $upgrade_from < 4) { $GLOBALS['SITE_DB']->add_table_field('transactions', 't_via', 'ID_TEXT', 'paypal'); } if (is_null($upgrade_from) || $upgrade_from < 4) { add_config_option('PAYMENT_GATEWAY', 'payment_gateway', 'line', 'return \'paypal\';', 'ECOMMERCE', 'ECOMMERCE'); add_config_option('USE_LOCAL_PAYMENT', 'use_local_payment', 'tick', 'return \'0\';', 'ECOMMERCE', 'ECOMMERCE'); add_config_option('IPN_PASSWORD', 'ipn_password', 'line', 'return \'\';', 'ECOMMERCE', 'ECOMMERCE'); // SecPay test account: 'secpay'/'secpay' add_config_option('IPN_DIGEST', 'ipn_digest', 'line', 'return \'\';', 'ECOMMERCE', 'ECOMMERCE'); add_config_option('VPN_USERNAME', 'vpn_username', 'line', 'return \'\';', 'ECOMMERCE', 'ECOMMERCE'); // SecPay: not needed add_config_option('VPN_PASSWORD', 'vpn_password', 'line', 'return \'\';', 'ECOMMERCE', 'ECOMMERCE'); // SecPay test account: 'secpay'/'secpay' add_config_option('CALLBACK_PASSWORD', 'callback_password', 'line', 'return \'\';', 'ECOMMERCE', 'ECOMMERCE'); // SecPay: not needed add_config_option('POSTAL_ADDRESS', 'pd_address', 'text', 'return \'\';', 'ECOMMERCE', 'ECOMMERCE'); // SecPay: not needed add_config_option('EMAIL_ADDRESS', 'pd_email', 'line', 'return get_option(\'staff_address\');', 'ECOMMERCE', 'ECOMMERCE'); // SecPay: not needed add_config_option('PHONE_NUMBER', 'pd_number', 'line', 'return \'\';', 'ECOMMERCE', 'ECOMMERCE'); // SecPay: not needed add_specific_permission('ECOMMERCE', 'access_ecommerce_in_test_mode', false); $GLOBALS['SITE_DB']->create_table('trans_expecting', array('id' => '*ID_TEXT', 'e_purchase_id' => 'ID_TEXT', 'e_item_name' => 'SHORT_TEXT', 'e_member_id' => 'USER', 'e_amount' => 'SHORT_TEXT', 'e_ip_address' => 'IP', 'e_session_id' => 'INTEGER', 'e_time' => 'TIME', 'e_length' => '?INTEGER', 'e_length_units' => 'ID_TEXT')); require_code('currency'); $cpf = array('currency' => array(3, 'list', implode('|', array_keys(get_currency_map())))); foreach ($cpf as $f => $l) { $GLOBALS['FORUM_DRIVER']->install_create_custom_field($f, $l[0], 1, 0, 1, 0, '', $l[1], 0, $l[2]); } $cpf = array('payment_cardholder_name' => array(100, 'short_text', ''), 'payment_type' => array(26, 'list', 'American Express|Delta|Diners Card|JCB|Master Card|Solo|Switch|Visa'), 'payment_card_number' => array(20, 'integer', ''), 'payment_card_start_date' => array(5, 'short_text', 'mm/yy'), 'payment_card_expiry_date' => array(5, 'short_text', 'mm/yy'), 'payment_card_issue_number' => array(2, 'short_text', ''), 'payment_card_cv2' => array(4, 'short_text', '')); foreach ($cpf as $f => $l) { $GLOBALS['FORUM_DRIVER']->install_create_custom_field($f, $l[0], 1, 0, 1, 0, '', $l[1], 1, $l[2]); } require_lang('ecommerce'); add_menu_item_simple('ecommerce_features', NULL, 'PURCHASING', '_SEARCH:purchase:type=misc'); add_menu_item_simple('ecommerce_features', NULL, 'INVOICES', '_SEARCH:invoices:type=misc'); add_menu_item_simple('ecommerce_features', NULL, 'MODULE_TRANS_NAME_subscriptions', '_SEARCH:subscriptions:type=misc'); } if (is_null($upgrade_from) || $upgrade_from < 3) { add_config_option('CURRENCY', 'currency', 'line', 'return \'GBP\';', 'ECOMMERCE', 'ECOMMERCE'); add_config_option('ECOMMERCE_TEST_MODE', 'ecommerce_test_mode', 'tick', 'return \'0\';', 'ECOMMERCE', 'ECOMMERCE'); add_config_option('IPN_ADDRESS_TEST', 'ipn_test', 'line', 'return get_option(\'staff_address\');', 'ECOMMERCE', 'ECOMMERCE'); add_config_option('IPN_ADDRESS', 'ipn', 'line', 'return get_option(\'staff_address\');', 'ECOMMERCE', 'ECOMMERCE'); } if (is_null($upgrade_from)) { $GLOBALS['SITE_DB']->create_table('transactions', array('id' => '*ID_TEXT', 'purchase_id' => 'ID_TEXT', 'status' => 'SHORT_TEXT', 'reason' => 'SHORT_TEXT', 'amount' => 'SHORT_TEXT', 't_currency' => 'ID_TEXT', 'linked' => 'ID_TEXT', 't_time' => '*TIME', 'item' => 'SHORT_TEXT', 'pending_reason' => 'SHORT_TEXT', 't_memo' => 'LONG_TEXT', 't_via' => 'ID_TEXT')); } }
/** * Standard modular install function. * * @param ?integer What version we're upgrading from (NULL: new install) * @param ?integer What hack version we're upgrading from (NULL: new-install/not-upgrading-from-a-hacked-version) */ function install($upgrade_from = NULL, $upgrade_from_hack = NULL) { if (is_null($upgrade_from) || !$GLOBALS['SITE_DB']->table_exists('shopping_order')) { $GLOBALS['SITE_DB']->create_table('shopping_order', array('id' => '*AUTO', 'c_member' => 'INTEGER', 'session_id' => 'INTEGER', 'add_date' => 'TIME', 'tot_price' => 'REAL', 'order_status' => 'ID_TEXT', 'notes' => 'LONG_TEXT', 'transaction_id' => 'SHORT_TEXT', 'purchase_through' => 'SHORT_TEXT', 'tax_opted_out' => 'BINARY')); $GLOBALS['SITE_DB']->create_index('shopping_order', 'finddispatchable', array('order_status')); $GLOBALS['SITE_DB']->create_index('shopping_order', 'soc_member', array('c_member')); $GLOBALS['SITE_DB']->create_index('shopping_order', 'sosession_id', array('session_id')); $GLOBALS['SITE_DB']->create_index('shopping_order', 'soadd_date', array('add_date')); } else { if (is_null($GLOBALS['SITE_DB']->query('SELECT COUNT(DISTINCT tax_opted_out) FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'shopping_order', NULL, NULL, true))) { $GLOBALS['SITE_DB']->add_table_field('shopping_order', 'tax_opted_out', 'BINARY', 0); } // This was badly versioned } if (is_null($upgrade_from)) { $GLOBALS['SITE_DB']->create_table('shopping_cart', array('id' => '*AUTO', 'session_id' => 'INTEGER', 'ordered_by' => '*USER', 'product_id' => '*AUTO_LINK', 'product_name' => 'SHORT_TEXT', 'product_code' => 'SHORT_TEXT', 'quantity' => 'INTEGER', 'price_pre_tax' => 'REAL', 'price' => 'REAL', 'product_description' => 'LONG_TEXT', 'product_type' => 'SHORT_TEXT', 'product_weight' => 'REAL', 'is_deleted' => 'BINARY')); $GLOBALS['SITE_DB']->create_index('shopping_cart', 'ordered_by', array('ordered_by')); $GLOBALS['SITE_DB']->create_index('shopping_cart', 'session_id', array('session_id')); $GLOBALS['SITE_DB']->create_index('shopping_cart', 'product_id', array('product_id')); $GLOBALS['SITE_DB']->create_table('shopping_order_details', array('id' => '*AUTO', 'order_id' => '?AUTO_LINK', 'p_id' => '?AUTO_LINK', 'p_name' => 'SHORT_TEXT', 'p_code' => 'SHORT_TEXT', 'p_type' => 'SHORT_TEXT', 'p_quantity' => 'INTEGER', 'p_price' => 'REAL', 'included_tax' => 'REAL', 'dispatch_status' => 'SHORT_TEXT')); $GLOBALS['SITE_DB']->create_index('shopping_order_details', 'p_id', array('p_id')); $GLOBALS['SITE_DB']->create_index('shopping_order_details', 'order_id', array('order_id')); $GLOBALS['SITE_DB']->create_table('shopping_logging', array('id' => '*AUTO', 'e_member_id' => '*USER', 'session_id' => 'INTEGER', 'ip' => 'IP', 'last_action' => 'SHORT_TEXT', 'date_and_time' => 'TIME')); $GLOBALS['SITE_DB']->create_table('shopping_order_addresses', array('id' => '*AUTO', 'order_id' => '?AUTO_LINK', 'address_name' => 'SHORT_TEXT', 'address_street' => 'LONG_TEXT', 'address_city' => 'SHORT_TEXT', 'address_zip' => 'SHORT_TEXT', 'address_country' => 'SHORT_TEXT', 'receiver_email' => 'SHORT_TEXT')); $GLOBALS['SITE_DB']->create_index('shopping_order_addresses', 'order_id', array('order_id')); require_lang('shopping'); $GLOBALS['SITE_DB']->create_index('shopping_order', 'recent_shopped', array('add_date')); $GLOBALS['SITE_DB']->create_index('shopping_logging', 'calculate_bandwidth', array('date_and_time')); add_config_option('SHIPPING_COST_FACTOR', 'shipping_cost_factor', 'float', 'return \'0\';', 'ECOMMERCE', 'ECOMMERCE', 1); add_config_option('ALLOW_OPTING_OUT_OF_TAX', 'allow_opting_out_of_tax', 'tick', 'return \'1\';', 'ECOMMERCE', 'ECOMMERCE'); add_menu_item_simple('ecommerce_features', NULL, 'ORDERS', '_SEARCH:shopping:type=my_orders'); //CPFs for ecommerce purchase $GLOBALS['FORUM_DRIVER']->install_create_custom_field('firstname', 20, 1, 0, 0, 0, '', 'short_text'); $GLOBALS['FORUM_DRIVER']->install_create_custom_field('lastname', 20, 1, 0, 0, 0, '', 'short_text'); $GLOBALS['FORUM_DRIVER']->install_create_custom_field('building_name_or_number', 100, 1, 0, 0, 0, '', 'long_text'); $GLOBALS['FORUM_DRIVER']->install_create_custom_field('city', 20, 1, 0, 0, 0, '', 'short_text'); $GLOBALS['FORUM_DRIVER']->install_create_custom_field('state', 100, 1, 0, 0, 0, '', 'short_text'); $GLOBALS['FORUM_DRIVER']->install_create_custom_field('post_code', 20, 1, 0, 0, 0, '', 'short_text'); require_code('currency'); $currencies = get_currency_map(); $_countries = array(); foreach ($currencies as $c) { $_countries = array_merge($_countries, $c); } $_countries = array_unique($_countries); sort($_countries); $countries = '|' . implode('|', $_countries); $GLOBALS['FORUM_DRIVER']->install_create_custom_field('country', 100, 1, 0, 0, 0, '', 'list', 0, $countries); } }
/** * Perform a currency conversion. * * @param mixed The starting amount (integer or float). * @param ID_TEXT The start currency code. * @param ?ID_TEXT The end currency code (NULL: unknown, guess it). * @param boolean Whether to get as a string. * @return ?mixed The new amount as float, or if $string then as a string (NULL: failed to do it). */ function currency_convert($amount, $from_currency, $to_currency = NULL, $string = false) { // Check data $from_currency = strtoupper($from_currency); $map = get_currency_map(); if (!array_key_exists($from_currency, $map)) { return NULL; } if (is_null($to_currency)) { // Perform a preferential guessing sequence // ======================================== // keep_currency $to_currency = get_param('keep_currency', NULL); if (is_null($to_currency)) { // a specially named custom profile field for the currency. $to_currency = get_ocp_cpf('currency'); if ($to_currency === '') { $to_currency = NULL; } if (is_null($to_currency)) { // keep_country $country = get_param('keep_country', NULL); if (!is_null($country)) { $to_currency = country_to_currency($country); } if (is_null($to_currency)) { // a specially named custom profile field for the country. $country = get_ocp_cpf('country'); if ($country != '') { $to_currency = country_to_currency($country); } if (is_null($to_currency)) { // geolocation $to_currency = ip_to_currency(); if (is_null($to_currency)) { // // Euros to the rescue (it's a reasonable guess based on the largest population using a single currency) // $to_currency='EUR'; $to_currency = get_option('currency'); } } } } } } // (We now know $to_currency) // We'll use Google as a simple web service if ($from_currency == $to_currency) { $new_amount = is_integer($amount) ? floatval($amount) : $amount; } else { $cache_key = 'currency_' . $from_currency . '_' . $to_currency . (is_float($amount) ? float_to_raw_string($amount) : strval($amount)); $_new_amount = get_long_value_newer_than($cache_key, time() - 60 * 60 * 24 * 2); $new_amount = is_null($_new_amount) ? NULL : floatval($_new_amount); if (is_null($new_amount)) { $GLOBALS['SITE_DB']->query('DELETE FROM ' . get_table_prefix() . 'long_values WHERE the_name LIKE \'' . db_encode_like('currency_%') . '\' AND date_and_time<' . strval(time() - 60 * 60 * 24 * 2)); // Cleanup $google_url = 'http://www.google.com/finance/converter?a=' . (is_float($amount) ? float_to_raw_string($amount) : strval($amount)) . '&from=' . $from_currency . '&to=' . strtoupper($to_currency); $result = http_download_file($google_url, NULL, false); if (is_string($result)) { $matches = array(); for ($i = 0; $i < strlen($result); $i++) { if (ord($result[$i]) > 127) { $result[$i] = ' '; } } if (preg_match('#<span class=bld>([\\d\\., ]+) [A-Z]+</span>#U', $result, $matches) != 0) { $new_amount = floatval(str_replace(',', '', str_replace(' ', '', $matches[1]))); set_long_value($cache_key, float_to_raw_string($new_amount)); } else { return NULL; } } else { $new_amount = is_integer($amount) ? floatval($amount) : $amount; $to_currency = $from_currency; } } } if ($string) { $ret = ''; if (in_array($to_currency, array('USD', 'AUD', 'CAD', 'SRD', 'SBD', 'SGD', 'NZD', 'NAD', 'MXN', 'LRD', 'GYD', 'FJD', 'SVC', 'XCD', 'COP', 'CLP', 'KYD', 'BND', 'BMD', 'BBD', 'BSD', 'ARS'))) { $ret .= '$'; } elseif (in_array($to_currency, array('GBP', 'SHP', 'LBP', 'JEP', 'GGP', 'GIP', 'FKP', 'EGP'))) { $ret .= '£'; } elseif (in_array($to_currency, array('JPY'))) { $ret .= '¥'; } elseif (in_array($to_currency, array('EUR'))) { $ret .= '€'; } $ret .= escape_html(float_format($new_amount)) . ' ' . escape_html($to_currency); return $ret; } return $new_amount; }