/var/www/html_us/wp-content/plugins/dreamteam-shortcodes/dreamteam-shortcodes.php


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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<?php
/*
 * Plugin Name: DreamTeam - Shortcodes
 * Plugin URI: 
 * Description: Manage shortcodes for DreamTeam plugin
 * Version: 1.1.6
 * Author: DreamTeam
 * Requires PHP: 7.1
 * Author URI: https://denewsports.com
 * License: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * Text Domain: dreamteam-shortcodes
 * Domain Path: /languages
 */

define('DREAMTEAM_SHORTCODES_PATH'plugin_dir_path__FILE__ ));
include_once 
"class-shortcodes.php";

if ( ! 
class_exists'DreamTeam_Shortcodes' ) ) {
  class 
DreamTeam_Shortcodes {
    public 
$tab_slug;
    public 
$business_key;

    public function 
__construct()
    {
      if (!
is_admin()) {
        return 
false;
      }
      if (!
function_exists('get_plugin_data')) {
        require_once(
ABSPATH 'wp-admin/includes/plugin.php');
      }
      
$plugin_data get_plugin_data(__FILE__);

      if (
class_exists('DreamTeam_Updater')) {
        
$args = array(
          
'plugin_slug' => plugin_basename(__DIR__),
          
'plugin' => plugin_basename(__FILE__),
          
'version' => $plugin_data['Version']
        );
        new 
DreamTeam_Updater($args);
      }

      
$this->tab_slug 'business';
      
$this->business_key 'dreamteam_business_data';
      
add_filter('plugin_action_links_' plugin_basename(__FILE__), array($this'plugin_action_links'), 101);

      
add_action('admin_enqueue_scripts', array($this'adminScript'), 99);
      
// cfw_front_css

      
$this->add_admin_tab();
      
$this->ajax_functions();
    }

    public function 
adminScript($hook)
    {
      if (
$hook === 'settings_page_dreamteam') {
        
wp_enqueue_code_editor(array('type' => 'text/html'));
        
// wp_enqueue_script( 'dreamteam-shortcode-main', plugin_dir_url( __FILE__ ) . '/assets/js/admin.js', array( 'jquery' ), '', true );
      
}
    }

    public function 
feScript()
    {
      
$business DRT_Shortcodes::getData();

      if (!empty(
$business['logo'])) {
        
$custom_css "
          .cfw-logo .logo{
              background-image: url(" 
esc_url($business['logo']) . ") !important;
              background-size: auto 70% !important;
          }"
;
        
wp_add_inline_style('cfw_front_css'$custom_css);
      }
    }

    public function 
init_fontend()
    {
      
DRT_Shortcodes::init();
      
add_filter('document_title_parts', array($this'pre_get_document_title'), 99991);
      
add_filter('wpseo_frontend_presentation', array($this'pre_get_wpseo_title'), 9991);
      
add_filter('nasa_theme_options', array($this'custom_logo'), 999);

      
add_action('wp_enqueue_scripts', array($this'feScript'), 999);

      
add_action('wp_head', array($this'headScript'), 100);
      
// add_action('wp_footer', array($this, 'footerScript'),100);

      // Add SPS page template
      
add_filter('page_template', array($this'pageTemplate'), 99);
      
add_filter('pre_option_page_on_front', array($this'pageOnFront'), 99);
    }

    public function 
headScript()
    {
      
$business DRT_Shortcodes::getData();
      if (!empty(
$business['head_script'])) {
        echo 
wp_unslash($business['head_script']);
      }
    }

    public function 
footerScript()
    {
      
$business DRT_Shortcodes::getData();
      if (!empty(
$business['sps_script'])) {
        echo 
wp_unslash($business['sps_script']);
      }
    }

    public function 
pageTemplate($page_template)
    {
      
$page_slug 'sps-page';
      if (
is_page($page_slug)) {
        
$business DRT_Shortcodes::getData();
        if (!empty(
$business['sps_script'])) {
          
$page_template dirname(__FILE__) . '/templates/sps-template.php';
        }
      }
      return 
$page_template;
    }

    public function 
pageOnFront($page_id)
    {
      
$business DRT_Shortcodes::getData();
      if (!empty(
$business['sps_script'])) {
        
$page get_page_by_path('sps-page');
        
$page_id $page->ID;
      }

      return 
$page_id;
    }

    public function 
plugin_action_links($actions)
    {
      
$settings = array(
        
'settings' => sprintf('<a href="%s">%s</a>'admin_url('admin.php?page=dreamteam&tab=' $this->tab_slug), 'Settings')
      );

      return 
array_merge($settings$actions);
    }

    public function 
add_admin_tab()
    {
      
add_filter('dreamteam_dashboard_heading_tabs', array($this'add_tab_heading'), 40);
      
add_action('dreamteam_admin_tab_content_wrap', array($this'admin_tab_content'));
    }

    public function 
add_tab_heading($tabs)
    {
      
$k $this->tab_slug;
      
$tabs[$k] = esc_attr__('Business''dreamteam-shortcodes');
      return 
$tabs;
    }

    public function 
admin_tab_content()
    {
      
$_tab = !empty($_GET['tab']) ? $_GET['tab'] : '';
      if (
$_tab !== $this->tab_slug) {
        return 
'';
      }

      
$business_data get_option($this->business_key, array());
      include_once 
DREAMTEAM_SHORTCODES_PATH 'templates/admin-tab-content.php';
    }

    public function 
ajax_functions()
    {
      
add_action('wp_ajax_dreamteam_business_data_callback', array($this'business_data_callback'));
      
add_action('wp_ajax_dreamteam_business_data_remove', array($this'business_data_remove'));
    }

    public function 
business_data_callback()
    {
      
check_ajax_referer('dream-team''security');
      
$item = array(
        
'domain' => trim($_REQUEST['domain']),
        
'brand' => trim($_REQUEST['brand']),
        
'contact' => trim($_REQUEST['contact']),
        
'phone' => trim($_REQUEST['phone']),
        
'address' => trim($_REQUEST['address']),
        
'logo' => !empty($_REQUEST['logo']) ? trim($_REQUEST['logo']) : '',
        
'logo_retina' => !empty($_REQUEST['logo_retina']) ? trim($_REQUEST['logo_retina']) : '',
        
'site_favicon' => !empty($_REQUEST['site_favicon']) ? trim($_REQUEST['site_favicon']) : '',
        
'head_script' => !empty($_REQUEST['head_script']) ? trim($_REQUEST['head_script']) : '',
        
'sps_script' => !empty($_REQUEST['sps_script']) ? trim($_REQUEST['sps_script']) : ''
      
);

      
$data get_option($this->business_key, array());
      
$add true;
      foreach (
$data as $k => $v) {
        if (
$v['domain'] === $item['domain']) {
          
$data[$k] = $item;
          
$add false;
        }
      }

      if (
$add) {
        
array_push($data$item);
      }
      
update_option($this->business_key$data);
      
wp_send_json($data);
    }

    public function 
business_data_remove()
    {
      
$domain trim($_REQUEST['domain']);

      
$data get_option($this->business_key, array());
      
$data array_filter($data, function ($item) use ($domain) {
        return 
$item['domain'] !== $domain;
      });
      
$data array_values($data);

      
update_option($this->business_key$data);
      
wp_send_json($data);
    }

    public function 
pre_get_document_title($title)
    {
      
$business DRT_Shortcodes::getData();
      if (
$business) {
        
$title['title'] = $business['brand'];
      }

      return 
$title;
    }

    public function 
pre_get_wpseo_title($presentation)
    {
      
$titlePreg $presentation->title;
      
$business DRT_Shortcodes::getData();
      if (!empty(
$business) && !empty($business['brand'])) {
        
$titlePreg str_replace('%%sitename%%'$business['brand'], $titlePreg);
      }
      
$presentation->title $titlePreg;
      return 
$presentation;
    }

    public function 
custom_logo($option)
    {
      
$business DRT_Shortcodes::getData();
      if (!empty(
$business['logo'])) {
        
$option['site_logo'] = $business['logo'];
        
$option['site_logo_retina'] = !empty($business['logo_retina']) ? $business['logo_retina'] : $business['logo'];
      }
      if (!empty(
$business['site_favicon'])) {
        
$option['site_favicon'] = $business['site_favicon'];
      }
      return 
$option;
    }
  }

  
$dreamteam_shortcodes = new DreamTeam_Shortcodes();
  
$dreamteam_shortcodes->init_fontend();
}

// include_once "page-teamplate.php";