_publicService)) {
$this->_publicService = new SoapClient(PR_PUBLIC_SERVICE_WSDL);
}
return $this->_publicService;
}
/**
* @return SoapClient An agency provider service soap client
* @TODO Check for exceptions.
*/
public function providerService () {
if (is_null($this->_providerService)) {
$this->_providerService = new SoapClient(PR_PROVIDER_SERVICE_WSDL);
}
return $this->_providerService;
}
/**
* @return SoapClient An activity wholesaler service soap client
* @TODO Check for exceptions.
*/
public function wholesalerService () {
if (is_null($this->_wholesalerService)) {
$this->_wholesalerService = new SoapClient(PR_WHOLESALER_SERVICE_WSDL);
}
return $this->_wholesalerService;
}
/**
* @return SoapVar A ServiceLogin object
*/
public function serviceLogin () {
return array("username" => get_option('pr_username'),
"password" => get_option('pr_password'));
}
/**
* @return PonoRez - Singleton instance
* @see PR()
*/
public static function instance () {
if (is_null(self::$_instance)) {
self::$_instance = new self();
}
return self::$_instance;
}
protected function _transientTag($scName, $id) {
$nonAlnum = array('.', '/', '-', '_', ' ');
return join('_', array('pr',
str_replace($nonAlnum, '', $scName),
str_replace($nonAlnum, '', $id)));
}
/**
* Cache the output of a function as a transient.
*
* @param string $scName The name of the shortcode calling the function.
* @param string $tag A variable tag used to store the transient.
* @param function $f The anonymous function whose output will be cached.
*/
public function withTransient ($scName, $tag, $f) {
$transientTag = $this->_transientTag($scName, $tag);
$timeout = get_option('pr_cache_timeout');
$rval = false;
if (!$timeout && 0 != $timeout) {
$timeout = 3600;
set_option('pr_cache_timeout', $timeout);
}
// When $timeout is 0, the cache is disabled.
if (0 > $timeout) {
$rval = get_transient($transientTag);
}
if (false === $rval) {
// Catch exceptions here.
// @TODO Better error reporting.
try {
$rval = $f();
}
catch (SoapFault $e) {
printf("
\n
\n%s\n", $e->getMessage()); } if (0 != $timeout) { set_transient($transientTag, $rval, $timeout); } } return $rval; } } /** * Returns the main instance of the PonoRez object. * * @return PonoRez */ function PR() { return PonoRez::instance(); } /** * Look at an array of arrays for a value. */ function pr_key_in_array($value, $array) { if (!$array) return false; foreach ($array as $k => $v) { if (in_array($value, $v)) { return $k; } } return false; } /** * Bootstrap function for admin pages. */ function pr_bootstrap_admin () { require_once('lib/class-ponorezadminconfig.php'); require_once('lib/class-ponorezactivitylist.php'); $prc = new PonoRezAdminConfig (); $prc->init(); } add_action('init', 'pr_bootstrap_admin'); /** * Bootstrap function for public pages. */ function pr_bootstrap_public () { // require_once('lib/class-ponorezrest.php'); require_once('lib/class-ponoreztransportation.php'); require_once('lib/class-ponorezgroup.php'); require_once('lib/class-ponoreztemplate.php'); $prt = new PonoRezTemplate (); $prt->init(); } add_action('init', 'pr_bootstrap_public'); /** * Shortcode to test login information. */ function pr_test_login_sc ($atts = array(), $content = null, $tag) { $pr = PR(); $psc = $pr->providerService(); $sl = $pr->serviceLogin(); $result = $psc->testLogin(array('serviceLogin' => $pr->serviceLogin())); if (true == $result->return) { $rval = "Login succeeded.\n"; } else { $rval= "Login failed.\n"; $rval .= sprintf("
\n%s\n", $result->out_status); } return $rval; } add_shortcode('pr_test_login', 'pr_test_login_sc'); // End a3h.php