creativecontactform.php
5.63 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
/**
* Joomla! component creativecontactform
*
* @version $Id: default.php 2012-04-05 14:30:25 svn $
* @author Creative-Solutions.net
* @package Creative Image Slider
* @subpackage com_creativecontactform
* @license GNU/GPL
*
*/
defined('_JEXEC') or die('Restricted access');
// Import library dependencies
jimport('joomla.plugin.plugin');
jimport('joomla.event.plugin');
class plgSystemCreativecontactform extends JPlugin {
function __construct( &$subject ) {
parent::__construct( $subject );
// load plugin parameters and language file
$this->_plugin = JPluginHelper::getPlugin( 'system', 'creativecontactform' );
$this->_params = json_decode( $this->_plugin->params );
JPlugin::loadLanguage('plg_system_creativecontactform', JPATH_ADMINISTRATOR);
}
function ccf_make_form($m) {
$form_id = (int) $m[2];
//include helper class
require_once JPATH_SITE.'/components/com_creativecontactform/helpers/helper.php';
$ccf_class = new CreativecontactformHelper;
$ccf_class->form_id = $form_id;
$ccf_class->type = 'plugin';
$ccf_class->class_suffix = 'ccf_plg';
$ccf_class->module_id = $this->plg_order;
$this->plg_order ++;
return $ccf_class->render_html();
}
function render_styles_scripts() {
$document = JFactory::getDocument();
$content = JResponse::getBody();
$db = JFactory::getDBO();
$version = '3.2.0';
$scripts = '';
//check if component or module loaded CCF scripts already, if no, load them
if (strpos($content,'components/com_creativecontactform/assets/css/main.css') === false) {
$cssFile = JURI::base(true).'/components/com_creativecontactform/assets/css/main.css?version='.$version;
$scripts .= '<link rel="stylesheet" href="'.$cssFile.'" type="text/css" />'."\n";
$cssFile = JURI::base(true).'/components/com_creativecontactform/assets/css/template.css?version='.$version;
$scripts .= '<link rel="stylesheet" href="'.$cssFile.'" type="text/css" />'."\n";
$cssFile = JURI::base(true).'/components/com_creativecontactform/assets/css/creativecss-ui.css';
$scripts .= '<link rel="stylesheet" href="'.$cssFile.'" type="text/css" />'."\n";
$cssFile = JURI::base(true).'/components/com_creativecontactform/assets/css/creative-scroll.css';
$scripts .= '<link rel="stylesheet" href="'.$cssFile.'" type="text/css" />'."\n";
$jsFile = JURI::base(true).'/components/com_creativecontactform/assets/js/creativelib.js';
$scripts .= '<script src="'.$jsFile.'" type="text/javascript"></script>'."\n";
$jsFile = JURI::base(true).'/components/com_creativecontactform/assets/js/creativelib-ui.js';
$scripts .= '<script src="'.$jsFile.'" type="text/javascript"></script>'."\n";
$jsFile = JURI::base(true).'/components/com_creativecontactform/assets/js/creative-mousewheel.js';
$scripts .= '<script src="'.$jsFile.'" type="text/javascript"></script>'."\n";
$jsFile = JURI::base(true).'/components/com_creativecontactform/assets/js/creative-scroll.js';
$scripts .= '<script src="'.$jsFile.'" type="text/javascript"></script>'."\n";
$jsFile = JURI::base(true).'/components/com_creativecontactform/assets/js/creativecontactform.js?version='.$version;
$scripts .= '<script src="'.$jsFile.'" type="text/javascript"></script>'."\n";
}
$content = str_replace('</head>', $scripts . '</head>', $content);
return $content;
}
function ccf_get_types_array($form_id) {
$db = JFactory::getDBO();
//get field types array/////////////////////////////////////////////////////////////////////////////////////////////////
$query = "
SELECT
sp.id,
st.name as type
FROM
`#__creative_fields` sp
JOIN `#__creative_field_types` st ON st.id = sp.id_type
WHERE sp.published = '1'
AND sp.id_form = '".$form_id."'
ORDER BY sp.ordering,sp.id
";
$db->setQuery($query);
$types_array_data = $db->loadAssocList();
$types_array_index = 1;
$types_array = array();
if(is_array($types_array_data)) {
foreach($types_array_data as $type) {
$types_array[$types_array_index] = strtolower(str_replace(' ','-',str_replace('-','',$type['type'])));
$types_array_index ++;
}
}
return $types_array;
}
function onAfterRender() {
$mainframe = JFactory::getApplication();
if($mainframe->isAdmin())
return;
$plugin = JPluginHelper::getPlugin('system', 'creativecontactform');
$pluginParams = json_decode( $plugin->params );
$content = JResponse::getBody();
//If shortcode found, then add scripts
if(preg_match('/(\[creativecontactform id="([0-9]+)"\])/s',$content))
$content = $this->render_styles_scripts();
// if there is no shortcode, and module or component does not load CCF as well, then return
if(!preg_match('/(\[creativecontactform id="([0-9]+)"\])/s',$content))
return;
//if shortcode found, render form
if(preg_match('/(\[creativecontactform id="([0-9]+)"\])/s',$content)) {
$this->plg_order = 10000;
//plugin
$content = preg_replace_callback('/(\[creativecontactform id="([0-9]+)"\])/s',array($this, 'ccf_make_form'),$content);
}
JResponse::setBody($content);
}
}