Changeset 3173030
- Timestamp:
- 10/21/2024 03:01:43 PM (17 months ago)
- Location:
- humix
- Files:
-
- 7 edited
- 8 copied
-
tags/1.5.0 (copied) (copied from humix/trunk)
-
tags/1.5.0/HumixNamespace (copied) (copied from humix/trunk/HumixNamespace)
-
tags/1.5.0/HumixNamespace/Authentication.php (modified) (3 diffs)
-
tags/1.5.0/HumixNamespace/Channels.php (modified) (5 diffs)
-
tags/1.5.0/HumixNamespace/Settings.php (copied) (copied from humix/trunk/HumixNamespace/Settings.php) (10 diffs)
-
tags/1.5.0/README.txt (copied) (copied from humix/trunk/README.txt) (2 diffs)
-
tags/1.5.0/humix-block/build/index.asset.php (copied) (copied from humix/trunk/humix-block/build/index.asset.php)
-
tags/1.5.0/humix-block/build/index.js (copied) (copied from humix/trunk/humix-block/build/index.js)
-
tags/1.5.0/humix-block/src/consts.js (copied) (copied from humix/trunk/humix-block/src/consts.js)
-
tags/1.5.0/humix.php (copied) (copied from humix/trunk/humix.php) (6 diffs)
-
trunk/HumixNamespace/Authentication.php (modified) (3 diffs)
-
trunk/HumixNamespace/Channels.php (modified) (5 diffs)
-
trunk/HumixNamespace/Settings.php (modified) (10 diffs)
-
trunk/README.txt (modified) (2 diffs)
-
trunk/humix.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
humix/tags/1.5.0/HumixNamespace/Authentication.php
r3129709 r3173030 23 23 add_action('rest_api_init', function () { 24 24 register_rest_route( 25 'humix/v1',25 RestApi::REST_API_BASE, 26 26 '/auth/verify', 27 array (27 array( 28 28 'methods' => \WP_REST_SERVER::READABLE, 29 'callback' => array (self::class, 'verify_handler'),29 'callback' => array(self::class, 'verify_handler'), 30 30 'permission_callback' => '__return_true', 31 31 'show_in_index' => false … … 33 33 ); 34 34 }); 35 36 35 } 37 36 … … 151 150 } 152 151 153 public function is_humix_direct_domain($token) { 152 public function is_humix_direct_domain($token) 153 { 154 154 // we have to cache result as string since an empty cache returns false, so we can't differentiate between false and not cached 155 155 $cached_result_as_str = get_transient(self::IS_HUMIX_DIRECT); -
humix/tags/1.5.0/HumixNamespace/Channels.php
r3129709 r3173030 10 10 const MY_CHANNELS_CACHE_KEY = "humix_plugin:my_channels"; 11 11 const MY_CHANNELS_CACHE_TTL = 12 * 3600; // 12 hours 12 const MIDDLETON_REWRITE_RULE_REGEX = '^(humix|beardeddragon|ezoimgfmt)/?(.*)?$'; 12 const HOSTING_LIVE_CHECK_ENDPOINT = "_humix_integration_check"; 13 const HOSTING_LIVE_CHECK_RESPONSE = "humix-integration-ok"; 14 const MIDDLETON_REWRITE_RULE_REGEX = '^(humix|beardeddragon|ezoimgfmt|_humix_integration_check)/?(.*)?$'; 13 15 14 16 public function update_assigned_channel($token, $new_channel_id) … … 31 33 } 32 34 33 function remove_assigned_channel($token)35 public function remove_assigned_channel($token) 34 36 { 35 37 if ($token === "") { … … 41 43 } 42 44 self::remove_middleton_paths(); 45 } 46 47 public function get_assigned_channel_from_publisher_backend($token) 48 { 49 if ($token === "") { 50 throw new \InvalidArgumentException("Token is empty"); 51 } 52 $response = \HumixNamespace\RequestUtils::publisher_backend_request($token, 'assigned-channel', 'GET'); 53 if (is_wp_error($response)) { 54 throw new \Exception("Error communicating with publisher backend: " . $response->get_error_message()); 55 } 56 $body = wp_remote_retrieve_body($response); 57 if (!$body) { 58 throw new \Exception("Error empty response from publisher backend"); 59 } 60 $data = json_decode($body, true); 61 if (!array_key_exists('data', $data) || !is_array($data['data'])) { 62 throw new \Exception("Error unexpected response from publisher backend"); 63 } 64 $assigned_channel_response = $data["data"]; 65 return isset($assigned_channel_response["humixChannelId"]) ? (int) $assigned_channel_response["humixChannelId"] : -1; 43 66 } 44 67 … … 110 133 } 111 134 112 $response = \HumixNamespace\RequestUtils::get_middleton_request($wp_query->query_vars['humix_middleton_path']); 135 $path = $wp_query->query_vars['humix_middleton_path']; 136 137 if ($path === self::HOSTING_LIVE_CHECK_ENDPOINT || $path === self::HOSTING_LIVE_CHECK_ENDPOINT . '/') { 138 // This is a live check request from humix.com 139 echo self::HOSTING_LIVE_CHECK_RESPONSE; 140 exit; 141 } 142 143 $response = \HumixNamespace\RequestUtils::get_middleton_request($path); 113 144 if (is_wp_error($response)) { 114 145 \error_log("Humix Plugin Error: Failed to load Humix Channel from middleton: " . $response->get_error_message()); … … 128 159 $output = wp_remote_retrieve_body($response); 129 160 echo $output; 130 exit; // Stop further processing161 exit; 131 162 } 132 163 -
humix/tags/1.5.0/HumixNamespace/Settings.php
r3144450 r3173030 1 1 <?php 2 2 3 Namespace HumixNamespace;4 5 class Settings 3 namespace HumixNamespace; 4 5 class Settings 6 6 { 7 7 8 const PAGE_TITLE = 'Humix Settings'; 9 const MENU_TITLE = 'Humix'; 10 const CAPABILITY = 'manage_options'; 11 const MENU_SLUG = 'humix_settings'; 12 13 const PREFIX = 'humix_plugin_'; 14 const GROUP_SUFFIX = '_group'; 15 const SECTION_SUFFIX = '_section'; 16 const PAGE_SUFFIX = '_page'; 17 18 const CHANNEL_SETTINGS = self::PREFIX.'channel_settings'; 19 const CHANNEL_SETTINGS_GROUP = self::CHANNEL_SETTINGS.self::GROUP_SUFFIX; 20 const CHANNEL_SETTINGS_SECTION = self::CHANNEL_SETTINGS.self::SECTION_SUFFIX; 21 const CHANNEL_SETTINGS_PAGE = self::CHANNEL_SETTINGS.self::PAGE_SUFFIX; 22 const ASSIGNED_CHANNEL_ID_OPTION = self::PREFIX.'assigned_channel_id'; 23 24 const ADSTXT_MANAGER_SETTINGS = self::PREFIX.'adstxt_manager'; 25 const ADSTXT_MANAGER_SETTINGS_GROUP = self::ADSTXT_MANAGER_SETTINGS.self::GROUP_SUFFIX; 26 const ADSTXT_MANAGER_SETTINGS_SECTION = self::ADSTXT_MANAGER_SETTINGS.self::SECTION_SUFFIX; 27 const ADSTXT_MANAGE_SETTINGS_PAGE = self::ADSTXT_MANAGER_SETTINGS.self::PAGE_SUFFIX; 28 const ADSTXT_MANAGER_ID_OPTION = self::PREFIX.'adxtxt_manager_id'; 29 30 const INSERT_ON_ALL_PAGES_OPTION = self::PREFIX.'insert_on_all_pages'; 31 const VIDEO_INSERT_SETTINGS = self::PREFIX.'video_insert_settings'; 32 const VIDEO_INSERT_SETTINGS_GROUP = self::VIDEO_INSERT_SETTINGS.self::GROUP_SUFFIX; 33 const VIDEO_INSERT_SETTINGS_SECTION = self::VIDEO_INSERT_SETTINGS.self::SECTION_SUFFIX; 34 const VIDEO_INSERT_SETTINGS_PAGE = self::VIDEO_INSERT_SETTINGS.self::PAGE_SUFFIX; 35 36 public static function get_assigned_channel_id() { 37 return (int) \get_option(self::ASSIGNED_CHANNEL_ID_OPTION, -1); 38 } 39 40 public static function get_adstxt_manager_id() { 41 return (int) \get_option(self::ADSTXT_MANAGER_ID_OPTION, -1); 42 } 43 44 public static function get_insert_on_all_pages() { 8 const PAGE_TITLE = 'Humix Settings'; 9 const MENU_TITLE = 'Humix'; 10 const CAPABILITY = 'manage_options'; 11 const MENU_SLUG = 'humix_settings'; 12 13 const PREFIX = 'humix_plugin_'; 14 const GROUP_SUFFIX = '_group'; 15 const SECTION_SUFFIX = '_section'; 16 const PAGE_SUFFIX = '_page'; 17 18 const CHANNEL_SETTINGS = self::PREFIX . 'channel_settings'; 19 const CHANNEL_SETTINGS_GROUP = self::CHANNEL_SETTINGS . self::GROUP_SUFFIX; 20 const CHANNEL_SETTINGS_SECTION = self::CHANNEL_SETTINGS . self::SECTION_SUFFIX; 21 const CHANNEL_SETTINGS_PAGE = self::CHANNEL_SETTINGS . self::PAGE_SUFFIX; 22 const ASSIGNED_CHANNEL_ID_OPTION = self::PREFIX . 'assigned_channel_id'; 23 24 const ADSTXT_MANAGER_SETTINGS = self::PREFIX . 'adstxt_manager'; 25 const ADSTXT_MANAGER_SETTINGS_GROUP = self::ADSTXT_MANAGER_SETTINGS . self::GROUP_SUFFIX; 26 const ADSTXT_MANAGER_SETTINGS_SECTION = self::ADSTXT_MANAGER_SETTINGS . self::SECTION_SUFFIX; 27 const ADSTXT_MANAGE_SETTINGS_PAGE = self::ADSTXT_MANAGER_SETTINGS . self::PAGE_SUFFIX; 28 const ADSTXT_MANAGER_ID_OPTION = self::PREFIX . 'adxtxt_manager_id'; 29 30 const INSERT_ON_ALL_PAGES_OPTION = self::PREFIX . 'insert_on_all_pages'; 31 const VIDEO_INSERT_SETTINGS = self::PREFIX . 'video_insert_settings'; 32 const VIDEO_INSERT_SETTINGS_GROUP = self::VIDEO_INSERT_SETTINGS . self::GROUP_SUFFIX; 33 const VIDEO_INSERT_SETTINGS_SECTION = self::VIDEO_INSERT_SETTINGS . self::SECTION_SUFFIX; 34 const VIDEO_INSERT_SETTINGS_PAGE = self::VIDEO_INSERT_SETTINGS . self::PAGE_SUFFIX; 35 36 public static function get_assigned_channel_id() 37 { 38 return (int) \get_option(self::ASSIGNED_CHANNEL_ID_OPTION, -1); 39 } 40 41 public static function update_assigned_channel_id($val) 42 { 43 $val = (int) $val; 44 if ($val === 0 || $val < -1) { 45 throw new \InvalidArgumentException("Invalid channel ID supplied"); 46 } 47 \update_option(self::ASSIGNED_CHANNEL_ID_OPTION, $val); 48 if ($val > 0) { 49 (new \HumixNamespace\Channels())->setup_middleton_paths(); 50 } else { 51 (new \HumixNamespace\Channels())->remove_middleton_paths(); 52 } 53 } 54 55 public static function get_adstxt_manager_id() 56 { 57 return (int) \get_option(self::ADSTXT_MANAGER_ID_OPTION, -1); 58 } 59 60 public static function get_insert_on_all_pages() 61 { 45 62 return (bool) \get_option(self::INSERT_ON_ALL_PAGES_OPTION, false); 46 63 } 47 64 48 public static function set_adstxt_redirect() { 65 public static function set_adstxt_redirect() 66 { 49 67 if (self::get_adstxt_manager_id() <= 0) { 50 68 return; … … 53 71 } 54 72 55 public static function adstxt_redirect() { 73 public static function adstxt_redirect() 74 { 56 75 global $wp; 57 76 $isAdsTxtRequest = isset($wp->request) && $wp->request === 'ads.txt'; 58 if(!$isAdsTxtRequest) {77 if (!$isAdsTxtRequest) { 59 78 return; 60 79 } … … 65 84 $domain = \wp_parse_url(\get_site_url(), PHP_URL_HOST); 66 85 $domain = preg_replace('/^www\./', '', $domain); 67 \wp_redirect( 'https://srv.adstxtmanager.com/' . $adstxt_manager_id . '/' . $domain, 301);86 \wp_redirect('https://srv.adstxtmanager.com/' . $adstxt_manager_id . '/' . $domain, 301); 68 87 exit(); 69 88 } 70 89 71 public static function add_auto_insert_script_to_head() { 90 public static function add_auto_insert_script_to_head() 91 { 72 92 if (!self::get_insert_on_all_pages()) { 73 93 return; 74 94 } 75 95 ?> 76 <script>(window.humixPlayers = window.humixPlayers || []).push({target: 'autoinsert'});</script> 77 <script async data-cfasync="false" src='https://www.humix.com/video.js'></script> 78 <?php 79 } 80 81 public static function delete_settings() { 96 <script>(window.humixPlayers = window.humixPlayers || []).push({ target: 'autoinsert', isGenerated: true });</script> 97 <script async data-cfasync="false" src='https://www.humix.com/video.js'></script> 98 <?php 99 } 100 101 public static function delete_settings() 102 { 82 103 $pluginSettings = array( 83 104 self::ASSIGNED_CHANNEL_ID_OPTION, … … 94 115 } 95 116 96 public static function show_settings_page() { 97 // For now, we only need to show the settings page if the domain is a Humix Direct domain. 98 $auth = new \HumixNamespace\Authentication(); 99 $token = $auth->get_token_from_publisher_backend(); 100 $is_humix_direct_domain = false; 101 try { 117 public static function show_settings_page() 118 { 119 // For now, we only need to show the settings page if the domain is a Humix Direct domain. 120 $auth = new \HumixNamespace\Authentication(); 121 $token = $auth->get_token_from_publisher_backend(); 122 $is_humix_direct_domain = false; 123 try { 102 124 // note: this will now return true if the domain is SA integrated or whitelisted as a test/demo domain 103 $is_humix_direct_domain = $auth->is_humix_direct_domain($token); 104 } catch (\InvalidArgumentException $ae) { 105 \error_log("Humix Plugin Error: Invalid Token supplied from Authentication Service"); 106 return false; 107 } catch (\Exception $e) { 108 \error_log("Humix Plugin Error: " . $e->getMessage()); 109 return false; 110 } 111 112 return $is_humix_direct_domain; 113 } 114 115 public static function init_settings_page() { 116 if(!self::show_settings_page()) { 125 $is_humix_direct_domain = $auth->is_humix_direct_domain($token); 126 } catch (\InvalidArgumentException $ae) { 127 \error_log("Humix Plugin Error: Invalid Token supplied from Authentication Service"); 128 return false; 129 } catch (\Exception $e) { 130 \error_log("Humix Plugin Error: " . $e->getMessage()); 131 return false; 132 } 133 134 return $is_humix_direct_domain; 135 } 136 137 public static function init_settings_page() 138 { 139 if (!self::show_settings_page()) { 117 140 // for non Humix Direct domains we do not show the settings page since they are all domain-specific 118 141 return; 119 142 } 120 \add_options_page(self::PAGE_TITLE, self::MENU_TITLE, self::CAPABILITY, self::MENU_SLUG, array(self::class, 'humix_plugin_options_page')); 121 \add_action('admin_init', array(self::class, 'humix_plugin_settings_init')); 122 } 123 124 public static function add_plugin_settings_link($links) { 125 if(!self::show_settings_page()) { 143 \add_options_page(self::PAGE_TITLE, self::MENU_TITLE, self::CAPABILITY, self::MENU_SLUG, array(self::class, 'humix_plugin_options_page')); 144 \add_action('admin_init', array(self::class, 'humix_plugin_settings_init')); 145 } 146 147 public static function add_plugin_settings_link($links) 148 { 149 if (!self::show_settings_page()) { 126 150 // for non Humix Direct domains we do not show the settings page since they are all domain-specific 127 151 return $links; 128 152 } 129 153 $humix_direct_link = '<a href="https://app.humix.com/site/" target="_blank">Humix Dashboard</a>'; 130 array_unshift($links, $humix_direct_link);131 $settings_link = '<a href="options-general.php?page=' .self::MENU_SLUG.'">Settings</a>';132 array_unshift($links, $settings_link);133 return $links;134 }135 136 public static function humix_plugin_settings_init()137 {138 // video insert settings tab154 array_unshift($links, $humix_direct_link); 155 $settings_link = '<a href="options-general.php?page=' . self::MENU_SLUG . '">Settings</a>'; 156 array_unshift($links, $settings_link); 157 return $links; 158 } 159 160 public static function humix_plugin_settings_init() 161 { 162 // video insert settings tab 139 163 \register_setting(self::VIDEO_INSERT_SETTINGS_GROUP, self::INSERT_ON_ALL_PAGES_OPTION); 140 164 \add_settings_section(self::VIDEO_INSERT_SETTINGS_SECTION, null, null, self::VIDEO_INSERT_SETTINGS_PAGE); 141 165 \add_settings_field(self::INSERT_ON_ALL_PAGES_OPTION, '', array(self::class, 'render_insert_on_all_pages_option'), self::VIDEO_INSERT_SETTINGS_PAGE, self::VIDEO_INSERT_SETTINGS_SECTION); 142 166 143 167 // channel settings tab 144 \register_setting(self::CHANNEL_SETTINGS_GROUP, self::ASSIGNED_CHANNEL_ID_OPTION); 145 \add_settings_section(self::CHANNEL_SETTINGS_SECTION, null, null, self::CHANNEL_SETTINGS_PAGE); 146 \add_settings_field(self::ASSIGNED_CHANNEL_ID_OPTION, 'Channel', array(self::class, 'render_assigned_channel_id_option'), self::CHANNEL_SETTINGS_PAGE, self::CHANNEL_SETTINGS_SECTION); 147 \add_action('pre_update_option_'.self::ASSIGNED_CHANNEL_ID_OPTION, array(self::class, 'on_assigned_channel_id_option_change'), 10, 3); 148 149 // ads.txt manager settings tab 150 \register_setting(self::ADSTXT_MANAGER_SETTINGS_GROUP, self::ADSTXT_MANAGER_ID_OPTION); 151 \add_settings_section(self::ADSTXT_MANAGER_SETTINGS_SECTION, null, null, self::ADSTXT_MANAGE_SETTINGS_PAGE); 152 \add_settings_field(self::ADSTXT_MANAGER_ID_OPTION, 'ID Number', array(self::class, 'render_adstxt_manager_id_option'), self::ADSTXT_MANAGE_SETTINGS_PAGE, self::ADSTXT_MANAGER_SETTINGS_SECTION); 153 \add_action('pre_update_option_'.self::ADSTXT_MANAGER_ID_OPTION, array(self::class, 'on_adstxt_manager_id_option_change'), 10, 3); 154 } 155 156 public static function is_using_plain_permalinks() { 157 global $wp_rewrite; 168 \register_setting(self::CHANNEL_SETTINGS_GROUP, self::ASSIGNED_CHANNEL_ID_OPTION); 169 \add_settings_section(self::CHANNEL_SETTINGS_SECTION, null, null, self::CHANNEL_SETTINGS_PAGE); 170 \add_settings_field(self::ASSIGNED_CHANNEL_ID_OPTION, 'Channel', array(self::class, 'render_assigned_channel_id_option'), self::CHANNEL_SETTINGS_PAGE, self::CHANNEL_SETTINGS_SECTION); 171 \add_action('pre_update_option_' . self::ASSIGNED_CHANNEL_ID_OPTION, array(self::class, 'on_assigned_channel_id_option_change'), 10, 3); 172 173 // ads.txt manager settings tab 174 \register_setting(self::ADSTXT_MANAGER_SETTINGS_GROUP, self::ADSTXT_MANAGER_ID_OPTION); 175 \add_settings_section(self::ADSTXT_MANAGER_SETTINGS_SECTION, null, null, self::ADSTXT_MANAGE_SETTINGS_PAGE); 176 \add_settings_field(self::ADSTXT_MANAGER_ID_OPTION, 'ID Number', array(self::class, 'render_adstxt_manager_id_option'), self::ADSTXT_MANAGE_SETTINGS_PAGE, self::ADSTXT_MANAGER_SETTINGS_SECTION); 177 \add_action('pre_update_option_' . self::ADSTXT_MANAGER_ID_OPTION, array(self::class, 'on_adstxt_manager_id_option_change'), 10, 3); 178 } 179 180 public static function is_using_plain_permalinks() 181 { 182 global $wp_rewrite; 158 183 return !$wp_rewrite->using_permalinks(); 159 184 } 160 185 161 public static function show_permalinks_unsupported_notice() { 186 public static function show_permalinks_unsupported_notice() 187 { 162 188 ?> 163 189 <div id="setting-error-permalinks_unsupported" class="notice notice-error settings-error"> 164 <p><strong>Notice:</strong> "Plain" permalinks structure is not supported for Humix Channel and Ads.txt features, please update your permalinks structure to use these features</p> 190 <p><strong>Notice:</strong> "Plain" permalinks structure is not supported for Humix Channel and Ads.txt features, 191 please update your permalinks structure to use these features</p> 165 192 </div> 166 193 <?php … … 168 195 169 196 const VIDEO_INSERT_SETTINGS_TAB = 'video_insert_settings'; 170 const CHANNEL_SETTINGS_TAB = 'channel_settings'; 171 const ADSTXT_SETTINGS_TAB = 'adstxt_settings'; 172 const DEFAULT_SELECTED_TAB = self::VIDEO_INSERT_SETTINGS_TAB; 173 174 public static function humix_plugin_options_page() { 175 if(self::is_using_plain_permalinks()) { 197 const CHANNEL_SETTINGS_TAB = 'channel_settings'; 198 const ADSTXT_SETTINGS_TAB = 'adstxt_settings'; 199 const DEFAULT_SELECTED_TAB = self::VIDEO_INSERT_SETTINGS_TAB; 200 201 public static function humix_plugin_options_page() 202 { 203 if (self::is_using_plain_permalinks()) { 176 204 // we do not support plain permalinks for the settings features 177 205 self::show_permalinks_unsupported_notice(); 178 206 } 179 ?> 180 <div class="wrap"> 181 <p> 182 <img alt="Humix Logo" src="https://assets.humix.com/full_humix_logo.png" /> 183 </p> 184 <?php 185 $active_tab = self::DEFAULT_SELECTED_TAB; 186 $tmp_active_tab = isset($_GET['tab']) ? $_GET['tab'] : ''; 187 if (in_array($tmp_active_tab, array(self::CHANNEL_SETTINGS_TAB, self::ADSTXT_SETTINGS_TAB))) { 188 $active_tab = $tmp_active_tab; 189 } 190 ?> 191 <h2 class="nav-tab-wrapper"> 192 <a href="?page=<?php echo self::MENU_SLUG ?>&tab=<?php echo self::VIDEO_INSERT_SETTINGS_TAB ?>" 193 class="nav-tab <?php echo $active_tab == self::VIDEO_INSERT_SETTINGS_TAB ? 'nav-tab-active' : ''; ?>">Video Insert Settings</a> 194 <a href="?page=<?php echo self::MENU_SLUG ?>&tab=<?php echo self::CHANNEL_SETTINGS_TAB ?>" 195 class="nav-tab <?php echo $active_tab == self::CHANNEL_SETTINGS_TAB ? 'nav-tab-active' : ''; ?>">Channel Settings</a> 196 <a href="?page=<?php echo self::MENU_SLUG ?>&tab=<?php echo self::ADSTXT_SETTINGS_TAB ?>" 197 class="nav-tab <?php echo $active_tab == self::ADSTXT_SETTINGS_TAB ? 'nav-tab-active' : ''; ?>">Ads.txt Manager</a> 198 199 200 <a href="https://support.ezoic.com/kb/category/video-humix-studio" target="_blank" class="nav-tab" style="float: right;"> 201 Help Center 202 </a> 203 <a href="https://login.humix.com/" target="_blank" class="nav-tab" style="float: right;"> 204 Humix Dashboard 205 </a> 206 </h2> 207 <?php 208 switch($active_tab) { 209 case self::VIDEO_INSERT_SETTINGS_TAB: 210 self::render_video_insert_settings_tab(); 211 break; 212 case self::CHANNEL_SETTINGS_TAB: 213 self::render_channel_settings_tab(); 214 break; 215 case self::ADSTXT_SETTINGS_TAB: 216 self::render_adstxt_manager_settings_tab(); 217 break; 218 default: 219 self::render_video_insert_settings_tab(); 220 break; 221 } 222 ?> 223 </div> 224 <?php 225 } 226 227 public static function render_video_insert_settings_tab() { 207 ?> 208 <div class="wrap"> 209 <p> 210 <img alt="Humix Logo" src="https://assets.humix.com/full_humix_logo.png" /> 211 </p> 212 <?php 213 $active_tab = self::DEFAULT_SELECTED_TAB; 214 $tmp_active_tab = isset($_GET['tab']) ? $_GET['tab'] : ''; 215 if (in_array($tmp_active_tab, array(self::CHANNEL_SETTINGS_TAB, self::ADSTXT_SETTINGS_TAB))) { 216 $active_tab = $tmp_active_tab; 217 } 218 ?> 219 <h2 class="nav-tab-wrapper"> 220 <a href="?page=<?php echo self::MENU_SLUG ?>&tab=<?php echo self::VIDEO_INSERT_SETTINGS_TAB ?>" 221 class="nav-tab <?php echo $active_tab == self::VIDEO_INSERT_SETTINGS_TAB ? 'nav-tab-active' : ''; ?>">Video 222 Insert Settings</a> 223 <a href="?page=<?php echo self::MENU_SLUG ?>&tab=<?php echo self::CHANNEL_SETTINGS_TAB ?>" 224 class="nav-tab <?php echo $active_tab == self::CHANNEL_SETTINGS_TAB ? 'nav-tab-active' : ''; ?>">Channel 225 Settings</a> 226 <a href="?page=<?php echo self::MENU_SLUG ?>&tab=<?php echo self::ADSTXT_SETTINGS_TAB ?>" 227 class="nav-tab <?php echo $active_tab == self::ADSTXT_SETTINGS_TAB ? 'nav-tab-active' : ''; ?>">Ads.txt 228 Manager</a> 229 230 231 <a href="https://support.ezoic.com/kb/category/video-humix-studio" target="_blank" class="nav-tab" 232 style="float: right;"> 233 Help Center 234 </a> 235 <a href="https://login.humix.com/" target="_blank" class="nav-tab" style="float: right;"> 236 Humix Dashboard 237 </a> 238 </h2> 239 <?php 240 switch ($active_tab) { 241 case self::VIDEO_INSERT_SETTINGS_TAB: 242 self::render_video_insert_settings_tab(); 243 break; 244 case self::CHANNEL_SETTINGS_TAB: 245 self::render_channel_settings_tab(); 246 break; 247 case self::ADSTXT_SETTINGS_TAB: 248 self::render_adstxt_manager_settings_tab(); 249 break; 250 default: 251 self::render_video_insert_settings_tab(); 252 break; 253 } 254 ?> 255 </div> 256 <?php 257 } 258 259 public static function render_video_insert_settings_tab() 260 { 228 261 ?> 229 262 <div class="wrap"> … … 231 264 <p class="notice notice-info" style="padding: 15px;"> 232 265 Automatically insert videos on all pages in this site. 233 <br/> 234 To configure the behavior and placement of the auto-inserted videos, visit the <a href="https://app.humix.com/site/settings/content-settings" target="_blank">Humix Dashboard</a>. 266 <br /> 267 To configure the behavior and placement of the auto-inserted videos, visit the <a 268 href="https://app.humix.com/site/settings/content-settings" target="_blank">Humix Dashboard</a>. 235 269 </p> 236 270 <form action="options.php" method="post"> … … 252 286 <h2>Channel Settings</h2> 253 287 <p class="notice notice-info" style="padding: 15px;"> 254 Select a channel from your account below to display on this site at <a href="<?php echo $channel_page; ?>" target="_blank"><?php echo $channel_page; ?></a> 288 Select a channel from your account below to display on this site at <a href="<?php echo $channel_page; ?>" 289 target="_blank"><?php echo $channel_page; ?></a> 255 290 </p> 256 291 <form action="options.php" method="post"> … … 274 309 <br> 275 310 <br> 276 If you are setting up via the Humix dashboard, you can put in <code>70772</code> as the ID. If you created an account with <a href="https://www.adstxtmanager.com/" target="_blank">adstxtmanager.com</a>, click <a href="https://www.adstxtmanager.com/" target="_blank">here</a> to login and access your ID. 311 If you are setting up via the Humix dashboard, you can put in <code>70772</code> as the ID. If you created an 312 account with <a href="https://www.adstxtmanager.com/" target="_blank">adstxtmanager.com</a>, click <a 313 href="https://www.adstxtmanager.com/" target="_blank">here</a> to login and access your ID. 277 314 </p> 278 315 <form action="options.php" method="post"> … … 287 324 } 288 325 289 public static function render_insert_on_all_pages_option(){ 290 ?> 291 <span style="position: absolute; left: 0; margin: 0 15px;"> 292 <input id="insert-on-all-pages" type="checkbox" name="<?php echo self::INSERT_ON_ALL_PAGES_OPTION; ?>" <?php \checked(self::get_insert_on_all_pages(), true); ?>> 326 public static function render_insert_on_all_pages_option() 327 { 328 ?> 329 <span style="position: absolute; left: 0; margin: 0 15px;"> 330 <input id="insert-on-all-pages" type="checkbox" name="<?php echo self::INSERT_ON_ALL_PAGES_OPTION; ?>" <?php \checked(self::get_insert_on_all_pages(), true); ?>> 293 331 <label for="insert-on-all-pages">Automatically insert video on all pages</label> 294 </span>295 <br/>296 <?php332 </span> 333 <br /> 334 <?php 297 335 } 298 336 299 337 public static function render_assigned_channel_id_option() 300 {301 $auth = new \HumixNamespace\Authentication();302 $token = $auth->get_token_from_publisher_backend();303 $channels = [];338 { 339 $auth = new \HumixNamespace\Authentication(); 340 $token = $auth->get_token_from_publisher_backend(); 341 $channels = []; 304 342 $load_channels_err = false; 305 try {306 $channels = (new \HumixNamespace\Channels())->get_channels($token);307 } catch (\Exception $e) {308 \error_log("Humix Plugin Error: Failed to load channels: " . $e->getMessage());309 $load_channels_err = true;310 }343 try { 344 $channels = (new \HumixNamespace\Channels())->get_channels($token); 345 } catch (\Exception $e) { 346 \error_log("Humix Plugin Error: Failed to load channels: " . $e->getMessage()); 347 $load_channels_err = true; 348 } 311 349 312 350 if ($load_channels_err || empty($channels)) { 313 351 ?> 314 <div id="setting-error-api_error" class="notice notice-error settings-error">315 <p><strong>Failed to load your channels from your account. Please refresh the page and try again.</strong></p>316 </div>317 <?php318 return;319 } 320 321 $selected_channel_id = self::get_assigned_channel_id();322 ?>323 <select name="<?php echo self::ASSIGNED_CHANNEL_ID_OPTION; ?>">324 <option value="-1" <?php \selected($selected_channel_id, -1); ?>>325 <?php326 echo (int) $selected_channel_id === -1 ? "Select a channel" : "Remove channel from this site";327 ?>328 </option>329 <?php foreach ($channels as $channel): ?>330 <option value="<?php echo \esc_attr($channel['humixChannelId']); ?>" <?php \selected($selected_channel_id, $channel['humixChannelId']); ?>>331 <?php echo \esc_html($channel['name']); ?>332 </option>333 <?php endforeach; ?>334 </select>335 <?php336 }352 <div id="setting-error-api_error" class="notice notice-error settings-error"> 353 <p><strong>Failed to load your channels from your account. Please refresh the page and try again.</strong></p> 354 </div> 355 <?php 356 return; 357 } 358 359 $selected_channel_id = self::get_assigned_channel_id(); 360 ?> 361 <select name="<?php echo self::ASSIGNED_CHANNEL_ID_OPTION; ?>"> 362 <option value="-1" <?php \selected($selected_channel_id, -1); ?>> 363 <?php 364 echo (int) $selected_channel_id === -1 ? "Select a channel" : "Remove channel from this site"; 365 ?> 366 </option> 367 <?php foreach ($channels as $channel): ?> 368 <option value="<?php echo \esc_attr($channel['humixChannelId']); ?>" <?php \selected($selected_channel_id, $channel['humixChannelId']); ?>> 369 <?php echo \esc_html($channel['name']); ?> 370 </option> 371 <?php endforeach; ?> 372 </select> 373 <?php 374 } 337 375 338 376 public static function render_adstxt_manager_id_option() 339 377 { 340 378 $selected_option = self::get_adstxt_manager_id() 341 ?>342 <input name="<?php echo self::ADSTXT_MANAGER_ID_OPTION; ?>" class="regular-text code" placeholder="Enter your Ads.txt Manager ID..."343 <?php344 if($selected_option > 0) {345 echo 'value="' . $selected_option . '"';346 }347 379 ?> 348 ></input> 380 <input name="<?php echo self::ADSTXT_MANAGER_ID_OPTION; ?>" class="regular-text code" 381 placeholder="Enter your Ads.txt Manager ID..." <?php 382 if ($selected_option > 0) { 383 echo 'value="' . $selected_option . '"'; 384 } 385 ?>></input> 349 386 <?php 350 387 } … … 388 425 389 426 // Allow user to pass empty string (or 0) to effectively clear out the value 390 if ($new_adstxt_manager_id === "") {427 if ($new_adstxt_manager_id === "") { 391 428 $new_adstxt_manager_id = 0; 392 429 } -
humix/tags/1.5.0/README.txt
r3144450 r3173030 4 4 Tags: humix, video, embed, network 5 5 Requires at least: 5.8.0 6 Tested up to: 6. 56 Tested up to: 6.6 7 7 Requires PHP: 7.0 8 Stable tag: 1. 4.18 Stable tag: 1.5.0 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 23 23 24 24 == Changelog == 25 = 1.5.0 = 26 * Improvements to channel hosting setup process 27 25 28 = 1.4.1 = 26 29 * Changed adstxtmanager ID -
humix/tags/1.5.0/humix.php
r3144450 r3173030 5 5 require "HumixNamespace/Channels.php"; 6 6 require "HumixNamespace/Settings.php"; 7 require "HumixNamespace/RestApi.php"; 7 8 8 9 /** … … 15 16 * 16 17 * @link https://www.humix.com/ 17 * @since 1. 4.118 * @since 1.5.0 18 19 * @package Humix 19 20 * … … 22 23 * Plugin URI: https://wordpress.org/plugins/humix 23 24 * Description: Humix allows you to easily embed videos to your site from the Humix Network. 24 * Version: 1. 4.125 * Version: 1.5.0 25 26 * Author: Humix 26 27 * Author URI: https://www.humix.com/ … … 39 40 * Rename this for your plugin and update it as you release new versions. 40 41 */ 41 define('HUMIX_VERSION', '1. 4.1');42 define('HUMIX_VERSION', '1.5.0'); 42 43 43 44 global $EZHX_REGEX; … … 62 63 \HumixNamespace\Authentication::register(); 63 64 65 // register API endpoitns 66 \HumixNamespace\RestApi::register(); 67 64 68 // handle rewrite rules for middleton requests appropriately 65 69 $assigned_humix_channel_id = \HumixNamespace\Settings::get_assigned_channel_id(); … … 76 80 } 77 81 82 // handle insert videos on all pages if enabled 78 83 $insert_on_all_pages = \HumixNamespace\Settings::get_insert_on_all_pages(); 79 84 if ($insert_on_all_pages) { -
humix/trunk/HumixNamespace/Authentication.php
r3129709 r3173030 23 23 add_action('rest_api_init', function () { 24 24 register_rest_route( 25 'humix/v1',25 RestApi::REST_API_BASE, 26 26 '/auth/verify', 27 array (27 array( 28 28 'methods' => \WP_REST_SERVER::READABLE, 29 'callback' => array (self::class, 'verify_handler'),29 'callback' => array(self::class, 'verify_handler'), 30 30 'permission_callback' => '__return_true', 31 31 'show_in_index' => false … … 33 33 ); 34 34 }); 35 36 35 } 37 36 … … 151 150 } 152 151 153 public function is_humix_direct_domain($token) { 152 public function is_humix_direct_domain($token) 153 { 154 154 // we have to cache result as string since an empty cache returns false, so we can't differentiate between false and not cached 155 155 $cached_result_as_str = get_transient(self::IS_HUMIX_DIRECT); -
humix/trunk/HumixNamespace/Channels.php
r3129709 r3173030 10 10 const MY_CHANNELS_CACHE_KEY = "humix_plugin:my_channels"; 11 11 const MY_CHANNELS_CACHE_TTL = 12 * 3600; // 12 hours 12 const MIDDLETON_REWRITE_RULE_REGEX = '^(humix|beardeddragon|ezoimgfmt)/?(.*)?$'; 12 const HOSTING_LIVE_CHECK_ENDPOINT = "_humix_integration_check"; 13 const HOSTING_LIVE_CHECK_RESPONSE = "humix-integration-ok"; 14 const MIDDLETON_REWRITE_RULE_REGEX = '^(humix|beardeddragon|ezoimgfmt|_humix_integration_check)/?(.*)?$'; 13 15 14 16 public function update_assigned_channel($token, $new_channel_id) … … 31 33 } 32 34 33 function remove_assigned_channel($token)35 public function remove_assigned_channel($token) 34 36 { 35 37 if ($token === "") { … … 41 43 } 42 44 self::remove_middleton_paths(); 45 } 46 47 public function get_assigned_channel_from_publisher_backend($token) 48 { 49 if ($token === "") { 50 throw new \InvalidArgumentException("Token is empty"); 51 } 52 $response = \HumixNamespace\RequestUtils::publisher_backend_request($token, 'assigned-channel', 'GET'); 53 if (is_wp_error($response)) { 54 throw new \Exception("Error communicating with publisher backend: " . $response->get_error_message()); 55 } 56 $body = wp_remote_retrieve_body($response); 57 if (!$body) { 58 throw new \Exception("Error empty response from publisher backend"); 59 } 60 $data = json_decode($body, true); 61 if (!array_key_exists('data', $data) || !is_array($data['data'])) { 62 throw new \Exception("Error unexpected response from publisher backend"); 63 } 64 $assigned_channel_response = $data["data"]; 65 return isset($assigned_channel_response["humixChannelId"]) ? (int) $assigned_channel_response["humixChannelId"] : -1; 43 66 } 44 67 … … 110 133 } 111 134 112 $response = \HumixNamespace\RequestUtils::get_middleton_request($wp_query->query_vars['humix_middleton_path']); 135 $path = $wp_query->query_vars['humix_middleton_path']; 136 137 if ($path === self::HOSTING_LIVE_CHECK_ENDPOINT || $path === self::HOSTING_LIVE_CHECK_ENDPOINT . '/') { 138 // This is a live check request from humix.com 139 echo self::HOSTING_LIVE_CHECK_RESPONSE; 140 exit; 141 } 142 143 $response = \HumixNamespace\RequestUtils::get_middleton_request($path); 113 144 if (is_wp_error($response)) { 114 145 \error_log("Humix Plugin Error: Failed to load Humix Channel from middleton: " . $response->get_error_message()); … … 128 159 $output = wp_remote_retrieve_body($response); 129 160 echo $output; 130 exit; // Stop further processing161 exit; 131 162 } 132 163 -
humix/trunk/HumixNamespace/Settings.php
r3144450 r3173030 1 1 <?php 2 2 3 Namespace HumixNamespace;4 5 class Settings 3 namespace HumixNamespace; 4 5 class Settings 6 6 { 7 7 8 const PAGE_TITLE = 'Humix Settings'; 9 const MENU_TITLE = 'Humix'; 10 const CAPABILITY = 'manage_options'; 11 const MENU_SLUG = 'humix_settings'; 12 13 const PREFIX = 'humix_plugin_'; 14 const GROUP_SUFFIX = '_group'; 15 const SECTION_SUFFIX = '_section'; 16 const PAGE_SUFFIX = '_page'; 17 18 const CHANNEL_SETTINGS = self::PREFIX.'channel_settings'; 19 const CHANNEL_SETTINGS_GROUP = self::CHANNEL_SETTINGS.self::GROUP_SUFFIX; 20 const CHANNEL_SETTINGS_SECTION = self::CHANNEL_SETTINGS.self::SECTION_SUFFIX; 21 const CHANNEL_SETTINGS_PAGE = self::CHANNEL_SETTINGS.self::PAGE_SUFFIX; 22 const ASSIGNED_CHANNEL_ID_OPTION = self::PREFIX.'assigned_channel_id'; 23 24 const ADSTXT_MANAGER_SETTINGS = self::PREFIX.'adstxt_manager'; 25 const ADSTXT_MANAGER_SETTINGS_GROUP = self::ADSTXT_MANAGER_SETTINGS.self::GROUP_SUFFIX; 26 const ADSTXT_MANAGER_SETTINGS_SECTION = self::ADSTXT_MANAGER_SETTINGS.self::SECTION_SUFFIX; 27 const ADSTXT_MANAGE_SETTINGS_PAGE = self::ADSTXT_MANAGER_SETTINGS.self::PAGE_SUFFIX; 28 const ADSTXT_MANAGER_ID_OPTION = self::PREFIX.'adxtxt_manager_id'; 29 30 const INSERT_ON_ALL_PAGES_OPTION = self::PREFIX.'insert_on_all_pages'; 31 const VIDEO_INSERT_SETTINGS = self::PREFIX.'video_insert_settings'; 32 const VIDEO_INSERT_SETTINGS_GROUP = self::VIDEO_INSERT_SETTINGS.self::GROUP_SUFFIX; 33 const VIDEO_INSERT_SETTINGS_SECTION = self::VIDEO_INSERT_SETTINGS.self::SECTION_SUFFIX; 34 const VIDEO_INSERT_SETTINGS_PAGE = self::VIDEO_INSERT_SETTINGS.self::PAGE_SUFFIX; 35 36 public static function get_assigned_channel_id() { 37 return (int) \get_option(self::ASSIGNED_CHANNEL_ID_OPTION, -1); 38 } 39 40 public static function get_adstxt_manager_id() { 41 return (int) \get_option(self::ADSTXT_MANAGER_ID_OPTION, -1); 42 } 43 44 public static function get_insert_on_all_pages() { 8 const PAGE_TITLE = 'Humix Settings'; 9 const MENU_TITLE = 'Humix'; 10 const CAPABILITY = 'manage_options'; 11 const MENU_SLUG = 'humix_settings'; 12 13 const PREFIX = 'humix_plugin_'; 14 const GROUP_SUFFIX = '_group'; 15 const SECTION_SUFFIX = '_section'; 16 const PAGE_SUFFIX = '_page'; 17 18 const CHANNEL_SETTINGS = self::PREFIX . 'channel_settings'; 19 const CHANNEL_SETTINGS_GROUP = self::CHANNEL_SETTINGS . self::GROUP_SUFFIX; 20 const CHANNEL_SETTINGS_SECTION = self::CHANNEL_SETTINGS . self::SECTION_SUFFIX; 21 const CHANNEL_SETTINGS_PAGE = self::CHANNEL_SETTINGS . self::PAGE_SUFFIX; 22 const ASSIGNED_CHANNEL_ID_OPTION = self::PREFIX . 'assigned_channel_id'; 23 24 const ADSTXT_MANAGER_SETTINGS = self::PREFIX . 'adstxt_manager'; 25 const ADSTXT_MANAGER_SETTINGS_GROUP = self::ADSTXT_MANAGER_SETTINGS . self::GROUP_SUFFIX; 26 const ADSTXT_MANAGER_SETTINGS_SECTION = self::ADSTXT_MANAGER_SETTINGS . self::SECTION_SUFFIX; 27 const ADSTXT_MANAGE_SETTINGS_PAGE = self::ADSTXT_MANAGER_SETTINGS . self::PAGE_SUFFIX; 28 const ADSTXT_MANAGER_ID_OPTION = self::PREFIX . 'adxtxt_manager_id'; 29 30 const INSERT_ON_ALL_PAGES_OPTION = self::PREFIX . 'insert_on_all_pages'; 31 const VIDEO_INSERT_SETTINGS = self::PREFIX . 'video_insert_settings'; 32 const VIDEO_INSERT_SETTINGS_GROUP = self::VIDEO_INSERT_SETTINGS . self::GROUP_SUFFIX; 33 const VIDEO_INSERT_SETTINGS_SECTION = self::VIDEO_INSERT_SETTINGS . self::SECTION_SUFFIX; 34 const VIDEO_INSERT_SETTINGS_PAGE = self::VIDEO_INSERT_SETTINGS . self::PAGE_SUFFIX; 35 36 public static function get_assigned_channel_id() 37 { 38 return (int) \get_option(self::ASSIGNED_CHANNEL_ID_OPTION, -1); 39 } 40 41 public static function update_assigned_channel_id($val) 42 { 43 $val = (int) $val; 44 if ($val === 0 || $val < -1) { 45 throw new \InvalidArgumentException("Invalid channel ID supplied"); 46 } 47 \update_option(self::ASSIGNED_CHANNEL_ID_OPTION, $val); 48 if ($val > 0) { 49 (new \HumixNamespace\Channels())->setup_middleton_paths(); 50 } else { 51 (new \HumixNamespace\Channels())->remove_middleton_paths(); 52 } 53 } 54 55 public static function get_adstxt_manager_id() 56 { 57 return (int) \get_option(self::ADSTXT_MANAGER_ID_OPTION, -1); 58 } 59 60 public static function get_insert_on_all_pages() 61 { 45 62 return (bool) \get_option(self::INSERT_ON_ALL_PAGES_OPTION, false); 46 63 } 47 64 48 public static function set_adstxt_redirect() { 65 public static function set_adstxt_redirect() 66 { 49 67 if (self::get_adstxt_manager_id() <= 0) { 50 68 return; … … 53 71 } 54 72 55 public static function adstxt_redirect() { 73 public static function adstxt_redirect() 74 { 56 75 global $wp; 57 76 $isAdsTxtRequest = isset($wp->request) && $wp->request === 'ads.txt'; 58 if(!$isAdsTxtRequest) {77 if (!$isAdsTxtRequest) { 59 78 return; 60 79 } … … 65 84 $domain = \wp_parse_url(\get_site_url(), PHP_URL_HOST); 66 85 $domain = preg_replace('/^www\./', '', $domain); 67 \wp_redirect( 'https://srv.adstxtmanager.com/' . $adstxt_manager_id . '/' . $domain, 301);86 \wp_redirect('https://srv.adstxtmanager.com/' . $adstxt_manager_id . '/' . $domain, 301); 68 87 exit(); 69 88 } 70 89 71 public static function add_auto_insert_script_to_head() { 90 public static function add_auto_insert_script_to_head() 91 { 72 92 if (!self::get_insert_on_all_pages()) { 73 93 return; 74 94 } 75 95 ?> 76 <script>(window.humixPlayers = window.humixPlayers || []).push({target: 'autoinsert'});</script> 77 <script async data-cfasync="false" src='https://www.humix.com/video.js'></script> 78 <?php 79 } 80 81 public static function delete_settings() { 96 <script>(window.humixPlayers = window.humixPlayers || []).push({ target: 'autoinsert', isGenerated: true });</script> 97 <script async data-cfasync="false" src='https://www.humix.com/video.js'></script> 98 <?php 99 } 100 101 public static function delete_settings() 102 { 82 103 $pluginSettings = array( 83 104 self::ASSIGNED_CHANNEL_ID_OPTION, … … 94 115 } 95 116 96 public static function show_settings_page() { 97 // For now, we only need to show the settings page if the domain is a Humix Direct domain. 98 $auth = new \HumixNamespace\Authentication(); 99 $token = $auth->get_token_from_publisher_backend(); 100 $is_humix_direct_domain = false; 101 try { 117 public static function show_settings_page() 118 { 119 // For now, we only need to show the settings page if the domain is a Humix Direct domain. 120 $auth = new \HumixNamespace\Authentication(); 121 $token = $auth->get_token_from_publisher_backend(); 122 $is_humix_direct_domain = false; 123 try { 102 124 // note: this will now return true if the domain is SA integrated or whitelisted as a test/demo domain 103 $is_humix_direct_domain = $auth->is_humix_direct_domain($token); 104 } catch (\InvalidArgumentException $ae) { 105 \error_log("Humix Plugin Error: Invalid Token supplied from Authentication Service"); 106 return false; 107 } catch (\Exception $e) { 108 \error_log("Humix Plugin Error: " . $e->getMessage()); 109 return false; 110 } 111 112 return $is_humix_direct_domain; 113 } 114 115 public static function init_settings_page() { 116 if(!self::show_settings_page()) { 125 $is_humix_direct_domain = $auth->is_humix_direct_domain($token); 126 } catch (\InvalidArgumentException $ae) { 127 \error_log("Humix Plugin Error: Invalid Token supplied from Authentication Service"); 128 return false; 129 } catch (\Exception $e) { 130 \error_log("Humix Plugin Error: " . $e->getMessage()); 131 return false; 132 } 133 134 return $is_humix_direct_domain; 135 } 136 137 public static function init_settings_page() 138 { 139 if (!self::show_settings_page()) { 117 140 // for non Humix Direct domains we do not show the settings page since they are all domain-specific 118 141 return; 119 142 } 120 \add_options_page(self::PAGE_TITLE, self::MENU_TITLE, self::CAPABILITY, self::MENU_SLUG, array(self::class, 'humix_plugin_options_page')); 121 \add_action('admin_init', array(self::class, 'humix_plugin_settings_init')); 122 } 123 124 public static function add_plugin_settings_link($links) { 125 if(!self::show_settings_page()) { 143 \add_options_page(self::PAGE_TITLE, self::MENU_TITLE, self::CAPABILITY, self::MENU_SLUG, array(self::class, 'humix_plugin_options_page')); 144 \add_action('admin_init', array(self::class, 'humix_plugin_settings_init')); 145 } 146 147 public static function add_plugin_settings_link($links) 148 { 149 if (!self::show_settings_page()) { 126 150 // for non Humix Direct domains we do not show the settings page since they are all domain-specific 127 151 return $links; 128 152 } 129 153 $humix_direct_link = '<a href="https://app.humix.com/site/" target="_blank">Humix Dashboard</a>'; 130 array_unshift($links, $humix_direct_link);131 $settings_link = '<a href="options-general.php?page=' .self::MENU_SLUG.'">Settings</a>';132 array_unshift($links, $settings_link);133 return $links;134 }135 136 public static function humix_plugin_settings_init()137 {138 // video insert settings tab154 array_unshift($links, $humix_direct_link); 155 $settings_link = '<a href="options-general.php?page=' . self::MENU_SLUG . '">Settings</a>'; 156 array_unshift($links, $settings_link); 157 return $links; 158 } 159 160 public static function humix_plugin_settings_init() 161 { 162 // video insert settings tab 139 163 \register_setting(self::VIDEO_INSERT_SETTINGS_GROUP, self::INSERT_ON_ALL_PAGES_OPTION); 140 164 \add_settings_section(self::VIDEO_INSERT_SETTINGS_SECTION, null, null, self::VIDEO_INSERT_SETTINGS_PAGE); 141 165 \add_settings_field(self::INSERT_ON_ALL_PAGES_OPTION, '', array(self::class, 'render_insert_on_all_pages_option'), self::VIDEO_INSERT_SETTINGS_PAGE, self::VIDEO_INSERT_SETTINGS_SECTION); 142 166 143 167 // channel settings tab 144 \register_setting(self::CHANNEL_SETTINGS_GROUP, self::ASSIGNED_CHANNEL_ID_OPTION); 145 \add_settings_section(self::CHANNEL_SETTINGS_SECTION, null, null, self::CHANNEL_SETTINGS_PAGE); 146 \add_settings_field(self::ASSIGNED_CHANNEL_ID_OPTION, 'Channel', array(self::class, 'render_assigned_channel_id_option'), self::CHANNEL_SETTINGS_PAGE, self::CHANNEL_SETTINGS_SECTION); 147 \add_action('pre_update_option_'.self::ASSIGNED_CHANNEL_ID_OPTION, array(self::class, 'on_assigned_channel_id_option_change'), 10, 3); 148 149 // ads.txt manager settings tab 150 \register_setting(self::ADSTXT_MANAGER_SETTINGS_GROUP, self::ADSTXT_MANAGER_ID_OPTION); 151 \add_settings_section(self::ADSTXT_MANAGER_SETTINGS_SECTION, null, null, self::ADSTXT_MANAGE_SETTINGS_PAGE); 152 \add_settings_field(self::ADSTXT_MANAGER_ID_OPTION, 'ID Number', array(self::class, 'render_adstxt_manager_id_option'), self::ADSTXT_MANAGE_SETTINGS_PAGE, self::ADSTXT_MANAGER_SETTINGS_SECTION); 153 \add_action('pre_update_option_'.self::ADSTXT_MANAGER_ID_OPTION, array(self::class, 'on_adstxt_manager_id_option_change'), 10, 3); 154 } 155 156 public static function is_using_plain_permalinks() { 157 global $wp_rewrite; 168 \register_setting(self::CHANNEL_SETTINGS_GROUP, self::ASSIGNED_CHANNEL_ID_OPTION); 169 \add_settings_section(self::CHANNEL_SETTINGS_SECTION, null, null, self::CHANNEL_SETTINGS_PAGE); 170 \add_settings_field(self::ASSIGNED_CHANNEL_ID_OPTION, 'Channel', array(self::class, 'render_assigned_channel_id_option'), self::CHANNEL_SETTINGS_PAGE, self::CHANNEL_SETTINGS_SECTION); 171 \add_action('pre_update_option_' . self::ASSIGNED_CHANNEL_ID_OPTION, array(self::class, 'on_assigned_channel_id_option_change'), 10, 3); 172 173 // ads.txt manager settings tab 174 \register_setting(self::ADSTXT_MANAGER_SETTINGS_GROUP, self::ADSTXT_MANAGER_ID_OPTION); 175 \add_settings_section(self::ADSTXT_MANAGER_SETTINGS_SECTION, null, null, self::ADSTXT_MANAGE_SETTINGS_PAGE); 176 \add_settings_field(self::ADSTXT_MANAGER_ID_OPTION, 'ID Number', array(self::class, 'render_adstxt_manager_id_option'), self::ADSTXT_MANAGE_SETTINGS_PAGE, self::ADSTXT_MANAGER_SETTINGS_SECTION); 177 \add_action('pre_update_option_' . self::ADSTXT_MANAGER_ID_OPTION, array(self::class, 'on_adstxt_manager_id_option_change'), 10, 3); 178 } 179 180 public static function is_using_plain_permalinks() 181 { 182 global $wp_rewrite; 158 183 return !$wp_rewrite->using_permalinks(); 159 184 } 160 185 161 public static function show_permalinks_unsupported_notice() { 186 public static function show_permalinks_unsupported_notice() 187 { 162 188 ?> 163 189 <div id="setting-error-permalinks_unsupported" class="notice notice-error settings-error"> 164 <p><strong>Notice:</strong> "Plain" permalinks structure is not supported for Humix Channel and Ads.txt features, please update your permalinks structure to use these features</p> 190 <p><strong>Notice:</strong> "Plain" permalinks structure is not supported for Humix Channel and Ads.txt features, 191 please update your permalinks structure to use these features</p> 165 192 </div> 166 193 <?php … … 168 195 169 196 const VIDEO_INSERT_SETTINGS_TAB = 'video_insert_settings'; 170 const CHANNEL_SETTINGS_TAB = 'channel_settings'; 171 const ADSTXT_SETTINGS_TAB = 'adstxt_settings'; 172 const DEFAULT_SELECTED_TAB = self::VIDEO_INSERT_SETTINGS_TAB; 173 174 public static function humix_plugin_options_page() { 175 if(self::is_using_plain_permalinks()) { 197 const CHANNEL_SETTINGS_TAB = 'channel_settings'; 198 const ADSTXT_SETTINGS_TAB = 'adstxt_settings'; 199 const DEFAULT_SELECTED_TAB = self::VIDEO_INSERT_SETTINGS_TAB; 200 201 public static function humix_plugin_options_page() 202 { 203 if (self::is_using_plain_permalinks()) { 176 204 // we do not support plain permalinks for the settings features 177 205 self::show_permalinks_unsupported_notice(); 178 206 } 179 ?> 180 <div class="wrap"> 181 <p> 182 <img alt="Humix Logo" src="https://assets.humix.com/full_humix_logo.png" /> 183 </p> 184 <?php 185 $active_tab = self::DEFAULT_SELECTED_TAB; 186 $tmp_active_tab = isset($_GET['tab']) ? $_GET['tab'] : ''; 187 if (in_array($tmp_active_tab, array(self::CHANNEL_SETTINGS_TAB, self::ADSTXT_SETTINGS_TAB))) { 188 $active_tab = $tmp_active_tab; 189 } 190 ?> 191 <h2 class="nav-tab-wrapper"> 192 <a href="?page=<?php echo self::MENU_SLUG ?>&tab=<?php echo self::VIDEO_INSERT_SETTINGS_TAB ?>" 193 class="nav-tab <?php echo $active_tab == self::VIDEO_INSERT_SETTINGS_TAB ? 'nav-tab-active' : ''; ?>">Video Insert Settings</a> 194 <a href="?page=<?php echo self::MENU_SLUG ?>&tab=<?php echo self::CHANNEL_SETTINGS_TAB ?>" 195 class="nav-tab <?php echo $active_tab == self::CHANNEL_SETTINGS_TAB ? 'nav-tab-active' : ''; ?>">Channel Settings</a> 196 <a href="?page=<?php echo self::MENU_SLUG ?>&tab=<?php echo self::ADSTXT_SETTINGS_TAB ?>" 197 class="nav-tab <?php echo $active_tab == self::ADSTXT_SETTINGS_TAB ? 'nav-tab-active' : ''; ?>">Ads.txt Manager</a> 198 199 200 <a href="https://support.ezoic.com/kb/category/video-humix-studio" target="_blank" class="nav-tab" style="float: right;"> 201 Help Center 202 </a> 203 <a href="https://login.humix.com/" target="_blank" class="nav-tab" style="float: right;"> 204 Humix Dashboard 205 </a> 206 </h2> 207 <?php 208 switch($active_tab) { 209 case self::VIDEO_INSERT_SETTINGS_TAB: 210 self::render_video_insert_settings_tab(); 211 break; 212 case self::CHANNEL_SETTINGS_TAB: 213 self::render_channel_settings_tab(); 214 break; 215 case self::ADSTXT_SETTINGS_TAB: 216 self::render_adstxt_manager_settings_tab(); 217 break; 218 default: 219 self::render_video_insert_settings_tab(); 220 break; 221 } 222 ?> 223 </div> 224 <?php 225 } 226 227 public static function render_video_insert_settings_tab() { 207 ?> 208 <div class="wrap"> 209 <p> 210 <img alt="Humix Logo" src="https://assets.humix.com/full_humix_logo.png" /> 211 </p> 212 <?php 213 $active_tab = self::DEFAULT_SELECTED_TAB; 214 $tmp_active_tab = isset($_GET['tab']) ? $_GET['tab'] : ''; 215 if (in_array($tmp_active_tab, array(self::CHANNEL_SETTINGS_TAB, self::ADSTXT_SETTINGS_TAB))) { 216 $active_tab = $tmp_active_tab; 217 } 218 ?> 219 <h2 class="nav-tab-wrapper"> 220 <a href="?page=<?php echo self::MENU_SLUG ?>&tab=<?php echo self::VIDEO_INSERT_SETTINGS_TAB ?>" 221 class="nav-tab <?php echo $active_tab == self::VIDEO_INSERT_SETTINGS_TAB ? 'nav-tab-active' : ''; ?>">Video 222 Insert Settings</a> 223 <a href="?page=<?php echo self::MENU_SLUG ?>&tab=<?php echo self::CHANNEL_SETTINGS_TAB ?>" 224 class="nav-tab <?php echo $active_tab == self::CHANNEL_SETTINGS_TAB ? 'nav-tab-active' : ''; ?>">Channel 225 Settings</a> 226 <a href="?page=<?php echo self::MENU_SLUG ?>&tab=<?php echo self::ADSTXT_SETTINGS_TAB ?>" 227 class="nav-tab <?php echo $active_tab == self::ADSTXT_SETTINGS_TAB ? 'nav-tab-active' : ''; ?>">Ads.txt 228 Manager</a> 229 230 231 <a href="https://support.ezoic.com/kb/category/video-humix-studio" target="_blank" class="nav-tab" 232 style="float: right;"> 233 Help Center 234 </a> 235 <a href="https://login.humix.com/" target="_blank" class="nav-tab" style="float: right;"> 236 Humix Dashboard 237 </a> 238 </h2> 239 <?php 240 switch ($active_tab) { 241 case self::VIDEO_INSERT_SETTINGS_TAB: 242 self::render_video_insert_settings_tab(); 243 break; 244 case self::CHANNEL_SETTINGS_TAB: 245 self::render_channel_settings_tab(); 246 break; 247 case self::ADSTXT_SETTINGS_TAB: 248 self::render_adstxt_manager_settings_tab(); 249 break; 250 default: 251 self::render_video_insert_settings_tab(); 252 break; 253 } 254 ?> 255 </div> 256 <?php 257 } 258 259 public static function render_video_insert_settings_tab() 260 { 228 261 ?> 229 262 <div class="wrap"> … … 231 264 <p class="notice notice-info" style="padding: 15px;"> 232 265 Automatically insert videos on all pages in this site. 233 <br/> 234 To configure the behavior and placement of the auto-inserted videos, visit the <a href="https://app.humix.com/site/settings/content-settings" target="_blank">Humix Dashboard</a>. 266 <br /> 267 To configure the behavior and placement of the auto-inserted videos, visit the <a 268 href="https://app.humix.com/site/settings/content-settings" target="_blank">Humix Dashboard</a>. 235 269 </p> 236 270 <form action="options.php" method="post"> … … 252 286 <h2>Channel Settings</h2> 253 287 <p class="notice notice-info" style="padding: 15px;"> 254 Select a channel from your account below to display on this site at <a href="<?php echo $channel_page; ?>" target="_blank"><?php echo $channel_page; ?></a> 288 Select a channel from your account below to display on this site at <a href="<?php echo $channel_page; ?>" 289 target="_blank"><?php echo $channel_page; ?></a> 255 290 </p> 256 291 <form action="options.php" method="post"> … … 274 309 <br> 275 310 <br> 276 If you are setting up via the Humix dashboard, you can put in <code>70772</code> as the ID. If you created an account with <a href="https://www.adstxtmanager.com/" target="_blank">adstxtmanager.com</a>, click <a href="https://www.adstxtmanager.com/" target="_blank">here</a> to login and access your ID. 311 If you are setting up via the Humix dashboard, you can put in <code>70772</code> as the ID. If you created an 312 account with <a href="https://www.adstxtmanager.com/" target="_blank">adstxtmanager.com</a>, click <a 313 href="https://www.adstxtmanager.com/" target="_blank">here</a> to login and access your ID. 277 314 </p> 278 315 <form action="options.php" method="post"> … … 287 324 } 288 325 289 public static function render_insert_on_all_pages_option(){ 290 ?> 291 <span style="position: absolute; left: 0; margin: 0 15px;"> 292 <input id="insert-on-all-pages" type="checkbox" name="<?php echo self::INSERT_ON_ALL_PAGES_OPTION; ?>" <?php \checked(self::get_insert_on_all_pages(), true); ?>> 326 public static function render_insert_on_all_pages_option() 327 { 328 ?> 329 <span style="position: absolute; left: 0; margin: 0 15px;"> 330 <input id="insert-on-all-pages" type="checkbox" name="<?php echo self::INSERT_ON_ALL_PAGES_OPTION; ?>" <?php \checked(self::get_insert_on_all_pages(), true); ?>> 293 331 <label for="insert-on-all-pages">Automatically insert video on all pages</label> 294 </span>295 <br/>296 <?php332 </span> 333 <br /> 334 <?php 297 335 } 298 336 299 337 public static function render_assigned_channel_id_option() 300 {301 $auth = new \HumixNamespace\Authentication();302 $token = $auth->get_token_from_publisher_backend();303 $channels = [];338 { 339 $auth = new \HumixNamespace\Authentication(); 340 $token = $auth->get_token_from_publisher_backend(); 341 $channels = []; 304 342 $load_channels_err = false; 305 try {306 $channels = (new \HumixNamespace\Channels())->get_channels($token);307 } catch (\Exception $e) {308 \error_log("Humix Plugin Error: Failed to load channels: " . $e->getMessage());309 $load_channels_err = true;310 }343 try { 344 $channels = (new \HumixNamespace\Channels())->get_channels($token); 345 } catch (\Exception $e) { 346 \error_log("Humix Plugin Error: Failed to load channels: " . $e->getMessage()); 347 $load_channels_err = true; 348 } 311 349 312 350 if ($load_channels_err || empty($channels)) { 313 351 ?> 314 <div id="setting-error-api_error" class="notice notice-error settings-error">315 <p><strong>Failed to load your channels from your account. Please refresh the page and try again.</strong></p>316 </div>317 <?php318 return;319 } 320 321 $selected_channel_id = self::get_assigned_channel_id();322 ?>323 <select name="<?php echo self::ASSIGNED_CHANNEL_ID_OPTION; ?>">324 <option value="-1" <?php \selected($selected_channel_id, -1); ?>>325 <?php326 echo (int) $selected_channel_id === -1 ? "Select a channel" : "Remove channel from this site";327 ?>328 </option>329 <?php foreach ($channels as $channel): ?>330 <option value="<?php echo \esc_attr($channel['humixChannelId']); ?>" <?php \selected($selected_channel_id, $channel['humixChannelId']); ?>>331 <?php echo \esc_html($channel['name']); ?>332 </option>333 <?php endforeach; ?>334 </select>335 <?php336 }352 <div id="setting-error-api_error" class="notice notice-error settings-error"> 353 <p><strong>Failed to load your channels from your account. Please refresh the page and try again.</strong></p> 354 </div> 355 <?php 356 return; 357 } 358 359 $selected_channel_id = self::get_assigned_channel_id(); 360 ?> 361 <select name="<?php echo self::ASSIGNED_CHANNEL_ID_OPTION; ?>"> 362 <option value="-1" <?php \selected($selected_channel_id, -1); ?>> 363 <?php 364 echo (int) $selected_channel_id === -1 ? "Select a channel" : "Remove channel from this site"; 365 ?> 366 </option> 367 <?php foreach ($channels as $channel): ?> 368 <option value="<?php echo \esc_attr($channel['humixChannelId']); ?>" <?php \selected($selected_channel_id, $channel['humixChannelId']); ?>> 369 <?php echo \esc_html($channel['name']); ?> 370 </option> 371 <?php endforeach; ?> 372 </select> 373 <?php 374 } 337 375 338 376 public static function render_adstxt_manager_id_option() 339 377 { 340 378 $selected_option = self::get_adstxt_manager_id() 341 ?>342 <input name="<?php echo self::ADSTXT_MANAGER_ID_OPTION; ?>" class="regular-text code" placeholder="Enter your Ads.txt Manager ID..."343 <?php344 if($selected_option > 0) {345 echo 'value="' . $selected_option . '"';346 }347 379 ?> 348 ></input> 380 <input name="<?php echo self::ADSTXT_MANAGER_ID_OPTION; ?>" class="regular-text code" 381 placeholder="Enter your Ads.txt Manager ID..." <?php 382 if ($selected_option > 0) { 383 echo 'value="' . $selected_option . '"'; 384 } 385 ?>></input> 349 386 <?php 350 387 } … … 388 425 389 426 // Allow user to pass empty string (or 0) to effectively clear out the value 390 if ($new_adstxt_manager_id === "") {427 if ($new_adstxt_manager_id === "") { 391 428 $new_adstxt_manager_id = 0; 392 429 } -
humix/trunk/README.txt
r3144450 r3173030 4 4 Tags: humix, video, embed, network 5 5 Requires at least: 5.8.0 6 Tested up to: 6. 56 Tested up to: 6.6 7 7 Requires PHP: 7.0 8 Stable tag: 1. 4.18 Stable tag: 1.5.0 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 23 23 24 24 == Changelog == 25 = 1.5.0 = 26 * Improvements to channel hosting setup process 27 25 28 = 1.4.1 = 26 29 * Changed adstxtmanager ID -
humix/trunk/humix.php
r3144450 r3173030 5 5 require "HumixNamespace/Channels.php"; 6 6 require "HumixNamespace/Settings.php"; 7 require "HumixNamespace/RestApi.php"; 7 8 8 9 /** … … 15 16 * 16 17 * @link https://www.humix.com/ 17 * @since 1. 4.118 * @since 1.5.0 18 19 * @package Humix 19 20 * … … 22 23 * Plugin URI: https://wordpress.org/plugins/humix 23 24 * Description: Humix allows you to easily embed videos to your site from the Humix Network. 24 * Version: 1. 4.125 * Version: 1.5.0 25 26 * Author: Humix 26 27 * Author URI: https://www.humix.com/ … … 39 40 * Rename this for your plugin and update it as you release new versions. 40 41 */ 41 define('HUMIX_VERSION', '1. 4.1');42 define('HUMIX_VERSION', '1.5.0'); 42 43 43 44 global $EZHX_REGEX; … … 62 63 \HumixNamespace\Authentication::register(); 63 64 65 // register API endpoitns 66 \HumixNamespace\RestApi::register(); 67 64 68 // handle rewrite rules for middleton requests appropriately 65 69 $assigned_humix_channel_id = \HumixNamespace\Settings::get_assigned_channel_id(); … … 76 80 } 77 81 82 // handle insert videos on all pages if enabled 78 83 $insert_on_all_pages = \HumixNamespace\Settings::get_insert_on_all_pages(); 79 84 if ($insert_on_all_pages) {
Note: See TracChangeset
for help on using the changeset viewer.