defaultTemplate));
return sprintf("%s_i%d_%s",
$scName, $id, $templateString);
}
// Execute a SOAP call, but check for cached version in WP transients first.
// $f is a function that should return a string.
protected function _withTransient ($scName, $id, $f) {
$tag = $this->_transientTag($scName, $id);
$timeout = get_option('pr_cache_timeout');
if (!$timeout) {
$timeout = 3600;
set_option('pr_cache_timeout', $timeout);
}
$rval = get_transient($tag);
if (false === $rval) {
$rval = $f();
set_transient($tag, $rval, $timeout);
}
return $rval;
}
public function setCurrentActivity ($activityId) {
$psc = PR()->providerService();
$serviceCreds = PR()->serviceLogin();
$result = $psc->getActivity(array('serviceLogin' => $serviceCreds,
'activityId' => $activityId));
$this->_soapDebug = print_r($result, true);
$this->_currentActivity = $result->return;
}
public function prLoadActivityShortcode ($atts = array(), $content = null, $tag) {
$a = shortcode_atts(array(
'id' => null
), $atts);
$rval = '';
try {
if (0 < (int)$a['id']) {
$this->setCurrentActivity((int)$a['id']);
}
}
catch (SoapFault $e) {
$rval .= sprintf("
\n
\n%s\n
",
$this->_soapDebug);
}
return $rval;
}
public function prActivityShortcode ($atts = array(), $content = null, $tag) {
$a = shortcode_atts(array(
'id' => null,
'template' => $this->defaultTemplate
), $atts);
$rval = '';
try {
if (0 < (int)$a['id']) {
$this->setCurrentActivity((int)$a['id']);
}
}
catch (SoapFault $e) {
$rval .= sprintf("
\n\n%s\n
",
$this->_soapDebug);
}
return $rval . $this->_withTransient('pr_activity', $a['id'], function () use ($a) {
$template_string = file_get_contents($a['template']);
return do_shortcode($template_string);
});
}
public function prActivityNameShortcode ($atts = array(), $content = null, $tag) {
$a = shortcode_atts(array(
'id' => null
), $atts);
return $this->_currentActivity->name;
}
public function prActivityDescriptionShortcode ($atts = array(), $content = null, $tag) {
$a = shortcode_atts(array(
'id' => null
), $atts);
return $this->_currentActivity->description;
}
public function prDatepickerShortcode ($atts = array(), $content = null, $tag) {
$a = shortcode_atts(array(
'id' => null
), $atts);
$rval_template = <<
EOT;
$rval = str_replace('XXXX', $this->_currentActivity->id, $rval_template);
$rval = str_replace('PPPP', plugins_url('assets/images', dirname(__FILE__)), $rval);
return $rval;
}
public function prGuestTypeListShortcode($atts = array(), $content = null, $tag) {
$a = shortcode_atts(array(
'id' => null
), $atts);
try {
$psc = PR()->providerService();
$serviceCreds = PR()->serviceLogin();
$result = $psc->getActivityGuestTypes(array('serviceLogin' => $serviceCreds,
'activityId' => $this->_currentActivity->id,
'supplierId' => $this->_currentActivity->supplierId,
'date' => new SoapVar(date('Y-m-d'), XSD_DATE)));
}
catch (SoapFault $e) {
$rval = sprintf("[SOAP FAULT] Could not load guest types
\n\n%s\n---\n%s\n
\n",
$e->faultcode,
$e->faultstring);
return $rval;
}
// $rest = new PonoRezRest ();
// $result = $rest->getGuestTypes($this->_currentActivity, new DateTime());
// $rval = sprintf("\n%s\n
",
// print_r($result, true));
$rval = '';
foreach ($result->return as $guestType) {
$html = sprintf('%s ";
$rval .= "\n$html\n";
}
$this->_soapDebug = print_r($result, true);
return $rval;
}
// @TODO For this to be done automatically, we might need to configure it in the DB.
public function prGuestTypeShortcode ($atts = array(), $content = null, $tag) {
$a = shortcode_atts(array(
'id' => null,
'guest-type-id' => null,
'max' => 20
), $atts);
$rval = sprintf('\n";
return $rval;
}
public function prHotelSelectShortcode ($atts = array(), $content = null, $tag) {
$a = shortcode_atts(array(
'id' => null
), $atts);
$rval_template = <<
EOT;
$rval = str_replace(array('AAAA', 'SSSS'),
array($this->_currentActivity->id,
$this->_currentActivity->supplierId),
$rval_template);
return $rval;
}
public function prHotelRoomShortcode ($atts = array(), $content = null, $tag) {
$a = shortcode_atts(array(
'id' => null
), $atts);
$rval = sprintf('',
$this->_currentActivity->id);
return $rval;
}
public function prCheckAvailabilityShortcode ($atts = array(), $content = null, $tag) {
$a = shortcode_atts(array(
'id' => null
), $atts);
$defaultStyle = get_option('pr_default_style');
// This might look lazy but Pono Rez is going to give me funny button names every time.
$dsTrimmed = str_replace('-', '', $defaultStyle);
if (!$defaultStyle) {
$rval = sprintf('',
$this->_currentActivity->id);
}
else {
$rval = sprintf('',
$this->_currentActivity->id,
plugins_url('assets/images/buttons', dirname(__FILE__)),
$dsTrimmed);
}
return $rval;
}
public function registerShortcodes() {
add_shortcode('pr_activity', array($this, 'prActivityShortcode'));
add_shortcode('pr_activity_name', array($this, 'prActivityNameShortcode'));
add_shortcode('pr_activity_description', array($this, 'prActivityDescriptionShortcode'));
add_shortcode('pr_datepicker', array($this, 'prDatepickerShortcode'));
add_shortcode('pr_guest_type_list', array($this, 'prGuestTypeListShortcode'));
add_shortcode('pr_guest_type', array($this, 'prGuestTypeShortcode'));
add_shortcode('pr_hotel_select', array($this, 'prHotelSelectShortcode'));
add_shortcode('pr_hotel_room', array($this, 'prHotelRoomShortcode'));
add_shortcode('pr_check_availability', array($this, 'prCheckAvailabilityShortcode'));
add_shortcode('pr_load_activity', array($this, 'prLoadActivityShortcode'));
}
public function loadScripts () {
// Note that the "calendar_js.jsp" file includes jQuery with
// the UI core and datepicker extensions. WordPress provides
// both of those, so we'll use the built-in. That means we
// need our own version of calendar_js.jsp that only includes
// the custom functions. It is included with this plugin.
wp_enqueue_script('pr_accommodation', plugins_url('assets/pr_accommodation.js', dirname(__FILE__)),
array('jquery'));
wp_enqueue_script('pr_calendar', plugins_url('assets/pr_calendar.js', dirname(__FILE__)),
array('jquery', 'jquery-ui-core', 'jquery-ui-datepicker', 'pr_accommodation'));
wp_enqueue_script('pr_functions', plugins_url('assets/pr_functions.js', dirname(__FILE__)),
array('jquery', 'pr_calendar'), null);
wp_enqueue_script('pr_document', plugins_url('assets/pr_document.js', dirname(__FILE__)),
array('jquery', 'pr_functions'));
// Add calendar-specific stylesheets. Note that this can be set by options.
$defaultStyle = get_option('pr_default_style');
if (!$defaultStyle) {
$defaultStyle = 'ui-lightness';
}
$styleUrl = sprintf('%s/%s/jquery-ui.css',
plugins_url('assets/css/themes', dirname(__FILE__)),
$defaultStyle);
wp_enqueue_style('pr_calendar_css', $styleUrl, false, null);
wp_enqueue_style('pr_datepicker_css', plugins_url('assets/css/datepicker_availability.css', dirname(__FILE__)));
}
public function init () {
$this->loadScripts();
$this->registerShortcodes();
$defaultTemplate = get_option('pr_default_template');
if (!$defaultTemplate) {
$defaultTemplate = 'activity-default';
}
$this->defaultTemplate = realpath(dirname(__FILE__) . '/../') . '/templates/' . $defaultTemplate . '.html';
}
}