Tabs.php
302 lines
| 1 | <?php |
| 2 | class TCMP_Tabs { |
| 3 | private $tabs = array(); |
| 4 | |
| 5 | function __construct() { |
| 6 | } |
| 7 | public function init() { |
| 8 | global $tcmp; |
| 9 | if($tcmp->Utils->isAdminUser()) { |
| 10 | add_action('admin_menu', array(&$this, 'attachMenu')); |
| 11 | add_filter('plugin_action_links', array(&$this, 'pluginActions'), 10, 2); |
| 12 | if($tcmp->Utils->isPluginPage()) { |
| 13 | add_action('admin_enqueue_scripts', array(&$this, 'enqueueScripts')); |
| 14 | } |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | function attachMenu() { |
| 19 | add_submenu_page('options-general.php' |
| 20 | , TCMP_PLUGIN_NAME, TCMP_PLUGIN_NAME |
| 21 | , 'manage_options', TCMP_PLUGIN_SLUG, array(&$this, 'showTabPage')); |
| 22 | } |
| 23 | function pluginActions($links, $file) { |
| 24 | global $tcmp; |
| 25 | if($file==TCMP_PLUGIN_SLUG.'/index.php'){ |
| 26 | $settings=array(); |
| 27 | $settings[]="<a href='".TCMP_TAB_MANAGER_URI."'>".$tcmp->Lang->L('Settings').'</a>'; |
| 28 | $settings[]="<a href='".TCMP_PAGE_PREMIUM."'>".$tcmp->Lang->L('PREMIUM').'</a>'; |
| 29 | $links=array_merge($settings, $links); |
| 30 | } |
| 31 | return $links; |
| 32 | } |
| 33 | function enqueueScripts() { |
| 34 | wp_enqueue_script('jquery'); |
| 35 | wp_enqueue_script('jQuery'); |
| 36 | wp_enqueue_script('jquery-ui-sortable'); |
| 37 | |
| 38 | $this->wpEnqueueStyle('assets/css/style.css'); |
| 39 | $this->wpEnqueueStyle('assets/deps/select2-3.5.2/select2.css'); |
| 40 | $this->wpEnqueueScript('assets/deps/select2-3.5.2/select2.min.js'); |
| 41 | $this->wpEnqueueScript('assets/deps/starrr/starrr.js'); |
| 42 | |
| 43 | $this->wpEnqueueScript('assets/js/library.js'); |
| 44 | $this->wpEnqueueScript('assets/js/plugin.js'); |
| 45 | } |
| 46 | function wpEnqueueStyle($uri, $name='') { |
| 47 | if($name=='') { |
| 48 | $name=explode('/', $uri); |
| 49 | $name=$name[count($name)-1]; |
| 50 | $dot=strrpos($name, '.'); |
| 51 | if($dot!==FALSE) { |
| 52 | $name=substr($name, 0, $dot); |
| 53 | } |
| 54 | $name=TCMP_PLUGIN_PREFIX.'_'.$name; |
| 55 | } |
| 56 | |
| 57 | $v='?v='.TCMP_PLUGIN_VERSION; |
| 58 | wp_enqueue_style($name, TCMP_PLUGIN_URI.$uri.$v); |
| 59 | } |
| 60 | function wpEnqueueScript($uri, $name='', $version=FALSE) { |
| 61 | if($name=='') { |
| 62 | $name=explode('/', $uri); |
| 63 | $name=$name[count($name)-1]; |
| 64 | $dot=strrpos($name, '.'); |
| 65 | if($dot!==FALSE) { |
| 66 | $name=substr($name, 0, $dot); |
| 67 | } |
| 68 | $name=TCMP_PLUGIN_PREFIX.'_'.$name; |
| 69 | } |
| 70 | |
| 71 | $v='?v='.TCMP_PLUGIN_VERSION; |
| 72 | $deps=array(); |
| 73 | wp_enqueue_script($name, TCMP_PLUGIN_URI.$uri.$v, $deps, $version, FALSE); |
| 74 | } |
| 75 | |
| 76 | function showTabPage() { |
| 77 | global $tcmp; |
| 78 | |
| 79 | $v=$tcmp->Options->getShowWhatsNewSeenVersion(); |
| 80 | if($v!=TCMP_WHATSNEW_VERSION) { |
| 81 | $tcmp->Options->setShowWhatsNew(TRUE); |
| 82 | } |
| 83 | |
| 84 | $hwb=TCMP_ISQS('hwb', ''); |
| 85 | if($hwb!='') { |
| 86 | $tcmp->Options->setShowWhatsNew(FALSE); |
| 87 | } |
| 88 | |
| 89 | $id=TCMP_ISQS('id', 0); |
| 90 | $defaultTab=TCMP_TAB_MANAGER; |
| 91 | $tab=TCMP_SQS('tab', $defaultTab); |
| 92 | |
| 93 | if($tcmp->Options->isShowWhatsNew()) { |
| 94 | $tab=TCMP_TAB_WHATS_NEW; |
| 95 | $defaultTab=$tab; |
| 96 | $this->tabs[TCMP_TAB_WHATS_NEW]=$tcmp->Lang->L('What\'s New'); |
| 97 | //$this->tabs[TCMP_TAB_MANAGER]=$tcmp->Lang->L('Start using the plugin!'); |
| 98 | } else { |
| 99 | if($id>0 || !$tcmp->Manager->isLimitReached(FALSE)) { |
| 100 | $this->tabs[TCMP_TAB_EDITOR]=$tcmp->Lang->L($id>0 && $tab==TCMP_TAB_EDITOR ? 'Edit Script' : 'Add New Script'); |
| 101 | } elseif($tab==TCMP_TAB_EDITOR) { |
| 102 | $tab = TCMP_TAB_MANAGER; |
| 103 | } |
| 104 | |
| 105 | $this->tabs[TCMP_TAB_MANAGER]=$tcmp->Lang->L('Manager'); |
| 106 | $this->tabs[TCMP_TAB_ADMIN_OPTIONS] = $tcmp->Lang->L('Admin Options'); |
| 107 | $this->tabs[TCMP_TAB_SETTINGS]=$tcmp->Lang->L('Settings'); |
| 108 | $this->tabs[TCMP_TAB_DOCS]=$tcmp->Lang->L('Docs & FAQ'); |
| 109 | } |
| 110 | |
| 111 | ?> |
| 112 | |
| 113 | <div class="wrap" style="margin: 5px;"> |
| 114 | <?php |
| 115 | $this->showTabs($defaultTab); |
| 116 | $header=''; |
| 117 | switch ($tab) { |
| 118 | case TCMP_TAB_EDITOR: |
| 119 | $header=($id>0 ? 'Edit' : 'Add'); |
| 120 | break; |
| 121 | case TCMP_TAB_WHATS_NEW: |
| 122 | $header=''; |
| 123 | break; |
| 124 | case TCMP_TAB_MANAGER: |
| 125 | $header='Manager'; |
| 126 | break; |
| 127 | case TCMP_TAB_ADMIN_OPTIONS: |
| 128 | $header='Admin Options'; |
| 129 | break; |
| 130 | case TCMP_TAB_SETTINGS: |
| 131 | $header='Settings'; |
| 132 | break; |
| 133 | } |
| 134 | |
| 135 | if($tcmp->Lang->H($header.'Title')) { ?> |
| 136 | <h2><?php $tcmp->Lang->P($header . 'Title', TCMP_PLUGIN_VERSION) ?></h2> |
| 137 | <?php if ($tcmp->Lang->H($header . 'Subtitle')) { ?> |
| 138 | <div><?php $tcmp->Lang->P($header . 'Subtitle') ?></div> |
| 139 | <?php } ?> |
| 140 | <br/> |
| 141 | <?php } |
| 142 | |
| 143 | tcmp_ui_first_time(); |
| 144 | ?> |
| 145 | <div style="float:left; margin:5px;"> |
| 146 | <?php |
| 147 | $styles=array(); |
| 148 | $styles[]='float:left'; |
| 149 | $styles[]='margin-right:20px'; |
| 150 | if($tab!=TCMP_TAB_WHATS_NEW) { |
| 151 | $styles[]='max-width:750px'; |
| 152 | } |
| 153 | $styles=implode('; ', $styles); |
| 154 | ?> |
| 155 | <div id="tcmp-page" style="<?php echo $styles?>"> |
| 156 | <?php switch ($tab) { |
| 157 | case TCMP_TAB_WHATS_NEW: |
| 158 | tcmp_ui_whats_new(); |
| 159 | break; |
| 160 | case TCMP_TAB_EDITOR: |
| 161 | tcmp_ui_editor(); |
| 162 | break; |
| 163 | case TCMP_TAB_MANAGER: |
| 164 | tcmp_ui_manager(); |
| 165 | break; |
| 166 | case TCMP_TAB_ADMIN_OPTIONS: |
| 167 | tcmp_ui_admin_options(); |
| 168 | break; |
| 169 | case TCMP_TAB_SETTINGS: |
| 170 | tcmp_ui_track(); |
| 171 | tcmp_ui_settings(); |
| 172 | break; |
| 173 | } ?> |
| 174 | </div> |
| 175 | <?php if($tab!=TCMP_TAB_WHATS_NEW) { ?> |
| 176 | <div id="tcmp-sidebar" style="float:left; max-width: 250px;"> |
| 177 | <?php |
| 178 | $count=$this->getPluginsCount(); |
| 179 | $plugins=array(); |
| 180 | while(count($plugins)<2) { |
| 181 | $id=rand(1, $count); |
| 182 | if(!isset($plugins[$id])) { |
| 183 | $plugins[$id]=$id; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | $this->drawContactUsWidget(); |
| 188 | foreach($plugins as $id) { |
| 189 | $this->drawPluginWidget($id); |
| 190 | } |
| 191 | ?> |
| 192 | </div> |
| 193 | <?php } ?> |
| 194 | </div> |
| 195 | </div> |
| 196 | <div style="clear:both"></div> |
| 197 | <?php } |
| 198 | function getPluginsCount() { |
| 199 | global $tcmp; |
| 200 | $index=1; |
| 201 | while($tcmp->Lang->H('Plugin'.$index.'.Name')) { |
| 202 | $index++; |
| 203 | } |
| 204 | return $index-1; |
| 205 | } |
| 206 | function drawPluginWidget($id) { |
| 207 | global $tcmp; |
| 208 | ?> |
| 209 | <div class="tcmp-plugin-widget"> |
| 210 | <b><?php $tcmp->Lang->P('Plugin'.$id.'.Name') ?></b> |
| 211 | <br> |
| 212 | <i><?php $tcmp->Lang->P('Plugin'.$id.'.Subtitle') ?></i> |
| 213 | <br> |
| 214 | <ul style="list-style: circle;"> |
| 215 | <?php |
| 216 | $index=1; |
| 217 | while($tcmp->Lang->H('Plugin'.$id.'.Feature'.$index)) { ?> |
| 218 | <li><?php $tcmp->Lang->P('Plugin'.$id.'.Feature'.$index) ?></li> |
| 219 | <?php $index++; |
| 220 | } ?> |
| 221 | </ul> |
| 222 | <a style="float:right;" class="button-primary" href="<?php $tcmp->Lang->P('Plugin'.$id.'.Permalink') ?>" target="_blank"> |
| 223 | <?php $tcmp->Lang->P('PluginCTA')?> |
| 224 | </a> |
| 225 | <div style="clear:both"></div> |
| 226 | </div> |
| 227 | <br> |
| 228 | <?php } |
| 229 | function drawContactUsWidget() { |
| 230 | global $tcmp; |
| 231 | ?> |
| 232 | <b><?php $tcmp->Lang->P('Sidebar.Title') ?></b> |
| 233 | <ul style="list-style: circle;"> |
| 234 | <?php |
| 235 | $index=1; |
| 236 | while($tcmp->Lang->H('Sidebar'.$index.'.Name')) { ?> |
| 237 | <li> |
| 238 | <a href="<?php $tcmp->Lang->P('Sidebar'.$index.'.Url')?>" target="_blank"> |
| 239 | <?php $tcmp->Lang->P('Sidebar'.$index.'.Name')?> |
| 240 | </a> |
| 241 | </li> |
| 242 | <?php $index++; |
| 243 | } ?> |
| 244 | </ul> |
| 245 | <?php } |
| 246 | function showTabs($defaultTab) { |
| 247 | global $tcmp; |
| 248 | $tab=$tcmp->Check->of('tab', $defaultTab); |
| 249 | if($tab==TCMP_TAB_DOCS) { |
| 250 | $tcmp->Utils->redirect(TCMP_TAB_DOCS_URI); |
| 251 | } |
| 252 | if($tcmp->Options->isShowWhatsNew()) { |
| 253 | $tab=TCMP_TAB_WHATS_NEW; |
| 254 | } |
| 255 | |
| 256 | ?> |
| 257 | <h2 class="nav-tab-wrapper" style="float:left; width:97%;"> |
| 258 | <?php |
| 259 | foreach ($this->tabs as $k=>$v) { |
| 260 | $active = ($tab==$k ? 'nav-tab-active' : ''); |
| 261 | $style=''; |
| 262 | $target='_self'; |
| 263 | if($tcmp->Options->isShowWhatsNew() && $k==TCMP_TAB_MANAGER) { |
| 264 | $active=''; |
| 265 | $style='background-color:#F2E49B'; |
| 266 | } |
| 267 | if($k==TCMP_TAB_DOCS) { |
| 268 | $target='_blank'; |
| 269 | $style='background-color:#F2E49B'; |
| 270 | } |
| 271 | ?> |
| 272 | <a style="float:left; margin-left:10px; <?php echo $style?>" class="nav-tab <?php echo $active?>" target="<?php echo $target ?>" href="?page=<?php echo TCMP_PLUGIN_SLUG?>&tab=<?php echo $k?>"><?php echo $v?></a> |
| 273 | <?php |
| 274 | } |
| 275 | ?> |
| 276 | <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.min.css"> |
| 277 | <style> |
| 278 | .starrr {display:inline-block} |
| 279 | .starrr i{font-size:16px;padding:0 1px;cursor:pointer;color:#2ea2cc;} |
| 280 | </style> |
| 281 | <div style="float:right; display:none;" id="rate-box"> |
| 282 | <span style="font-weight:700; font-size:13px; color:#555;"><?php $tcmp->Lang->P('Rate us')?></span> |
| 283 | <div id="tcmp-rate" class="starrr" data-connected-input="tcmp-rate-rank"></div> |
| 284 | <input type="hidden" id="tcmp-rate-rank" name="tcmp-rate-rank" value="5" /> |
| 285 | <?php $tcmp->Utils->twitter('data443risk') ?> |
| 286 | </div> |
| 287 | <script> |
| 288 | jQuery(function() { |
| 289 | jQuery(".starrr").starrr(); |
| 290 | jQuery('#tcmp-rate').on('starrr:change', function(e, value){ |
| 291 | var url='https://wordpress.org/support/view/plugin-reviews/tracking-code-manager?rate=5#postform'; |
| 292 | window.open(url); |
| 293 | }); |
| 294 | jQuery('#rate-box').show(); |
| 295 | }); |
| 296 | </script> |
| 297 | </h2> |
| 298 | <div style="clear:both;"></div> |
| 299 | <?php } |
| 300 | } |
| 301 | |
| 302 |