| @@ -1,117 +1,202 @@ | ||
| 1 | -<?php | |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; | |
| 3 | -function tcmp_ui_manager() { | |
| 4 | - global $tcmp; | |
| 5 | - | |
| 6 | - $id = tcmp_isqs( 'id', 0 ); | |
| 7 | - if ( tcmp_sqs( 'action' ) === 'delete' && $id > 0 && wp_verify_nonce( tcmp_qs( 'tcmp_nonce' ), 'tcmp_delete' ) ) { | |
| 8 | - $snippet = $tcmp->manager->get( $id ); | |
| 9 | - if ( $tcmp->manager->remove( $id ) ) { | |
| 10 | - $tcmp->options->pushSuccessMessage( 'CodeDeleteNotice', $id, esc_html( $snippet['name'] ) ); | |
| 11 | - } | |
| 12 | - } elseif ( '' != $id && 0 != $id ) { | |
| 13 | - $snippet = $tcmp->manager->get( $id ); | |
| 14 | - if ( $tcmp->utils->is( 'action', 'toggle' ) && $id > 0 && wp_verify_nonce( tcmp_qs( 'tcmp_nonce' ), 'tcmp_toggle' ) ) { | |
| 15 | - $snippet['active'] = ( 0 === $snippet['active'] ? 1 : 0 ); | |
| 16 | - $tcmp->manager->put( $snippet['id'], $snippet ); | |
| 17 | - } | |
| 18 | - $tcmp->options->pushSuccessMessage( 'CodeUpdateNotice', $id, esc_html( $snippet['name'] ) ); | |
| 19 | - } | |
| 20 | - | |
| 21 | - $tcmp->manager->is_limit_reached( true ); | |
| 22 | - $tcmp->options->writeMessages(); | |
| 23 | - | |
| 24 | - //controllo che faccio per essere retrocompatibile con la prima versione | |
| 25 | - //dove non avevo un id e salvavo tutto con il con il nome quindi una stringa | |
| 26 | - $snippets = $tcmp->manager->keys(); | |
| 27 | - foreach ( $snippets as $v ) { | |
| 28 | - $snippet = $tcmp->manager->get( $v, false, true ); | |
| 29 | - if ( ! $snippet ) { | |
| 30 | - $tcmp->manager->remove( $v ); | |
| 31 | - } elseif ( ! is_numeric( $v ) ) { | |
| 32 | - $tcmp->manager->remove( $v ); | |
| 33 | - $tcmp->manager->put( '', $snippet ); | |
| 34 | - } | |
| 35 | - } | |
| 36 | - $snippets = $tcmp->manager->values(); | |
| 37 | - if ( count( $snippets ) > 0 ) { ?> | |
| 38 | - <div style="float:left;"> | |
| 39 | - <form method="get" action="" style="margin:5px; float:left;"> | |
| 40 | - <input type="hidden" name="page" value="<?php echo esc_attr( TCMP_PLUGIN_SLUG ); ?>" /> | |
| 41 | - <input type="hidden" name="tab" value="<?php echo esc_attr( TCMP_TAB_EDITOR ); ?>" /> | |
| 42 | - <input type="submit" class="button-primary" value="<?php $tcmp->lang->P( 'Button.Add' ); ?>" /> | |
| 43 | - </form> | |
| 44 | - </div> | |
| 45 | - <div style="clear:both;"></div> | |
| 46 | - | |
| 47 | - <table class="widefat fixed" style="width:100%" id="tblSortable"> | |
| 48 | - <thead> | |
| 49 | - <tr> | |
| 50 | - <th style="width:30px;">#N</th> | |
| 51 | - <th style="width:50px; text-align:center;"><?php $tcmp->lang->P( 'Active?' ); ?></th> | |
| 52 | - <th><?php $tcmp->lang->P( 'Name' ); ?></th> | |
| 53 | - <th><?php $tcmp->lang->P( 'Where?' ); ?></th> | |
| 54 | - <th style="text-align:center;"><?php $tcmp->lang->P( 'Shortcode' ); ?></th> | |
| 55 | - <th style="text-align:center;"><?php $tcmp->lang->P( 'Actions' ); ?></th> | |
| 56 | - </tr> | |
| 57 | - </thead> | |
| 58 | - <tbody class="table-body"> | |
| 59 | - <?php | |
| 60 | - $i = 1; | |
| 61 | - foreach ( $snippets as $snippet ) { | |
| 62 | - global $tcmp_allowed_html_tags; | |
| 63 | - $bClass = ( ( $i % 2 ) === 1 ? 'odd' : 'even' ); | |
| 64 | - ?> | |
| 65 | - <tr class="<?php echo esc_attr( $bClass ); ?>" id="row_<?php echo esc_attr( $snippet['id'] ); ?>"> | |
| 66 | - <td>#<?php echo esc_html( $i++ ); ?></td> | |
| 67 | - <td style="text-align:center;"> | |
| 68 | - <?php | |
| 69 | - $color = 'red'; | |
| 70 | - $text = 'No'; | |
| 71 | - $question = 'QuestionActiveOn'; | |
| 72 | - if ( 1 == $snippet['active'] ) { | |
| 73 | - $color = 'green'; | |
| 74 | - $text = 'Yes'; | |
| 75 | - $question = 'QuestionActiveOff'; | |
| 76 | - } | |
| 77 | - $text = '<span style="font-weight:bold; color:' . $color . '">' . $tcmp->lang->L( $text ) . '</span>'; | |
| 78 | - $toggle_url = TCMP_TAB_MANAGER_URI . '&tcmp_nonce=' . wp_create_nonce( 'tcmp_toggle' ) . '&action=toggle&id=' . $snippet['id']; | |
| 79 | - ?> | |
| 80 | - <a onclick="return confirm('<?php echo esc_js( $tcmp->lang->L( $question ) ); ?>');" href="<?php echo esc_url( $toggle_url ); ?>"> | |
| 81 | - <?php echo wp_kses( $text, $tcmp_allowed_html_tags ); ?> | |
| 82 | - </a> | |
| 83 | - </td> | |
| 84 | - <td><?php echo esc_html( $snippet['name'] ); ?></td> | |
| 85 | - <td> | |
| 86 | - <?php | |
| 87 | - if ( $tcmp->manager->is_mode_script( $snippet ) ) { | |
| 88 | - if ( $tcmp->manager->is_page_everywhere( $snippet ) ) { | |
| 89 | - $text = 'Everywhere'; | |
| 90 | - } else { | |
| 91 | - $text = 'Specific Pages'; | |
| 92 | - } | |
| 93 | - } else { | |
| 94 | - $text = 'Conversion'; | |
| 95 | - } | |
| 96 | - $tcmp->lang->P( $text ); | |
| 97 | - ?> | |
| 98 | - </td> | |
| 99 | - <td style="text-align:center;"> | |
| 100 | - <input type="text" style="width:110px; text-align:center;" value='[tcm id="<?php echo esc_html( $snippet['id'] ); ?>"]' readonly="readonly" class="tcmp-select-onfocus" /> | |
| 101 | - </td> | |
| 102 | - <td style="text-align:center;"> | |
| 103 | - <input type="button" class="button button-secondary" value="<?php $tcmp->lang->P( 'Edit' ); ?>" onclick="location.href='<?php echo esc_url( TCMP_TAB_EDITOR_URI . '&id=' . $snippet['id'] ); ?>';"/> | |
| 104 | - <input type="button" class="button button-secondary" value="<?php $tcmp->lang->P( 'Delete?' ); ?>" onclick="TCMP_btnDeleteClick(<?php echo esc_attr( $snippet['id'] ); ?>)"/> | |
| 105 | - </td> | |
| 106 | - </tr> | |
| 107 | - <?php } ?> | |
| 108 | - </tbody> | |
| 109 | - </table> | |
| 110 | - <?php | |
| 111 | - tcmp_notice_pro_features(); | |
| 112 | - } else { | |
| 113 | - ?> | |
| 114 | - <h2><?php $tcmp->lang->P( 'EmptyTrackingList', TCMP_TAB_EDITOR_URI ); ?></h2> | |
| 115 | - <?php | |
| 116 | - } | |
| 117 | -} | |
| 1 | +<?php | |
| 2 | +//column renderer | |
| 3 | +function tcmp_ui_manager_column($active, $values=NULL, $hide=FALSE) { | |
| 4 | + global $tcmp; | |
| 5 | + ?> | |
| 6 | + <td style="text-align:center;"> | |
| 7 | + <?php | |
| 8 | + if($hide) { | |
| 9 | + $text='-'; | |
| 10 | + } else { | |
| 11 | + if($active) { | |
| 12 | + $text='<span style="font-weight:bold; color:green">'.$tcmp->Lang->L('Yes').'</span>'; | |
| 13 | + } else { | |
| 14 | + $text='<span style="font-weight:bold; color:red">'.$tcmp->Lang->L('No').'</span>'; | |
| 15 | + } | |
| 16 | + if($active && $values) { | |
| 17 | + if(!is_array($values)) { | |
| 18 | + $text.=' {'.$values.'}'; | |
| 19 | + } elseif(count($values)>0) { | |
| 20 | + $what=implode(',', $values); | |
| 21 | + if($what!='') { | |
| 22 | + $text.=' ['.$what.']'; | |
| 23 | + } | |
| 24 | + } | |
| 25 | + } | |
| 26 | + } | |
| 27 | + echo $text; | |
| 28 | + ?> | |
| 29 | + </td> | |
| 30 | +<?php | |
| 31 | +} | |
| 32 | + | |
| 33 | +function tcmp_ui_manager() { | |
| 34 | + global $tcmp; | |
| 35 | + | |
| 36 | + $id=TCMP_ISQS('id', 0); | |
| 37 | + if (TCMP_SQS('action')=='delete' && $id>0 && wp_verify_nonce(TCMP_QS('tcmp_nonce'), 'tcmp_delete')) { | |
| 38 | + $snippet=$tcmp->Manager->get($id); | |
| 39 | + if ($tcmp->Manager->remove($id)) { | |
| 40 | + $tcmp->Options->pushSuccessMessage('CodeDeleteNotice', $id, $snippet['name']); | |
| 41 | + } | |
| 42 | + } else if($id!='') { | |
| 43 | + $snippet=$tcmp->Manager->get($id); | |
| 44 | + if($tcmp->Utils->is('action', 'toggle') && $id>0 && wp_verify_nonce(TCMP_QS('tcmp_nonce'), 'tcmp_toggle')) { | |
| 45 | + $snippet['active']=($snippet['active']==0 ? 1 : 0); | |
| 46 | + $tcmp->Manager->put($snippet['id'], $snippet); | |
| 47 | + } | |
| 48 | + $tcmp->Options->pushSuccessMessage('CodeUpdateNotice', $id, $snippet['name']); | |
| 49 | + } | |
| 50 | + | |
| 51 | + $tcmp->Manager->isLimitReached(TRUE); | |
| 52 | + $tcmp->Options->writeMessages(); | |
| 53 | + | |
| 54 | + //controllo che faccio per essere retrocompatibile con la prima versione | |
| 55 | + //dove non avevo un id e salvavo tutto con il con il nome quindi una stringa | |
| 56 | + $snippets=$tcmp->Manager->keys(); | |
| 57 | + foreach($snippets as $v) { | |
| 58 | + $snippet=$tcmp->Manager->get($v, FALSE, TRUE); | |
| 59 | + if(!$snippet) { | |
| 60 | + $tcmp->Manager->remove($v); | |
| 61 | + } elseif(!is_numeric($v)) { | |
| 62 | + $tcmp->Manager->remove($v); | |
| 63 | + $tcmp->Manager->put('', $snippet); | |
| 64 | + } | |
| 65 | + } | |
| 66 | + $snippets=$tcmp->Manager->values(); | |
| 67 | + if (count($snippets)>0) { ?> | |
| 68 | + <div style="float:left;"> | |
| 69 | + <form method="get" action="" style="margin:5px; float:left;"> | |
| 70 | + <input type="hidden" name="page" value="<?php echo TCMP_PLUGIN_SLUG?>" /> | |
| 71 | + <input type="hidden" name="tab" value="<?php echo TCMP_TAB_EDITOR?>" /> | |
| 72 | + <input type="submit" class="button-primary" value="<?php $tcmp->Lang->P('Button.Add')?>" /> | |
| 73 | + </form> | |
| 74 | + </div> | |
| 75 | + <div style="clear:both;"></div> | |
| 76 | + | |
| 77 | + <style> | |
| 78 | + .widefat th { | |
| 79 | + font-weight: bold!important; | |
| 80 | + } | |
| 81 | + table input { | |
| 82 | + font-size: 13px; | |
| 83 | + } | |
| 84 | + .widefat thead td, .widefat thead th { | |
| 85 | + border-bottom: 0px!important; | |
| 86 | + } | |
| 87 | + </style> | |
| 88 | + <table class="widefat fixed" style="width:100%" id="tblSortable"> | |
| 89 | + <thead> | |
| 90 | + <tr> | |
| 91 | + <th style="width:30px;">#N</th> | |
| 92 | + <th style="width:50px; text-align:center;"><?php $tcmp->Lang->P('Active?')?></th> | |
| 93 | + <th><?php $tcmp->Lang->P('Name')?></th> | |
| 94 | + <th><?php $tcmp->Lang->P('Where?')?></th> | |
| 95 | + <th style="text-align:center;"><?php $tcmp->Lang->P('Shortcode')?></th> | |
| 96 | + <th style="text-align:center;"><?php $tcmp->Lang->P('Actions')?></th> | |
| 97 | + </tr> | |
| 98 | + </thead> | |
| 99 | + <tbody class="table-body"> | |
| 100 | + <?php | |
| 101 | + $i=1; | |
| 102 | + foreach ($snippets as $snippet) { | |
| 103 | + $bClass=(($i%2)==1 ? 'odd' : 'even'); | |
| 104 | + ?> | |
| 105 | + <tr class="<?php echo $bClass?>" id="row_<?php echo $snippet['id']?>"> | |
| 106 | + <td>#<?php echo $i++ ?></td> | |
| 107 | + <td style="text-align:center;"> | |
| 108 | + <?php | |
| 109 | + $color='red'; | |
| 110 | + $text='No'; | |
| 111 | + $question='QuestionActiveOn'; | |
| 112 | + if($snippet['active']==1) { | |
| 113 | + $color='green'; | |
| 114 | + $text='Yes'; | |
| 115 | + $question='QuestionActiveOff'; | |
| 116 | + } | |
| 117 | + $text='<span style="font-weight:bold; color:'.$color.'">'.$tcmp->Lang->L($text).'</span>'; | |
| 118 | + ?> | |
| 119 | + <a onclick="return confirm('<?php echo $tcmp->Lang->L($question)?>');" href="<?php echo TCMP_TAB_MANAGER_URI?>&tcmp_nonce=<?php echo esc_attr(wp_create_nonce('tcmp_toggle')); ?>&action=toggle&id=<?php echo $snippet['id'] ?>"> | |
| 120 | + <?php echo $text?> | |
| 121 | + </a> | |
| 122 | + </td> | |
| 123 | + <td><?php echo $snippet['name']?></td> | |
| 124 | + <td> | |
| 125 | + <?php | |
| 126 | + if($tcmp->Manager->isModeScript($snippet)) { | |
| 127 | + if($tcmp->Manager->isPageEverywhere($snippet)) { | |
| 128 | + $text='Everywhere'; | |
| 129 | + } else { | |
| 130 | + $text='Specific Pages'; | |
| 131 | + } | |
| 132 | + } else { | |
| 133 | + $text='Conversion'; | |
| 134 | + } | |
| 135 | + $tcmp->Lang->P($text); | |
| 136 | + ?> | |
| 137 | + </td> | |
| 138 | + <td style="text-align:center;"> | |
| 139 | + <input type="text" style="width:110px; text-align:center;" value='[tcm id="<?php echo esc_html($snippet['id']); ?>"]' readonly="readonly" class="tcmp-select-onfocus" /> | |
| 140 | + </td> | |
| 141 | + <td style="text-align:center;"> | |
| 142 | + <input type="button" class="button button-secondary" value="<?php $tcmp->Lang->P('Edit')?>" onclick="location.href='<?php echo TCMP_TAB_EDITOR_URI?>&id=<?php echo $snippet['id'] ?>';"/> | |
| 143 | + <input type="button" class="button button-secondary" value="<?php $tcmp->Lang->P('Delete?')?>" onclick="TCMP_btnDeleteClick(<?php echo $snippet['id'] ?>)"/> | |
| 144 | + </td> | |
| 145 | + </tr> | |
| 146 | + <?php } ?> | |
| 147 | + </tbody> | |
| 148 | + </table> | |
| 149 | + <script> | |
| 150 | + function TCMP_btnDeleteClick(id) { | |
| 151 | + var success=confirm('<?php echo $tcmp->Lang->L('Question.DeleteQuestion')?>'); | |
| 152 | + if(success) { | |
| 153 | + var href='<?php echo TCMP_TAB_MANAGER_URI?>&tcmp_nonce=<?php echo esc_attr(wp_create_nonce('tcmp_delete')); ?>&action=delete&id='; | |
| 154 | + location.href=href+id; | |
| 155 | + } | |
| 156 | + } | |
| 157 | + </script> | |
| 158 | + <?php | |
| 159 | + tcmp_notice_pro_features(); | |
| 160 | + if(count($snippets)>1) { | |
| 161 | + tcmp_manager_sortable_scripts(); | |
| 162 | + } | |
| 163 | + } else { ?> | |
| 164 | + <h2><?php $tcmp->Lang->P('EmptyTrackingList', TCMP_TAB_EDITOR_URI)?></h2> | |
| 165 | + <?php } | |
| 166 | +} | |
| 167 | +function tcmp_manager_sortable_scripts() { | |
| 168 | + ?> | |
| 169 | + <style> | |
| 170 | + .ui-state-highlight { | |
| 171 | + border: 1px dotted red!important; | |
| 172 | + background-color: #F4E449!important; | |
| 173 | + } | |
| 174 | + #tblSortable tbody tr:hover { | |
| 175 | + cursor: move!important; | |
| 176 | + } | |
| 177 | + #tblSortable tbody tr a:hover { | |
| 178 | + cursor: hand!important; | |
| 179 | + } | |
| 180 | + </style> | |
| 181 | + <script> | |
| 182 | + jQuery(function() { | |
| 183 | + var $sortable=jQuery("#tblSortable .table-body"); | |
| 184 | + $sortable.sortable({ | |
| 185 | + tolerance:'intersect' | |
| 186 | + , cursor:'move' | |
| 187 | + , items:'tr' | |
| 188 | + , placeholder:'ui-state-highlight' | |
| 189 | + , nested: 'tbody' | |
| 190 | + , update: function(event, ui) { | |
| 191 | + var orders=$sortable.sortable('serialize'); | |
| 192 | + var data={action: 'TCMP_changeOrder', order: orders}; | |
| 193 | + jQuery.post(ajaxurl, data, function(result) { | |
| 194 | + console.log(result); | |
| 195 | + }); | |
| 196 | + } | |
| 197 | + }); | |
| 198 | + $sortable.disableSelection(); | |
| 199 | + }); | |
| 200 | + </script> | |
| 201 | +<?php | |
| 202 | +} | |