not available"); return t('Converts between currencies using data from !url (needs Soap which is !status)', array('!url' => l('Xurrency', 'http://xurrency.com/api'), '!status' => $status)); } function tribune_xurrency_filter(&$post) { $answer = array( 'info' => variable_get('tribune_xurrency_name', "Xurrency"), ); if (variable_get('tribune_xurrency_authentified', FALSE)) { $answer['login'] = $answer['info']; } if (preg_match(':([0-9]+([,\.][0-9]{2})?) ?([A-Z]{3}) '. t('[ei]n') .' ([A-Z]{3}):', $post['message'], $matches)) { $comma = FALSE; $amount = $matches[1]; if (strpos($amount, ',') !== FALSE) { $comma = TRUE; $amount = str_replace(",", ".", $amount); } $cur1 = $matches[3]; $cur2 = $matches[4]; $response = array('error' => FALSE, 'text' => ""); if (_tribune_xurrency_are_symbols_valid(array($cur1, $cur2))) { $result = _tribune_xurrency_convert($amount, $cur1, $cur2); if ($result) { if ($comma) { $amount = str_replace(".", ",", $amount); $result = str_replace(".", ",", $result); } $answer['message'] = tribune_filters_print_clock($post) ." ". $amount ." ". $cur1 ." = ". $result ." ". $cur2; return array($answer); } } } } function _tribune_xurrency_are_symbols_valid($symbols) { $xurrency = new SoapClient('http://xurrency.com/api.wsdl'); foreach ($symbols as $symbol) { if (!$xurrency->isCurrency(strtolower($symbol))) { return FALSE; } } return TRUE; } function _tribune_xurrency_convert($amount, $from, $to) { $xurrency = new SoapClient('http://xurrency.com/api.wsdl'); return round($xurrency->getValue($amount, strtolower($from), strtolower($to)), 2); } function tribune_xurrency_settings() { $form = array(); $form['tribune_xurrency_name'] = array( '#type' => "textfield", '#title' => t("Display name"), '#default_value' => variable_get('tribune_xurrency_name', "Xurrency"), ); $form['tribune_xurrency_authentified'] = array( '#type' => "checkbox", '#title' => t("Appear to be authentified"), '#default_value' => variable_get('tribune_xurrency_authentified', FALSE), '#description' => t("Whether this filter will appear to be 'anonymous' or 'authentified'. Since the filter does not correspond to a real user, posting as authentified may result in 'nickname collisions'."), ); return system_settings_form($form); }