namespace PixieApp; class App { private $page = false; private $action = 'index'; protected $controller = 'home'; public $tables = array( 'sponsors' => 'pixiebolt_sponsor', 'teams' => 'pixiebolt_team', 'players' => 'pixiebolt_player', 'streams' => 'pixiebolt_stream', 'matches' => 'pixiebolt_match', 'boardmembers' => 'pixiebolt_boardmembers', 'achievements' => 'pixiebolt_achievements', 'gallery_albums' => 'pixiebolt_galley_albums', 'gallery_photos' => 'pixiebolt_galley_photos', ); // constructor function __construct(){ global $wpdb; global $wp_query; // prefixes for tables $prefix = $wpdb->prefix; foreach ($this->tables as $key => $table ) { $this->tables[$key] = $prefix . $table; } $data = []; // initialize tables add_action('init', array($this, 'load_db')); // initialize pages $this->page = (isset($_REQUEST['page']) && !empty($_REQUEST['page']) && $_REQUEST['page'] != 'pixie-panel') ? $_REQUEST['page'] : 'home'; add_action('admin_menu', array($this, 'loadPages')); add_action('init', array($this, 'global_vars')); // Other $this->loadOptions(); $this->load_dependencies(); } function global_vars(){ global $wp_query; set_query_var('tables', $this->tables); } private function load_dependencies() { require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/pixieboltpanel-importer.php'; require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/pixieboltpanel-widget.php'; require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/pixieboltpanel-i18n.php'; } // load all tables public function load_db(){ global $wpdb; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); require_once plugin_dir_path( dirname( __FILE__ ) ) . '../database/scheme.php'; $orderNum = $wpdb->get_row("SHOW COLUMNS FROM `{$this->tables['players']}` LIKE 'orderNum'"); //Add column if not present. if(empty($orderNum)){ $wpdb->query("ALTER TABLE `{$this->tables['players']}` ADD `orderNum` INT NULL DEFAULT NULL AFTER `hitbox`"); } } // load all options private function loadOptions() { require_once plugin_dir_path( dirname( __FILE__ ) ) . 'core/Options.php'; add_action('admin_init', 'pixiebolt_add_options'); } // Make pages public function loadPages(){ // Add main page add_menu_page(esc_html__('PixiePanel', 'pixiebolt'), esc_html__('PixiePanel', 'pixiebolt'), 'manage_options', 'pixiepanel', array($this, 'router'), plugin_dir_url(__FILE__ ) . '../../assets/admin/panel_ic.svg'); // Adding submenu pages add_submenu_page('pixiepanel', esc_html__('Teams', 'pixiebolt'), esc_html__('Teams', 'pixiebolt'), 'manage_options', 'pixieteams', array($this, 'router')); add_submenu_page('pixiepanel', esc_html__('Streams', 'pixiebolt'), esc_html__('Streams', 'pixiebolt'), 'manage_options', 'pixiestreams', array($this, 'router')); add_submenu_page('pixiepanel', esc_html__('Matches', 'pixiebolt'), esc_html__('Matches', 'pixiebolt'), 'manage_options', 'pixiematches', array($this, 'router')); add_submenu_page('pixiepanel', esc_html__('Sponsors', 'pixiebolt'), esc_html__('Sponsors', 'pixiebolt'), 'manage_options', 'pixiesponsors', array($this, 'router')); add_submenu_page('pixiepanel', esc_html__('Gallery', 'pixiebolt'), esc_html__('Gallery', 'pixiebolt'), 'manage_options', 'pixiegallery', array($this, 'router')); add_submenu_page('pixiepanel', esc_html__('About', 'pixiebolt'), esc_html__('About', 'pixiebolt'), 'manage_options', 'pixieabout', array($this, 'router')); } public function router() { // check if exists if(file_exists(plugin_dir_path( dirname( __FILE__ ) ) . 'controllers/' . $this->page . 'Controller.php')) { $this->controller = $this->page . 'Controller'; } // initialize controller require_once plugin_dir_path( dirname( __FILE__ ) ) . 'controllers/' . $this->controller .'.php'; $this->controller = new $this->controller; $this->action = (isset($_REQUEST['action']) && !empty($_REQUEST['action'])) ? $_REQUEST['action'] : 'index'; // Method exists if(method_exists($this->controller, $this->action)) { call_user_func_array([$this->controller, $this->action], ['tables' => $this->tables]); } else { die('Not found'); } } public function redirect($to) { wp_redirect('fasf'); } } namespace PixieApp; class Controller { protected $view = false; public function view($view, $data = [], $notification = false) { // Enqueue style $this->view = $view; $this->enqueue(); // Notification if($notification) { $data['notification'] = $data; } // Set Data set_query_var('pixiebolt_data', $data); if(!isset($data['menu'])) { $data['menu'] = []; } set_query_var('pixiebolt_admin_menu', $data['menu']); // Require header require_once PIXIE_LOC_DIR . 'includes/header.php'; // Content require_once PIXIE_LOC_DIR . 'pages/' . $view . '.php'; // Require footer require_once PIXIE_LOC_DIR . 'includes/footer.php'; } public function query($q) { global $wpdb; $result = $wpdb->get_results($q, ARRAY_A); return $result; } public function redirect($url, $status = 'success', $notification = true, $slug = false) { $redirectUrl = menu_page_url($url, false); if($slug) { $redirectUrl .= $slug; } $this->view('error/index', ['status' => $status, 'message' => $notification, 'redirectUrl' => $redirectUrl], $notification); } /** * Admin panel including styles and scripts **/ public function enqueue() { // Page hook $hook = $this->view; // Styles add_action( 'admin_enqueue_scripts', array($this, $this->pixiebolt_admin_assets($hook))); add_action( 'customize_preview_init', array($this, 'pixiebolt_add_customization_script')); } // adding styles for admin page function pixiebolt_admin_assets($hook){ // pages that are including scripts and styles $pages = [ 'home', 'error/index', 'team/index', 'team/edit', 'team/editplayer', 'team/achievement', 'sponsor/index', 'sponsor/edit', 'stream/index', 'stream/edit', 'match/index', 'match/edit', 'about/index', 'about/edit', 'gallery/index', 'gallery/edit', ]; if( !in_array($hook, $pages) ) { return; } // escape if it's not pixie page /* Styles */ wp_enqueue_style('pixiebolt_admin_style', plugin_dir_url( __FILE__ ) . '../../assets/admin/css/style.admin.css', array(), '1.0.1', 'all'); wp_enqueue_style('font-awesome', plugin_dir_url( __FILE__ ) . '../../assets/css/font-awesome.min.css', array(), '1.0.0', 'all'); wp_enqueue_style('jquery-ui-structure', plugin_dir_url( __FILE__ ) . '../../assets/admin/css/jquery-ui.structure.min.css', array(), '1.12.0', 'all'); wp_enqueue_style('jquery-ui-theme', plugin_dir_url( __FILE__ ) . '../../assets/admin/css/jquery-ui.theme.min.css', array(), '1.12.0', 'all'); wp_enqueue_style('jquery-ui', plugin_dir_url( __FILE__ ) . '../../assets/admin/css/jquery-ui.min.css', array(), '1.12.1', 'all'); wp_enqueue_style('datatables', plugin_dir_url( __FILE__ ) . '../../assets/admin/css/datatables.min.css', array(), '1.10.12', 'all'); wp_enqueue_style('tipsy', plugin_dir_url( __FILE__ ) . '../../assets/admin/css/tipsy.css', array(), '1.0.0', 'all'); wp_enqueue_style('jquery_datetimepicker', plugin_dir_url( __FILE__ ) . '../../assets/admin/css/jquery.datetimepicker.min.css', array(), '1.0.0', 'all'); /* Scripts */ wp_enqueue_media(); wp_enqueue_script( 'datatablesjs', plugin_dir_url( __FILE__ ) . '../../assets/admin/js/datatables.min.js', array('jquery'), '1.10.12', true ); wp_enqueue_script( 'jquery_tipsy', plugin_dir_url( __FILE__ ) . '../../assets/admin/js/jquery.tipsy.js', array('jquery'), '1.0.0', true ); $customJS = $this->pixiebolt_inline_datatables(); // Load inline js wp_add_inline_script( 'datatablesjs', $customJS ); wp_enqueue_script( 'jquery_datetimepicker_fulljs', plugin_dir_url( __FILE__ ) . '../../assets/admin/js/jquery.datetimepicker.full.min.js', array('jquery'), '1.0.0', true); $datePickerJS = $this->pixiebolt_inline_datetimepicker(); wp_add_inline_script('jquery_datetimepicker_fulljs', $datePickerJS); $jqueryTipsy = $this->pixiebolt_inline_tipsy(); wp_add_inline_script('jquery_tipsy', $jqueryTipsy); wp_enqueue_script( 'jquery_uijs', plugin_dir_url( __FILE__ ) . '../../assets/admin/js/jquery-ui.min.js', array('jquery'), '1.12.1', true ); $customSortable = $this->pixiebolt_inline_sortable(); // Load inline js wp_add_inline_script('jquery_uijs', $customSortable); wp_enqueue_script( 'pixiebolt_admin_script', plugin_dir_url( __FILE__ ) . '../../assets/admin/js/script.admin.js', array('jquery'), '1.0.0', true ); wp_localize_script( 'pixiebolt_admin_script', 'ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'pixieboltpanel_value' => false ) ); } private function pixiebolt_inline_tipsy() { $txt = " jQuery(function() { jQuery('[rel=tipsy]').tipsy({fade: true, gravity: 's'}); }); "; return $txt; } private function pixiebolt_inline_sortable() { $txt = " jQuery(document).ready(function() { jQuery('.playersTable > tbody').sortable({ placeholder: \"ui-state-highlight\", update: function() { var items = jQuery('.playersTable > tbody').sortable(\"toArray\", {key:'item[]'}); var data = { 'action': 'pixieboltpanel_save_player_order', 'items': items, 'pixieboltpanel_value': ajax_object.pixieboltpanel_value }; // We can also pass the url value separately from ajaxurl for front end AJAX implementations jQuery.post(ajax_object.ajax_url, data, function(response) { console.log('Saved'); }); } }); jQuery('.playersTable > tbody').disableSelection(); }); "; return $txt; } private function pixiebolt_inline_datatables() { $txt = " jQuery(document).ready(function() { jQuery('#datatable').DataTable({}); jQuery('.playersTable').DataTable({\"bSort\" : false}); jQuery('.noSortTable').DataTable({\"bSort\" : false}); }); "; return $txt; } private function pixiebolt_inline_datetimepicker() { $js = " jQuery(document).ready(function() { jQuery('.dateFrom').datetimepicker({ minDate: 0, onShow:function( ct ){ this.setOptions({ maxDate:jQuery('.dateTo').val()?jQuery('.dateTo').val():false }) } }); jQuery('.dateTo').datetimepicker({ onShow:function( ct ){ this.setOptions({ minDate:jQuery('.dateFrom').val()?jQuery('.dateFrom').val():0 }) } }); }); "; return $js; } // adding scripts for customization options function pixiebolt_add_customization_script(){ wp_register_script( 'pixiebolt_custom_script', plugin_dir_url( __FILE__ ) . '../../assets/admin/js/customization.js', array('jquery'), '1.0.0', true ); wp_enqueue_script( 'pixiebolt_custom_script' ); } } namespace PixieApp; class Stream { public function parseStreamURI($uri) { $parsed = parse_url($uri); if(empty($parsed['path'])) { return NULL; } $temp = explode('/', $parsed['path']); return "{$temp[1]}"; } public function getStream($uri, $type, $clientid = null) { $curl = curl_init(); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($curl, CURLOPT_TIMEOUT, 30); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); if($type == 'twitch') { curl_setopt($curl, CURLOPT_HTTPHEADER, array('Client-ID: ' . $clientid)); } curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); if($type == 'twitch') { $uri = 'https://api.twitch.tv/kraken/channels/' . $uri; } elseif($type == 'hitbox') { $uri = 'https://api.hitbox.tv/media/live/' . $uri; } else { $uri = 'http://api.azubu.tv/public/channel/' . $uri; } curl_setopt($curl, CURLOPT_URL, $uri); $response = curl_exec($curl); if(curl_errno($curl)) { $response = json_encode(['error' => true, 'message' => curl_error($curl)]); } curl_close($curl); return $response; } }