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'] ) {
53 error_log("DACOOKIE: ". $_COOKIE['freeside_session_id']);
54 $GLOBALS['FREESIDE_SESSION_ID'] = $_COOKIE['freeside_session_id'];
57 $GLOBALS['FREESIDE_PROCESS_LOGIN'] = false;
60 $freeside = new FreesideSelfService();
62 $response = $freeside->login( array(
63 'email' => strtolower($_POST['freeside_email']),
64 'username' => strtolower($_POST['freeside_username']),
65 'domain' => strtolower($_POST['freeside_domain']),
66 'password' => $_POST['freeside_password'],
69 #error_log("[login] received response from freeside: $response");
71 $error = $response['error'];
76 $url = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
77 $url .= $_SERVER['SERVER_NAME'];
78 $url .= $_SERVER['REQUEST_URI'];
80 wp_redirect(dirname($url). '/example_login.php?username='. urlencode($_POST['freeside_username']).
81 '&domain='. urlencode($_POST['freeside_domain']).
82 '&email='. urlencode($_POST['freeside_email']).
83 '&freeside_error='. urlencode($error)
91 $session_id = $response['session_id'];
93 error_log("[login] logged into freeside with session_id=$freeside_session_id, setting cookie");
95 // now what? for now, always redirect to the main page (or the select a
96 // customer diversion).
97 // eventually, other options?
99 setcookie('freeside_session_id', $session_id);
101 $GLOBALS['FREESIDE_LOGIN_RESPONSE'] = $response;
105 function freeside_flatten($hash) {
106 if ( !is_array($hash) ) return $hash;
109 array_walk($hash, function($value, $key, &$to) {
110 array_push($to, $key, $value);
113 foreach ($hash as $key => $value) {
121 class FreesideSelfService {
123 function FreesideSelfService() {
127 public function __call($name, $arguments) {
129 $URL = 'http://'. get_option('freeside_server'). ':8080';
130 error_log("[FreesideSelfService] $name called, sending to ". $URL);
132 $request = xmlrpc_encode_request("FS.ClientAPI_XMLRPC.$name", freeside_flatten($arguments[0]));
133 $context = stream_context_create( array( 'http' => array(
135 'header' => "Content-Type: text/xml",
136 'content' => $request
138 $file = file_get_contents($URL, false, $context);
139 $response = xmlrpc_decode($file);
140 if (xmlrpc_is_fault($response)) {
141 trigger_error("[FreesideSelfService] XML-RPC communication error: $response[faultString] ($response[faultCode])");
143 //error_log("[FreesideSelfService] $response");