PluginProbe ʕ •ᴥ•ʔ
Tracking Code Manager / 1.5
Tracking Code Manager v1.5
trunk 1.11.8 1.11.9 1.12.0 1.12.1 1.12.2 1.12.3 1.4 1.5 2.0.0 2.0.1 2.0.13 2.0.14 2.0.15 2.0.16 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.2.0 2.3.0 2.4.0 2.5.0 2.6.0
tracking-code-manager / includes / admin / editor.php
tracking-code-manager / includes / admin Last commit date
about.php 11 years ago editor.php 11 years ago feedback.php 11 years ago manager.php 11 years ago metabox.php 11 years ago settings.php 11 years ago
editor.php
248 lines
1 <?php
2 function tcm_ui_editor() {
3 global $tcm;
4
5 $tcm->Form->prefix = 'Editor';
6 $id = intval($tcm->Utils->qs('id', 0));
7 $action = $tcm->Utils->qs('action');
8 $snippet = $tcm->Manager->get($id, TRUE);
9 //var_dump($snippet);
10
11 if (wp_verify_nonce($tcm->Utils->qs('tcm_nonce'), 'tcm_nonce')) {
12 //var_dump($_POST);
13 //var_dump($_GET);
14 foreach ($snippet as $k => $v) {
15 $snippet[$k] = $tcm->Utils->qs($k);
16 if (is_string($snippet[$k])) {
17 $snippet[$k] = stripslashes($snippet[$k]);
18 }
19 }
20
21 if ($snippet['name'] == '') {
22 $tcm->Options->pushErrorMessage('Please enter a unique name');
23 } else {
24 $exist=$tcm->Manager->exists($snippet['name']);
25 if ($exist && $exist['id'] != $snippet['id']) {
26 //nonostante il tutto il nome deve essee univoco
27 $tcm->Options->pushErrorMessage('You have entered a name that already exists. IDs are NOT case-sensitive');
28 }
29 }
30 if ($snippet['code'] == '') {
31 $tcm->Options->pushErrorMessage('Paste your HTML Tracking Code into the textarea');
32 }
33
34 if (!$tcm->Options->hasErrorMessages()) {
35 $snippet = $tcm->Manager->put($snippet['id'], $snippet);
36 if ($id <= 0) {
37 $tcm->Options->pushSuccessMessage('Editor.Add', $snippet['id'], $snippet['name']);
38 $snippet = $tcm->Manager->get('', TRUE);
39 } else {
40 $tcm->Utils->redirect(TCM_PAGE_MANAGER.'&id='.$id);
41 exit();
42 }
43 }
44 }
45 $tcm->Options->writeMessages();
46
47 if($tcm->Manager->rc()<=0 && $id<=0) {
48 $tcm->Utils->redirect(TCM_PAGE_MANAGER);
49 exit();
50 }
51 tcm_ui_free_notice();
52
53 ?>
54 <script>
55 jQuery(function(){
56 var tcmPostTypes=[];
57
58 <?php
59 $types=$tcm->Utils->query(TCM_QUERY_POST_TYPES);
60 foreach($types as $v) { ?>
61 tcmPostTypes.push('<?php echo $v['name']?>');
62 <?php } ?>
63
64 //enable/disable some part of except creating coherence
65 function tcmCheckVisible() {
66 var showExceptCategories=true;
67 var showExceptTags=true;
68 var showExceptPostTypes={};
69 jQuery.each(tcmPostTypes, function (i,v) {
70 showExceptPostTypes[v]=true;
71 });
72
73 var $all=jQuery('#includeEverywhereActive');
74 if(!$all.is(':checked')) {
75 showExceptCategories=false;
76 showExceptTags=false;
77
78 jQuery.each(tcmPostTypes, function (i,v) {
79 isCheck=jQuery('#includePostsOfType_'+v+'_Active').is(':checked');
80 selection=jQuery('#includePostsOfType_'+v).select2("val");
81 found=false;
82 for(i=0; i<selection.length; i++) {
83 if(parseInt(selection[i])==-1){
84 found=true;
85 }
86 }
87
88 showExceptPostTypes[v]=false;
89 if(isCheck && found) {
90 showExceptPostTypes[v]=true;
91 if(v!='page') {
92 showExceptCategories=true;
93 showExceptTags=true;
94 }
95 }
96 });
97 }
98
99 //hide/show except post type if all the website is selected
100 //or [All] is selected in a specific post type select
101 var showExcept=false;
102 jQuery.each(showExceptPostTypes, function (k,v) {
103 if(v) {
104 //at least one post type to show except
105 showExcept=true;
106 }
107 tcmShowHide('#exceptPostsOfType_'+k+'Box', v);
108 });
109
110 tcmShowHide('#exceptCategoriesBox', showExceptCategories);
111 tcmShowHide('#exceptTagsBox', showExceptTags);
112
113 showExcept=(showExcept || showExceptTags || showExceptCategories);
114 tcmShowHide('#tcm-except-div', showExcept);
115 }
116 function tcmShowHide(selector, show) {
117 $selector=jQuery(selector);
118 if(show) {
119 $selector.show();
120 } else {
121 $selector.hide();
122 }
123 }
124
125 /*jQuery(".tcmTags").select2({
126 placeholder: "Type here..."
127 , theme: "classic"
128 }).on('change', function() {
129 tcmCheckVisible();
130 });*/
131 jQuery(".tcmLineTags").select2({
132 placeholder: "Type here..."
133 , theme: "classic"
134 , width: '550px'
135 });
136
137 jQuery('.tcm-hideShow').click(function() {
138 tcmCheckVisible();
139 });
140 jQuery('.tcm-hideShow, input[type=checkbox]').change(function() {
141 tcmCheckVisible();
142 });
143 jQuery('.tcmLineTags').on('change', function() {
144 tcmCheckVisible();
145 });
146 tcmCheckVisible();
147 });
148 </script>
149 <?php
150
151 $tcm->Form->formStarts();
152 $tcm->Form->hidden('id', $snippet);
153 $tcm->Form->checkbox('active', $snippet);
154 $tcm->Form->text('name', $snippet);
155 $tcm->Form->textarea('code', $snippet);
156 $values = array(TCM_POSITION_HEAD, TCM_POSITION_BODY, TCM_POSITION_FOOTER);
157 $tcm->Form->select('position', $snippet, $values, FALSE);
158
159 $tcm->Form->p('When do you want to add this code?');
160 $args=array('class'=>'tcm-hideShow tcm-checkbox'
161 , 'tcm-hideIfTrue'=>'true'
162 , 'tcm-hideShow'=>'tcm-include-div');
163 $tcm->Form->checkbox('includeEverywhereActive', $snippet, 1, $args);
164
165 $args=array('id'=>'tcm-include-div', 'name'=>'tcm-include-div', 'style'=>'margin-top:10px;');
166 $tcm->Form->divStarts($args);
167 tcm_formOptions('include', $snippet);
168 $tcm->Form->divEnds();
169
170 $args=array('id'=>'tcm-except-div', 'name'=>'tcm-except-div');
171 $tcm->Form->divStarts($args);
172 $tcm->Form->p('Exclude when?');
173 tcm_formOptions('except', $snippet);
174 $tcm->Form->divEnds();
175
176 $tcm->Form->nonce('tcm_nonce', 'tcm_nonce');
177 tcm_notice_pro_features();
178 $tcm->Form->submit('Save');
179 if($id>0) {
180 $tcm->Form->delete($id);
181 }
182 $tcm->Form->formEnds();
183 }
184
185 function tcm_notice_pro_features() {
186 global $tcm;
187
188 ?>
189 <br/>
190 <div class="message updated below-h2">
191 <div style="height:10px;"></div>
192 <?php
193 $i=1;
194 while($tcm->Lang->H('Notice.ProHeader'.$i)) {
195 $tcm->Lang->P('Notice.ProHeader'.$i);
196 echo '<br/>';
197 ++$i;
198 }
199 $i=1;
200 ?>
201 <br/>
202 <?php
203
204 $options = array('public' => TRUE, '_builtin' => FALSE);
205 $q=get_post_types($options, 'names');
206 if(is_array($q) && count($q)>0) {
207 sort($q);
208 $q=implode(', ', $q);
209 $q='(<b>'.$q.'</b>)';
210 } else {
211 $q='';
212 }
213
214 while($tcm->Lang->H('Notice.ProFeature'.$i)) { ?>
215 <div style="clear:both; margin-top: 2px;"></div>
216 <div style="float:left; vertical-align:middle; height:24px; margin-right:5px;">
217 <img src="<?php echo TCM_PLUGIN_IMAGES?>tick.png" />
218 </div>
219 <div style="float:left; vertical-align:middle; height:24px;">
220 <?php $tcm->Lang->P('Notice.ProFeature'.$i, $q)?>
221 </div>
222 <?php ++$i;
223 }
224 ?>
225 <div style="clear:both;"></div>
226 <div style="height:10px;"></div>
227 </div>
228 <br/>
229 <?php }
230
231 function tcm_formOptions($prefix, $snippet) {
232 global $tcm;
233
234 $types=$tcm->Utils->query(TCM_QUERY_POST_TYPES);
235 foreach($types as $v) {
236 $args = array('post_type' => $v['name'], 'all' => TRUE);
237 $values = $tcm->Utils->query(TCM_QUERY_POSTS_OF_TYPE, $args);
238
239 $keyActive=$prefix.'PostsOfType_'.$v['name'].'_Active';
240 $keyArray=$prefix.'PostsOfType_'.$v['name'];
241 if($snippet[$keyActive]==0 && count($snippet[$keyArray])==0) {
242 //when enabled default selected -1
243 $snippet[$keyArray]=array(-1);
244 }
245 $tcm->Form->checkSelect($keyActive, $keyArray, $snippet, $values);
246 }
247 }
248