function tcm_ui_manager() { global $tcm; if ($tcm->Plugin->isActive(TCM_PLUGINS_TRACKING_CODE_MANAGER_PRO)) { $tcm->Options->pushErrorMessage('YouHaveThePremiumVersion', TCMP_TAB_MANAGER_URI); $tcm->Options->writeMessages(); return; } $id = intval($tcm->Utils->qs('id', 0)); if ($tcm->Utils->is('action', 'delete') && $id > 0 && wp_verify_nonce($tcm->Utils->qs('tcm_nonce'), 'tcm_delete')) { $snippet = $tcm->Manager->get($id); if ($tcm->Manager->remove($id)) { $tcm->Options->pushSuccessMessage('CodeDeleteNotice', $id, $snippet['name']); } } elseif ($id > 0) { $snippet = $tcm->Manager->get($id); if ($tcm->Utils->is('action', 'toggle') && $id > 0 && wp_verify_nonce($tcm->Utils->qs('tcm_nonce'), 'tcm_toggle')) { $snippet['active'] = $snippet['active'] == 0 ? 1 : 0; $tcm->Manager->put($snippet['id'], $snippet); } $tcm->Options->pushSuccessMessage('CodeUpdateNotice', $id, $snippet['name']); } $tcm->Options->writeMessages(); tcm_ui_free_notice(); //controllo che faccio per essere retrocompatibile con la prima versione //dove non avevo un id e salvavo tutto con il con il nome quindi una stringa $snippets = $tcm->Manager->keys(); foreach ($snippets as $v) { $snippet = $tcm->Manager->get($v, FALSE, TRUE); if (!$snippet) { $tcm->Manager->remove($v); } elseif (!is_numeric($v)) { $tcm->Manager->remove($v); $tcm->Manager->put('', $snippet); } } $snippets = $tcm->Manager->values(); if (count($snippets) > 0) { ?> <div style="float:left;"> <form method="get" style="margin:5px; float:left;" action="<?php echo TCM_PAGE_PREMIUM; ?> "> <input type="hidden" name="utm_source" value="free-users" /> <input type="hidden" name="utm_medium" value="tcm-manager" /> <input type="hidden" name="utm_campaign" value="TCM" /> <input type="submit" class="button" value="<?php $tcm->Lang->P('Button.BuyPRO'); ?> " /> </form> <form method="get" action="" style="margin:5px; float:left;"> <input type="hidden" name="page" value="<?php echo TCM_PLUGIN_SLUG; ?> " /> <input type="hidden" name="tab" value="<?php echo TCM_TAB_EDITOR; ?> " /> <input type="submit" class="button-primary" value="<?php $tcm->Lang->P('Button.Add'); ?> " /> </form> </div> <div style="clear:both;"></div> <style> .widefat th { font-weight: bold!important; } </style> <table class="widefat fixed" style="width:auto;"> <thead> <tr> <th>#N</th> <th><?php $tcm->Lang->P('Name'); ?> </th> <th><?php $tcm->Lang->P('Position'); ?> </th> <th style="text-align:center;"><?php $tcm->Lang->P('Active?'); ?> </th> <th><?php $tcm->Lang->P('Where?'); ?> </th> <th style="text-align:center;"><?php $tcm->Lang->P('Each pages?'); ?> </th> <?php /*<th style="text-align:center;"><?php $tcm->Lang->P('Count')?></th> */ ?> <th style="text-align:center;"><?php $tcm->Lang->P('Actions'); ?> </th> </tr> </thead> <tbody> <?php $i = 1; foreach ($snippets as $snippet) { ?> <tr> <td>#<?php echo $i++; ?> </td> <td><?php echo $snippet['name']; ?> </td> <td><?php $tcm->Lang->P('Editor.position.' . $snippet['position']); ?> </td> <td style="text-align:center;"> <?php $color = 'red'; $text = 'No'; $question = 'QuestionActiveOn'; if ($snippet['active'] == 1) { $color = 'green'; $text = 'Yes'; $question = 'QuestionActiveOff'; } $text = '<span style="font-weight:bold; color:' . $color . '">' . $tcm->Lang->L($text) . '</span>'; ?> <a onclick="return confirm('<?php echo $tcm->Lang->L($question); ?> ');" href="<?php echo TCM_TAB_MANAGER_URI; ?> &tcm_nonce=<?php echo esc_attr(wp_create_nonce('tcm_toggle')); ?> &action=toggle&id=<?php echo $snippet['id']; ?> "> <?php echo $text; ?> </a> </td> <td> <?php $text = 'Standard'; if ($snippet['trackMode'] != TCM_TRACK_MODE_CODE) { $text = $tcm->Plugin->getName($snippet['trackMode']); } $tcm->Lang->P($text); ?> </td> <?php $hide = !$snippet['active']; $active = $snippet['trackMode'] == TCM_TRACK_MODE_CODE && $snippet['trackPage'] == TCM_TRACK_PAGE_ALL; tcm_ui_manager_column($active, NULL, $hide); ?> <?php /*<td style="text-align:center;"><?php echo $snippet['codesCount']?></td> */ ?> <td style="text-align:center;"> <a href="<?php echo TCM_TAB_EDITOR_URI; ?> &id=<?php echo $snippet['id']; ?> "> <?php echo $tcm->Lang->L('Edit'); ?> </a> | <span class="trash"> <a onclick="return confirm('<?php echo $tcm->Lang->L('Question.DeleteQuestion'); ?> ');" href="<?php echo TCM_TAB_MANAGER_URI; ?> &tcm_nonce=<?php echo esc_attr(wp_create_nonce('tcm_delete')); ?> &action=delete&id=<?php echo $snippet['id']; ?> "> <?php echo $tcm->Lang->L('Delete'); ?> </a> </span> </td> </tr> <?php } ?> </tbody> </table> <?php } else { ?> <h2><?php $tcm->Lang->P('EmptyTrackingList', TCM_TAB_EDITOR_URI); ?> </h2> <?php } tcm_notice_pro_features(); }
function tcm_ui_editor() { global $tcm; $tcm->Form->prefix = 'Editor'; $id = intval($tcm->Utils->qs('id', 0)); $action = $tcm->Utils->qs('action'); $snippet = $tcm->Manager->get($id, TRUE); //var_dump($snippet); if (wp_verify_nonce($tcm->Utils->qs('tcm_nonce'), 'tcm_nonce')) { //var_dump($_POST); //var_dump($_GET); foreach ($snippet as $k => $v) { $snippet[$k] = $tcm->Utils->qs($k); if (is_string($snippet[$k])) { $snippet[$k] = stripslashes($snippet[$k]); } } tcm_ui_editor_check($snippet); if (!$tcm->Options->hasErrorMessages()) { $snippet = $tcm->Manager->put($snippet['id'], $snippet); /*if ($id <= 0) { $tcm->Options->pushSuccessMessage('Editor.Add', $snippet['id'], $snippet['name']); $snippet = $tcm->Manager->get('', TRUE); } else { $tcm->Utils->redirect(TCM_PAGE_MANAGER.'&id='.$id); exit(); }*/ $id = $snippet['id']; $tcm->Utils->redirect(TCM_PAGE_MANAGER . '&id=' . $id); } } if (!$tcm->Options->writeMessages()) { tcm_ui_free_notice(); } if ($tcm->Manager->rc() <= 0 && $id <= 0) { $tcm->Utils->redirect(TCM_PAGE_MANAGER); exit; } ?> <script> jQuery(function(){ var tcmPostTypes=[]; <?php $types = $tcm->Utils->query(TCM_QUERY_POST_TYPES); foreach ($types as $v) { ?> tcmPostTypes.push('<?php echo $v['name']; ?> '); <?php } ?> //enable/disable some part of except creating coherence function tcmCheckVisible() { var showExceptCategories=true; var showExceptTags=true; var showExceptPostTypes={}; jQuery.each(tcmPostTypes, function (i,v) { showExceptPostTypes[v]=true; }); var $mode=jQuery('[name=trackMode]:checked'); var showTrackCode=false; var showTrackConversion=false; if($mode.length>0) { if(parseInt($mode.val())!=<?php echo TCM_TRACK_MODE_CODE; ?> ) { showTrackConversion=true; jQuery('[name=position]').val(<?php echo TCM_POSITION_FOOTER; ?> ); jQuery('[name=position]').prop('disabled', true); tcmShowHide('.box-track-conversion', false); tcmShowHide('#box-track-conversion-'+$mode.val(), true); } else { showTrackCode=true; jQuery('[name=position]').prop('disabled', false); } } tcmShowHide('#box-track-conversion', showTrackConversion); tcmShowHide('#box-track-code', showTrackCode); var $all=jQuery('[name=trackPage]:checked'); if($all.length>0 && parseInt($all.val())==<?php echo TCM_TRACK_PAGE_SPECIFIC; ?> ) { showExceptCategories=false; showExceptTags=false; jQuery.each(tcmPostTypes, function (i,v) { isCheck=jQuery('#includePostsOfType_'+v+'_Active').is(':checked'); selection=jQuery('#includePostsOfType_'+v).select2("val"); found=false; for(i=0; i<selection.length; i++) { if(parseInt(selection[i])==-1){ found=true; } } showExceptPostTypes[v]=false; if(isCheck && found) { showExceptPostTypes[v]=true; if(v!='page') { showExceptCategories=true; showExceptTags=true; } } }); } //hide/show except post type if all the website is selected //or [All] is selected in a specific post type select var showExcept=false; jQuery.each(showExceptPostTypes, function (k,v) { if(v) { //at least one post type to show except showExcept=true; } tcmShowHide('#exceptPostsOfType_'+k+'Box', v); }); //tcmShowHide('#exceptCategoriesBox', showExceptCategories); //tcmShowHide('#exceptTagsBox', showExceptTags); showInclude=false; if($all.length==0) { showExcept=false; } else { showExcept=(showExcept || showExceptTags || showExceptCategories); if(parseInt($all.val())==<?php echo TCM_TRACK_PAGE_ALL; ?> ) { showExcept=true; } else { showInclude=true; } } tcmShowHide('#tcm-except-div', showExcept); tcmShowHide('#tcm-include-div', showInclude); } function tcmShowHide(selector, show) { $selector=jQuery(selector); if(show) { $selector.show(); } else { $selector.hide(); } } /*jQuery(".tcmTags").select2({ placeholder: "Type here..." , theme: "classic" }).on('change', function() { tcmCheckVisible(); });*/ jQuery(".tcmLineTags").select2({ placeholder: "Type here..." , theme: "classic" , width: '550px' }); jQuery('.tcm-hideShow').click(function() { tcmCheckVisible(); }); jQuery('.tcm-hideShow, input[type=checkbox], input[type=radio]').change(function() { tcmCheckVisible(); }); jQuery('.tcmLineTags').on('change', function() { tcmCheckVisible(); }); tcmCheckVisible(); }); </script> <?php $tcm->Form->formStarts(); $tcm->Form->hidden('id', $snippet); $tcm->Form->checkbox('active', $snippet); $tcm->Form->text('name', $snippet); $tcm->Form->textarea('code', $snippet); $values = array(TCM_POSITION_HEAD, TCM_POSITION_BODY, TCM_POSITION_FOOTER); $tcm->Form->select('position', $snippet, $values, FALSE); $args = array('id' => 'box-track-mode'); $tcm->Form->divStarts($args); $tcm->Form->p('Where do you want to add this code?'); $tcm->Form->radio('trackMode', $snippet['trackMode'], TCM_TRACK_MODE_CODE); $plugins = $tcm->Ecommerce->getActivePlugins(); if (count($plugins) == 0) { $plugins = array('Ecommerce' => array('name' => 'Ecommerce', 'id' => TCM_PLUGINS_NO_PLUGINS, 'version' => '')); } $tcm->Form->tagNew = TRUE; foreach ($plugins as $k => $v) { $ecommerce = $v['name']; if (isset($v['version']) && $v['version'] != '') { $ecommerce .= ' (v.' . $v['version'] . ')'; } $args = array('label' => $tcm->Lang->L('Editor.trackMode_1', $ecommerce)); $tcm->Form->radio('trackMode', $snippet['trackMode'], $v['id'], $args); } $tcm->Form->tagNew = FALSE; $tcm->Form->divEnds(); $args = array('id' => 'box-track-conversion'); $tcm->Form->divStarts($args); $tcm->Form->p('In which products do you want to insert this code?'); ?> <p style="font-style: italic;"><?php $tcm->Lang->P('Editor.PositionBlocked'); ?> </p> <?php foreach ($plugins as $k => $v) { $args = array('id' => 'box-track-conversion-' . $v['id'], 'class' => 'box-track-conversion'); $tcm->Form->divStarts($args); if ($v['id'] == TCM_PLUGINS_NO_PLUGINS) { $plugins = $tcm->Ecommerce->getPlugins(FALSE); $ecommerce = ''; foreach ($plugins as $k => $v) { if ($ecommerce != '') { $ecommerce .= ', '; } $ecommerce .= $k; } $tcm->Options->pushErrorMessage('Editor.NoEcommerceFound', $ecommerce); $tcm->Options->writeMessages(); } else { $postType = $tcm->Ecommerce->getCustomPostType($v['id']); $keyActive = 'CTC_' . $v['id'] . '_Active'; $label = $tcm->Lang->L('Editor.EcommerceCheck', $v['name'], $v['version']); if ($postType != '') { $args = array('post_type' => $postType, 'all' => TRUE); $values = $tcm->Utils->query(TCM_QUERY_POSTS_OF_TYPE, $args); $keyArray = 'CTC_' . $v['id'] . '_ProductsIds'; if (count($snippet[$keyArray]) == 0) { //when enabled default selected -1 $snippet[$keyArray] = array(-1); } $args = array('label' => $label, 'class' => 'tcm-select tcmLineTags'); $tcm->Form->labels = FALSE; $tcm->Form->select($keyArray, $snippet[$keyArray], $values, TRUE, $args); $tcm->Form->labels = TRUE; } else { $args = array('label' => $label); $tcm->Form->checkbox($keyActive, $snippet[$keyActive], 1, $args); } } $tcm->Form->divEnds(); } $tcm->Form->divEnds(); $args = array('id' => 'box-track-code'); $tcm->Form->divStarts($args); $tcm->Form->p('In which page do you want to insert this code?'); $tcm->Form->radio('trackPage', $snippet['trackPage'], TCM_TRACK_PAGE_ALL); $tcm->Form->radio('trackPage', $snippet['trackPage'], TCM_TRACK_PAGE_SPECIFIC); //, 'style'=>'margin-top:10px;' $args = array('id' => 'tcm-include-div'); $tcm->Form->divStarts($args); $tcm->Form->p('Include tracking code in which pages?'); tcm_formOptions('include', $snippet); $tcm->Form->divEnds(); $args = array('id' => 'tcm-except-div'); $tcm->Form->divStarts($args); $tcm->Form->p('Do you want to exclude some specific pages?'); tcm_formOptions('except', $snippet); $tcm->Form->divEnds(); $tcm->Form->divEnds(); $tcm->Form->nonce('tcm_nonce', 'tcm_nonce'); tcm_notice_pro_features(); $tcm->Form->submit('Save'); if ($id > 0) { $tcm->Form->delete($id); } $tcm->Form->formEnds(); }