This repository has been archived by the owner on Mar 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheckfront.php
91 lines (71 loc) · 3 KB
/
checkfront.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/**
* @package Joomla.Plugin
* @subpackage Content.Checkfront
* @version 3.0
* @copyright Copyright (C) 2008-2014 Checkfront Inc. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* @link https://github.com/Checkfront/Joomla-Plugin
* @link http://www.checkfront.com/joomla
*
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
/**
* Embed a Checkfront booking window into a Joomla page.
*/
class plgContentCheckfront extends JPlugin {
private $path = 'plugins/content/checkfront/';
/**
* @param string $context The context of the content being passed to the plugin.
* @param object $article The article object. Note $article->text is also available
* @param object $params The article params
* @param int $page
* @return bool
*/
public function onContentPrepare($context, &$article, &$params, $page = 0) {
JPlugin::loadLanguage('plg_content_checkfront');
// Don't run this plugin when the content is being indexed
if($context != 'com_content.article' && isset($article->readmore_link)) {
$link = '<a href="' . urlencode($article->readmore_link) . '">' . JText::_('PLG_CONTENT_CHECKFRONT_CONTINUE_BOOKING') . '</a>';
$article->text = preg_replace('/[\[|{]checkfront(.*?)[\]|}]/iU', $link, $article->text);
return true;
}
$article->text = preg_replace_callback('/[\[|{]checkfront(.*?)[\]|}]/iU', array($this, 'renderWidget'), $article->text);
}
protected function renderWidget($shortcode) {
$url = $this->params->get('CF_url');
if(!preg_match('~^http://|https://~', $url)) $url = 'https://' . $url;
$host = parse_url($url, PHP_URL_HOST);
if (!$host) {
return '<p style="padding:1em; border: solid 1px firebrick; font-weight: bold;">Checkfront not configured!</p>';
}
$root_dir = JPATH_SITE . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'content' . DIRECTORY_SEPARATOR . 'checkfront'. DIRECTORY_SEPARATOR;
include_once($root_dir . 'CheckfrontWidget.php');
$Checkfront = new CheckfrontWidget(
array(
'host' => $host,
'pipe_url'=> JURI::base() . $this->path . 'pipe.html',
'provider' => 'joomla',
'load_msg'=> JText::_('PLG_CONTENT_CHECKFRONT_SEARCHING_AVAILABILITY'),
'continue_msg' => JText::_('PLG_CONTENT_CHECKFRONT_CONTINUE_BOOKING'),
)
);
$config = array(
'widget_id' => uniqid()
);
$this->parseShortcode($shortcode[1], $config);
$doc = JFactory::getDocument();
$doc->addScript('//' . $host . '/lib/interface--' . $Checkfront->interface_version . '.js');
return $Checkfront->render($config);
}
protected function parseShortcode($shortcode, &$cnf) {
preg_match_all('/(\w+)\s*=\s*(?|"([^"]*)"|\'([^\']*)\'|([^ ]+))/', $shortcode, $args, PREG_SET_ORDER);
foreach($args as $val) {
$cnf[$val[1]] = $val[2];
}
}
}