3 Plugin Name: Freeside signup and self-service
4 Plugin URI: http://freeside.biz/freeside
5 Description: Call the Freeside signup and self-service APIs from within Wordpress
7 Author: Freeside Internet Services, Inc.
8 Author URI: https://freeside.biz/freeside/
9 License URI: https://www.gnu.org/licenses/gpl-3.0.html
10 Text Domain: freeside_selfserivce
11 Domain Path: /languages
14 The Freeside signup and self-service plugin is free software: you can
15 redistribute it and/or modify it under the terms of the GNU Lesser General
16 Public License as published by the Free Software Foundation, either version
17 3 of the License, or any later version.
19 The Freeside signup and self-service plugin is distributed in the hope that
20 it will be useful, but WITHOUT ANY WARRANTY; without even the implied
21 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU Lesser General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this plugin. If not, see
26 https://www.gnu.org/licenses/lgpl-3.0.en.html
29 add_action('admin_init', 'freeside_admin_init' );
31 add_action('init', 'freeside_init');
33 function freeside_admin_init() {
34 register_setting( 'general', 'freeside_server', 'freeside.example.com' );
35 add_settings_field( 'freeside_server', 'Freeside server', 'freeside_server_input', 'general' );
38 function freeside_server_input() {
39 $value = get_option('freeside_server');
40 //$value = ($value ? $value : 'freeside.example.com');
42 <INPUT TYPE="text" ID="freeside_server" NAME="freeside_server" VALUE="<?php echo htmlspecialchars($value); ?>">
46 //TODO: remove freeside_server on uninstall
48 function freeside_init() {
49 //error_log("FINALLY action run ". $FREESIDE_PROCESS_LOGIN);
51 //error_log($GLOBALS['$FREESIDE_PROCESS_LOGIN']);
52 if ( ! $GLOBALS['FREESIDE_PROCESS_LOGIN'] ) {
55 $GLOBALS['FREESIDE_PROCESS_LOGIN'] = false;
58 $freeside = new FreesideSelfService();
60 $response = $freeside->login( array(
61 'email' => strtolower($_POST['freeside_email']),
62 'username' => strtolower($_POST['freeside_username']),
63 'domain' => strtolower($_POST['freeside_domain']),
64 'password' => $_POST['freeside_password'],
67 #error_log("[login] received response from freeside: $response");
69 $error = $response['error'];
74 $url = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
75 $url .= $_SERVER['SERVER_NAME'];
76 $url .= $_SERVER['REQUEST_URI'];
78 wp_redirect(dirname($url). '/example_login.php?username='. urlencode($_POST['freeside_username']).
79 '&domain='. urlencode($_POST['freeside_domain']).
80 '&email='. urlencode($_POST['freeside_email']).
81 '&freeside_error='. urlencode($error)
89 $session_id = $response['session_id'];
91 //error_log("[login] logged into freeside with session_id=$freeside_session_id, setting cookie");
93 // now what? for now, always redirect to the main page (or the select a
94 // customer diversion).
95 // eventually, other options?
97 setcookie('freeside_session_id', $session_id);
99 $GLOBALS['FREESIDE_LOGIN_RESPONSE'] = $response;
103 function freeside_flatten($hash) {
104 if ( !is_array($hash) ) return $hash;
107 array_walk($hash, function($value, $key, &$to) {
108 array_push($to, $key, $value);
111 foreach ($hash as $key => $value) {
119 class FreesideSelfService {
121 function FreesideSelfService() {
125 public function __call($name, $arguments) {
127 $URL = 'http://'. get_option('freeside_server'). ':8080';
128 error_log("[FreesideSelfService] $name called, sending to ". $URL);
130 $request = xmlrpc_encode_request("FS.ClientAPI_XMLRPC.$name", freeside_flatten($arguments[0]));
131 $context = stream_context_create( array( 'http' => array(
133 'header' => "Content-Type: text/xml",
134 'content' => $request
136 $file = file_get_contents($URL, false, $context);
137 $response = xmlrpc_decode($file);
138 if (xmlrpc_is_fault($response)) {
139 trigger_error("[FreesideSelfService] XML-RPC communication error: $response[faultString] ($response[faultCode])");
141 //error_log("[FreesideSelfService] $response");