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: http://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() {
50 if ( $GLOBALS['FREESIDE_PROCESS_LOGOUT'] ) {
51 $GLOBALS['FREESIDE_PROCESS_LOGOUT'] = false;
53 $freeside = new FreesideSelfService();
54 $response = $freeside->logout( array(
55 'session_id' => $_COOKIE['freeside_session_id'],
57 setcookie('freeside_session_id', '', time() - 3600);
58 $error = $response['error'];
60 error_log("Logout error: $error");
65 if ( ! $GLOBALS['FREESIDE_PROCESS_LOGIN'] ) {
68 $GLOBALS['FREESIDE_PROCESS_LOGIN'] = false;
71 $freeside = new FreesideSelfService();
73 $response = $freeside->login( array(
74 'email' => strtolower($_POST['freeside_email']),
75 'username' => strtolower($_POST['freeside_username']),
76 'domain' => strtolower($_POST['freeside_domain']),
77 'password' => $_POST['freeside_password'],
80 #error_log("[login] received response from freeside: $response");
82 $error = $response['error'];
87 $url = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
88 $url .= $_SERVER['SERVER_NAME'];
89 $url .= $_SERVER['REQUEST_URI'];
91 wp_redirect(dirname($url). '/example_login.php?'.
92 'username='. urlencode($_POST['freeside_username']).
93 '&domain='. urlencode($_POST['freeside_domain']).
94 '&email='. urlencode($_POST['freeside_email']).
95 '&freeside_error='. urlencode($error)
103 $session_id = $response['session_id'];
105 //error_log("[login] logged into freeside with session_id=$freeside_session_id, setting cookie");
107 setcookie('freeside_session_id', $session_id);
109 $GLOBALS['FREESIDE_LOGIN_RESPONSE'] = $response;
113 function freeside_flatten($hash) {
114 if ( !is_array($hash) ) return $hash;
117 array_walk($hash, function($value, $key, &$to) {
118 array_push($to, $key, $value);
121 foreach ($hash as $key => $value) {
129 class FreesideSelfService {
131 function FreesideSelfService() {
135 public function __call($name, $arguments) {
137 $URL = 'http://'. get_option('freeside_server'). ':8080';
138 //error_log("[FreesideSelfService] $name called, sending to ". $URL);
140 $request = xmlrpc_encode_request("FS.ClientAPI_XMLRPC.$name", freeside_flatten($arguments[0]));
141 $context = stream_context_create( array( 'http' => array(
143 'header' => "Content-Type: text/xml",
144 'content' => $request
146 $file = file_get_contents($URL, false, $context);
147 $response = xmlrpc_decode($file);
148 if (isset($response) && xmlrpc_is_fault($response)) {
149 trigger_error("[FreesideSelfService] XML-RPC communication error: $response[faultString] ($response[faultCode])");
151 //error_log("[FreesideSelfService] $response");