具有许多高级广告功能的广告管理功能,可在最佳位置插入广告
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

10934 lines
466 KiB

  1. <?php
  2. /*
  3. Plugin Name: Ad Inserter
  4. Version: 2.6.16
  5. Description: Ad management with many advanced advertising features to insert ads at optimal positions
  6. Author: Igor Funa
  7. Author URI: http://igorfuna.com/
  8. Plugin URI: https://adinserter.pro/documentation
  9. Text Domain: ad-inserter
  10. Domain Path: /languages
  11. Requires at least: 4.6
  12. Requires PHP: 5.6
  13. */
  14. /*
  15. Change Log
  16. Ad Inserter 2.6.16 - 2020-10-20
  17. - Added support for ad blocking detection action every n pageviews
  18. - Added support to individually disable pageview or click tracking (Pro only)
  19. - Changed IAB TCF v2 cookie check name from euconsent-v2 to tcf-v2 (euconsent-v2 will still work)
  20. - Fix for category check on category pages
  21. - Fix for issues with Safari browser
  22. - Few minor bug fixes, cosmetic changes and code improvements
  23. Ad Inserter 2.6.15 - 2020-10-02
  24. - No ad blocking detection actions for crawlers and bots
  25. - Fix for processing Ad Inserter shortcodes inside HTML tags
  26. - Few minor bug fixes, cosmetic changes and code improvements
  27. Ad Inserter 2.6.14 - 2020-09-07
  28. - Added support to insert [embed] shortcodes
  29. - Few minor bug fixes, cosmetic changes and code improvements
  30. Ad Inserter 2.6.13 - 2020-08-26
  31. - Few minor bug fixes
  32. Ad Inserter 2.6.12 - 2020-08-23
  33. - Support for PHP 7.4
  34. - Improved ad blocking detection
  35. - Added options to delay client-side insertions at HTML element
  36. - Added support to check for multiple cookie values (needed for IAB TCF 2.0)
  37. - Added filter hooks for block processing
  38. - Few minor bug fixes, cosmetic changes and code improvements
  39. Ad Inserter 2.6.11 - 2020-07-23
  40. - Added support for IAB Transparency & Consent Framework 2.0
  41. - Added support for taxonomy for primary category
  42. - Added support for taxonomy for post meta data
  43. - Added support to invert contain/do not contain text condition for paragraph counting
  44. - Few minor bug fixes, cosmetic changes and code improvements
  45. Ad Inserter 2.6.10 - 2020-06-25
  46. - Added user taxonomy items for logged-in and not logged-in users
  47. - Added option to define tab setup delay (for the plugin settings page)
  48. - Added option to insert unique ad rotation options when block is inserted more than once
  49. - Added support for client-side device detection for AMP pages (for method Show)
  50. - Added support for code generator for Amazon AMP ads
  51. - Added support for custom tracking events (Pro only)
  52. - Few minor bug fixes, cosmetic changes and code improvements
  53. Ad Inserter 2.6.9 - 2020-05-22
  54. - Added option for paragraph counting to search only tag attributes for text
  55. - Added option to embed block Javascript code (to be loaded with Ajax calls)
  56. - Added support to prevent duplicate insertions when the_content filter is called more than once (experimental)
  57. - Added support for the client list to check for partial user agent strings
  58. - Added support for check of cookie object properties
  59. - Improved ad blocking detection
  60. - Viewports no longer need to be in descending width order
  61. - Added option to protect inserted block content (Pro only)
  62. - Added support for adb scripts path filter hook (Pro only)
  63. - Added support to export statistics data to CSV file (Pro only)
  64. - Few minor bug fixes, cosmetic changes and code improvements
  65. Ad Inserter 2.6.8 - 2020-04-27
  66. - Added support to disable PHP processing by PHP constant
  67. - Added support to repeat COUNT options
  68. - Added support for offset for %n paragraph number (%n@o)
  69. - Added support for options to skip insertion for first and last paragraphs
  70. - Added support for hook filter 'ai_block_insertion_check'
  71. - Added support for background ads (Pro only)
  72. - Few minor bug fixes, cosmetic changes and code improvements
  73. Ad Inserter 2.6.7 - 2020-04-07
  74. - Added support for various shortcodes for post categories
  75. - Added support for various shortcodes for post tags
  76. - Added support for user action on click (Pro only)
  77. - Added support for manual loading (Pro only)
  78. - Few minor bug fixes, cosmetic changes and code improvements
  79. Ad Inserter 2.6.6 - 2020-03-15
  80. - Fix for exceptions list not showing all exceptions
  81. - Improved ad blocking detection
  82. - Fix for close button in preview window (Pro only)
  83. - Few minor bug fixes, cosmetic changes and code improvements
  84. Ad Inserter 2.6.5 - 2020-02-26
  85. - Added support for url data shortcode
  86. - Added warning if not all exceptions were cleared
  87. - Added support for MaxMind country only database (Pro only)
  88. - Added support for ip to country lookup filter hook (Pro only)
  89. - Fix for country groups in CHECK separators (Pro only)
  90. - Few minor bug fixes, cosmetic changes and code improvements
  91. Ad Inserter 2.6.4 - 2020-02-13
  92. - Fix for use of undefined constant warning (Pro only)
  93. Ad Inserter 2.6.3 - 2020-02-10
  94. - Added support for shortcodes to disable block insertion
  95. - Added support for child taxonomy list items
  96. - Added random parameter to Ajax requests for geolocation (Pro only)
  97. - Added options to define external tracking event category, action and label (Pro only)
  98. - Number of custom hooks increased to 20
  99. - Fix to prevent insertion into head section when using Rank Math plugin
  100. - Few minor bug fixes, cosmetic changes and code improvements
  101. Ad Inserter 2.6.2 - 2020-01-20
  102. - Added support to disable caching of block PHP code
  103. - Added support to pause blocks on the blocks list
  104. - Added support for no url parameters list item
  105. - Added support for client-side scheduling (Pro only)
  106. - Added support for server-side scheduling using W3TC (Pro only)
  107. - Added support for multisite:site-id taxonomy list item (Pro only)
  108. - Updated MaxMind GeoLite2 database download using license key (Pro only)
  109. - Changed settings format in the database to prevent export/import issues with MySQL/PhpMyAdmin
  110. - Fix for [ADINSERTER counter] shortcode not expanding inside HTML tags
  111. - Few minor bug fixes, cosmetic changes and code improvements
  112. Ad Inserter 2.6.1 - 2020-01-10
  113. - Fix for errors on the settings page
  114. - Fix for non English characters in ads
  115. - Fix for sticky widgets
  116. - Few minor bug fixes
  117. Ad Inserter 2.6.0 - 2020-01-09
  118. - Added support for VIEWPORT separator
  119. - Added support for viewport check in CHECK separators (Pro only)
  120. - Added support to show processing log on front-end
  121. - Added support to show link to the Ad Inserter Pro settings page on multisite Sites page (Pro only)
  122. - Added support to detect and prevent document.write after DOM is ready
  123. - Added support for scheduling hours (Pro only)
  124. - Added support for scheduling days in week (Pro only)
  125. - Added support for W3TC insertion debugging info
  126. - Improved Javascript code for client-side functions
  127. - Improved ad blocking detection
  128. - Default value for Wait for jQuery set to Enabled
  129. - Few minor bug fixes, cosmetic changes and code improvements
  130. Ad Inserter 2.5.10 - 2019-12-08
  131. - Optimized Javascript code to allow advanced optimizations
  132. - Added support to wait for jQuery so it can be deferred
  133. - Added support for children categories in lists
  134. - Added support to load settings page in safe mode
  135. - Added warning notice if PHP version is below 5.6
  136. - Improved user interface for lists
  137. - Modified Javascript code that was wrongly replaced by CDN url
  138. - Fix for updates server access warning message (Pro only)
  139. - Few minor bug fixes, cosmetic changes and code improvements
  140. Ad Inserter 2.5.9 - 2019-11-19
  141. - Added support for block name class
  142. - Added support for code generator for AdSense sticky AMP ads
  143. - Fix for paragraph clearance issues
  144. - Few minor bug fixes, cosmetic changes and code improvements
  145. Ad Inserter 2.5.8 - 2019-11-14
  146. - Added support to call function adinserter () with block name
  147. - Added support to insert header code with HEAD separator only once
  148. - Additional info for errors when saving settings
  149. - Improved support for insertion between posts on AMP pages
  150. - Implemented compatibility with other plugins using phpQuery library
  151. - Added support for shortcode to disable tracking on specific pages (Pro only)
  152. - Few minor bug fixes, cosmetic changes and code improvements
  153. Ad Inserter 2.5.7 - 2019-10-14
  154. - Fix for error when saving settings
  155. Ad Inserter 2.5.6 - 2019-10-12
  156. - Added support for PenCi Soledad AMP plugin
  157. - Fix for php processing on multisite installations
  158. - Fix for client-side referrer check
  159. - Fix for header and footer code on AMP pages using AMP plugin
  160. - Few minor bug fixes, cosmetic changes and code improvements
  161. Ad Inserter 2.5.5 - 2019-09-29
  162. - Added support for client list (black/whitelist operating systems, browsers, device names)
  163. - Fix for replaced tags with default value {name:default-value}
  164. - Few minor bug fixes, cosmetic changes and code improvements
  165. Ad Inserter 2.5.4 - 2019-09-27
  166. - Minor bug fix regarding update checks (Pro only)
  167. Ad Inserter 2.5.3 - 2019-09-24
  168. - Added support for warning when Ad Inserter is disabled by AMPforWP Plugin Manager
  169. - Added support for block shortcode attributes
  170. - Added support for post ID list to include all posts or static pages
  171. - Added option for maximum number of paragraphs
  172. - Added support to check for update server accessibility (Pro only)
  173. - Added ids to ad blocking popup message and overlay elements
  174. - Few minor bug fixes, cosmetic changes and code improvements
  175. Ad Inserter 2.5.2 - 2019-09-10
  176. - Added options to define paragraph counting inside container elements
  177. - Added support to pin block list (Pro only)
  178. - Few minor bug fixes, cosmetic changes and code improvements
  179. Ad Inserter 2.5.1 - 2019-08-24
  180. - Few minor bug fixes (Pro only)
  181. Ad Inserter 2.5.0 - 2019-08-20
  182. - Improved user interface
  183. - Simplified user interface for individual post/page exceptions
  184. - Added support for virtual ads.txt file
  185. - Added support for frequency capping (Pro only)
  186. - Added support for click fraud detection (Pro only)
  187. - Changed url prefix for public reports to avoid possible url collisions (Pro only)
  188. - Fix for shortcode processing when blocks were used before init hook
  189. - Many minor bug fixes, cosmetic changes and code improvements
  190. Ad Inserter 2.4.23 - 2019-07-30
  191. - Added support to define custom fields with shortocdes
  192. - Added experimental support to delay showing ads for specified number of pageviews (Pro only)
  193. - Fix for false positive ad blocking detection (Pro only)
  194. - Few minor bug fixes, cosmetic changes and code improvements
  195. Ad Inserter 2.4.22 - 2019-07-13
  196. - Fix for remote code execution vulnerability - credit to Wordfence
  197. Ad Inserter 2.4.21 - 2019-07-11
  198. - Fix for possible error Class not found (Pro only)
  199. Ad Inserter 2.4.20 - 2019-07-09
  200. - Fix for path traversal vulnerability - credit to Wilfried Bécard of Synacktiv (https://synacktiv.com)
  201. - Fix for block rearrangement issues
  202. - Added experimental support to remember closed ad for specified time period (Pro only)
  203. - Added experimental support to automatically close ad after specified time period (Pro only)
  204. - Few minor bug fixes, cosmetic changes and code improvements
  205. Ad Inserter 2.4.19 - 2019-06-18
  206. - Added support for taxonomy for Yoast primary category
  207. - Layout changes to accomodate longer translated texts
  208. - Fix for escape character not saved in header, footer and ad blocking message code
  209. - Few minor bug fixes, cosmetic changes and code improvements
  210. Ad Inserter 2.4.18 - 2019-05-26
  211. - Added support for full width responsive AdSense code option
  212. - Few minor bug fixes, cosmetic changes and code improvements
  213. Ad Inserter 2.4.17 - 2019-05-13
  214. - Few minor bug fixes, cosmetic changes and code improvements
  215. Ad Inserter 2.4.16 - 2019-04-21
  216. - Fix for compatibility with AMP for WP - Accelerated Mobile Pages for WordPress
  217. - Few minor bug fixes
  218. Ad Inserter 2.4.15 - 2019-04-19
  219. - Fix for improved compatibility with other plugins
  220. - Few minor bug fixes and cosmetic changes
  221. Ad Inserter 2.4.14 - 2019-04-18
  222. - Fix for ROTATE shortcodes with option name identical to block name
  223. - Fix for possible conflict with output buffering in other plugins
  224. - Few minor bug fixes, cosmetic changes and code improvements
  225. Ad Inserter 2.4.13 - 2019-04-12
  226. - Added shortcode to disable ad blocking detection code
  227. - Added options to disable ad blocking actions for administrators or logged in users
  228. - Added option to change PDF report footer (Pro only)
  229. - Added support for public ad impression and click reports (Pro only)
  230. - Few minor bug fixes, cosmetic changes and code improvements
  231. Ad Inserter 2.4.12 - 2019-03-21
  232. - Added ads.txt editor
  233. - Added option to prevent disabling caching for logged in administrators
  234. - Improved compatibility with PHP 7.2
  235. - Few minor bug fixes, cosmetic changes and code improvements
  236. Ad Inserter 2.4.11 - 2019-02-23
  237. - Fix for saving code with slashes
  238. - Fix for rotation editor code import
  239. - Few minor bug fixes, cosmetic changes and code improvements
  240. Ad Inserter 2.4.10 - 2019-02-18
  241. - Added support for counter shortcodes
  242. - Added support for code separator selection for code preview
  243. - Added support for group rotations
  244. - Added support for CHECK separator (Pro only)
  245. - Added links to test pages for check for available positions
  246. - Few minor bug fixes, cosmetic changes and code improvements
  247. Ad Inserter 2.4.9 - 2019-02-05
  248. - Added support for HEAD separator
  249. - Added support for DoubleClick for Publishers (DFP) ads
  250. - Added support to generate statistics reports in PDF format (Pro only)
  251. - Fix for ad label when using AMP separator
  252. - Fix for AdSense code fixed by viewport
  253. - Fix for error when checking for available positions
  254. - Few minor bug fixes, cosmetic changes and code improvements
  255. Ad Inserter 2.4.8 - 2019-01-20
  256. - Added support for automatic insertion before/after image
  257. - Added support for theme checker for available positions for automatic insertion
  258. Ad Inserter 2.4.7 - 2019-01-15
  259. - Added support for automatic insertion before/after image (experimental)
  260. - Added support for theme checker for available positions for automatic insertion (experimental)
  261. - Improvements to the user interface
  262. - Fix for lazy loading in Ajax calls (Pro only)
  263. - Fix for country list editor (Pro only)
  264. - Few minor bug fixes, cosmetic changes and code improvements
  265. Ad Inserter 2.4.6 - 2019-01-08
  266. - Improved ad blocking detection (detects Firefox content blocking)
  267. - Added support for wildcards for referrers (domains)
  268. - Added debugging notice when JavaScript errors are detected
  269. - Added support to load blocks in iframes (Pro only)
  270. - Added geolocation support for country subdivisions and cities (Pro only)
  271. - Added option to hide license key on client websites (Pro only)
  272. - Few minor bug fixes, cosmetic changes and code improvements
  273. Ad Inserter 2.4.5 - 2018-12-26
  274. - Added support for AMP WP - Google AMP For WordPress
  275. - Added support to individually disable insertions for debugging purposes
  276. - Improved HTML element selection tool
  277. - Fix for Call to undefined function wp_get_current_user()
  278. - Few minor bug fixes, cosmetic changes and code improvements
  279. Ad Inserter 2.4.4 - 2018-12-11
  280. - Fix for Fatal error: Call to undefined function mb_strtoupper()
  281. Ad Inserter 2.4.3 - 2018-12-10
  282. - Added support for insertion before/after every N paragraphs (%N)
  283. - Added support for i18n
  284. - Fix for insertion on admin pages
  285. - Fix for client-side cookie check
  286. - Fix for loaded styles from other plugins/themes on the settings page
  287. - Fix for client-side insertion near HTML elements using :eq selector
  288. - Fix for deactivation feedback form not closing
  289. - Few minor bug fixes, cosmetic changes and code improvements
  290. Ad Inserter 2.4.2 - 2018-10-21
  291. - Added support for visual HTML element selection
  292. - Fix for client-side insertion inside HTML elements
  293. - Few minor bug fixes, cosmetic changes and code improvements
  294. Ad Inserter 2.4.1 - 2018-10-05
  295. - Added option to insert into HTML element (prepend, append, replace content)
  296. - Added option to remove HTML element
  297. - Added option to not show deactivation feedback form
  298. - Added support for negative relative positions for paragraph counting
  299. - Few minor bug fixes, cosmetic changes and code improvements
  300. Ad Inserter 2.4.0 - 2018-09-26
  301. - Improved code for client-side insertion
  302. - Added support for usage tracking
  303. - Fix for compatibility with older PHP versions (below 5.4)
  304. - Few minor bug fixes, cosmetic changes and code improvements
  305. */
  306. if (!defined ('ABSPATH')) exit;
  307. if (!defined ('AD_INSERTER_VERSION')) {
  308. function ai_wp_default_editor () {
  309. return 'tinymce';
  310. }
  311. function ai_wp_default_editor_html () {
  312. return 'html';
  313. }
  314. function ai_disable_caching () {
  315. // WP Super Cache, W3 Total Cache, WP Rocket
  316. if (!defined('DONOTCACHEPAGE'))
  317. define('DONOTCACHEPAGE', true);
  318. if (!defined('DONOTCACHEOBJECT'))
  319. define('DONOTCACHEOBJECT', true);
  320. if (!defined('DONOTCACHEDB'))
  321. define('DONOTCACHEDB', true);
  322. if (!headers_sent () && !is_user_logged_in ()) {
  323. header('Cache-Control: private, proxy-revalidate, s-maxage=0');
  324. }
  325. }
  326. function ai_toolbar_menu_items () {
  327. global $block_object, $ai_wp_data;
  328. if (isset ($ai_wp_data [AI_DEBUG_MENU_ITEMS])) return;
  329. $disable_block_insertions = get_disable_block_insertions ();
  330. $disable_php_processing = get_disable_php_processing ();
  331. $disable_html_code = get_disable_html_code ();
  332. $disable_css_code = get_disable_css_code ();
  333. $disable_js_code = get_disable_js_code ();
  334. $disable_footer_code = get_disable_footer_code ();
  335. $disable_header_code = get_disable_header_code ();
  336. $statuses = '<span class="ai-insertion-status"'. ($disable_header_code ? ' style="color: #f22"' : '') . '">H</span> &nbsp; ';
  337. $statuses .= '<span class="ai-insertion-status"'. ($disable_footer_code ? ' style="color: #f22"' : '') . '">F</span> &nbsp; ';
  338. $statuses .= '<span class="ai-insertion-status"'. ($disable_js_code ? ' style="color: #f22"' : '') . '">JS</span> &nbsp; ';
  339. $statuses .= '<span class="ai-insertion-status"'. ($disable_css_code ? ' style="color: #f22"' : '') . '">CSS</span> &nbsp; ';
  340. $statuses .= '<span class="ai-insertion-status"'. ($disable_html_code ? ' style="color: #f22"' : '') . '">HTML</span> &nbsp; ';
  341. $statuses .= '<span class="ai-insertion-status"'. ($disable_php_processing ? ' style="color: #f22"' : '') . '">PHP</span> &nbsp; ';
  342. $statuses .= '<span class="ai-insertion-status"'. ($disable_block_insertions ? ' style="color: #f22"' : '') . '">BLOCKS</span>';
  343. $insertion_disabled = $disable_block_insertions || $disable_php_processing || $disable_html_code || $disable_css_code || $disable_js_code || $disable_footer_code || $disable_header_code;
  344. $ai_wp_data [AI_DEBUG_MENU_ITEMS] = array ();
  345. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_BLOCKS) == 0) $debug_blocks = 1; else $debug_blocks = 0;
  346. $debug_blocks_class = $debug_blocks == 0 ? ' on' : '';
  347. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_POSITIONS) == 0) $debug_positions = 0; else $debug_positions = '';
  348. $debug_positions_class = $debug_positions === '' ? ' on' : '';
  349. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_TAGS) == 0) $debug_tags = 1; else $debug_tags = 0;
  350. $debug_tags_class = $debug_tags == 0 ? ' on' : '';
  351. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) == 0) $debug_processing = 1; else $debug_processing = 0;
  352. $debug_processing_class = $debug_processing == 0 ? ' on' : '';
  353. if (!isset ($_GET [AI_URL_DEBUG_PROCESSING_FE_]) || $_GET [AI_URL_DEBUG_PROCESSING_FE_] == 0) $debug_processing_fe = 1; else $debug_processing_fe = 0;
  354. $debug_processing__fe_class = $debug_processing_fe == 0 ? ' on' : '';
  355. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) $debug_no_insertion = 1; else $debug_no_insertion = 0;
  356. $debug_no_insertion_class = $debug_no_insertion == 0 ? ' on' : '';
  357. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_AD_BLOCKING) == 0) $debug_ad_blocking = 1; else $debug_ad_blocking = 0;
  358. $debug_ad_blocking_class = $debug_ad_blocking == 0 ? ' on' : '';
  359. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_AD_BLOCKING_STATUS) == 0) $debug_ad_blocking_status = 1; else $debug_ad_blocking_status = 0;
  360. $debug_ad_blocking_status_class = $debug_ad_blocking_status == 0 ? ' on' : '';
  361. $debug_settings_on = $debug_blocks == 0 || $debug_positions === '' || $debug_tags == 0 || $debug_processing == 0 || $debug_no_insertion == 0 || $debug_ad_blocking == 0 || $debug_ad_blocking_status == 0;
  362. $debug_settings_class = $debug_settings_on ? ' on' : '';
  363. if ($insertion_disabled) $debug_settings_class .= ' red';
  364. $top_menu_url = $debug_settings_on ? (defined ('AI_DEBUGGING_DEMO') ? get_permalink () : add_query_arg (AI_URL_DEBUG, '0', remove_debug_parameters_from_url ())) :
  365. add_query_arg (array (AI_URL_DEBUG_BLOCKS => '1', AI_URL_DEBUG_POSITIONS => '0'), remove_debug_parameters_from_url ());
  366. $ai_wp_data [AI_DEBUG_MENU_ITEMS][] = array (
  367. 'id' => 'ai-toolbar',
  368. 'group' => true
  369. );
  370. $ai_wp_data [AI_DEBUG_MENU_ITEMS][] = array (
  371. 'id' => 'ai-toolbar-settings',
  372. // 'parent' => 'ai-toolbar',
  373. // 'title' => '<span class="ab-icon'.$debug_settings_class.'"></span>'.AD_INSERTER_NAME . (defined ('AI_DEBUGGING_DEMO') ? ' Debugging DEMO' : ($debug_settings_on ? ' Debugging' : '')),
  374. 'title' => '<span class="ab-icon'.$debug_settings_class.'"></span>'.AD_INSERTER_NAME . (defined ('AI_DEBUGGING_DEMO') ? ' ' . _x('Debugging DEMO', 'Menu item', 'ad-inserter') : ($debug_settings_on ? '' : '')),
  375. 'href' => $top_menu_url,
  376. // 'meta' => $debug_settings_on ? array ('title' => 'Turn Debugging Off') : array (),
  377. );
  378. if ($insertion_disabled) {
  379. $ai_wp_data [AI_DEBUG_MENU_ITEMS][] = array (
  380. 'id' => 'ai-toolbar-status',
  381. 'parent' => 'ai-toolbar-settings',
  382. 'title' => '&nbsp;'.$statuses,
  383. );
  384. }
  385. $ai_wp_data [AI_DEBUG_MENU_ITEMS][] = array (
  386. 'id' => 'ai-toolbar-blocks',
  387. 'parent' => 'ai-toolbar-settings',
  388. 'title' => '<span class="ab-icon'.$debug_blocks_class.'"></span>' . _x('Label Blocks', 'Menu item', 'ad-inserter'),
  389. 'href' => set_url_parameter (AI_URL_DEBUG_BLOCKS, $debug_blocks),
  390. );
  391. $ai_wp_data [AI_DEBUG_MENU_ITEMS][] = array (
  392. 'id' => 'ai-toolbar-positions',
  393. 'parent' => 'ai-toolbar-settings',
  394. 'title' => '<span class="ab-icon'.$debug_positions_class.'"></span>' . _x('Show Positions', 'Menu item', 'ad-inserter'),
  395. 'href' => set_url_parameter (AI_URL_DEBUG_POSITIONS, $debug_positions),
  396. );
  397. $paragraph_blocks = array ();
  398. for ($block = 0; $block <= 96; $block ++) {
  399. $obj = $block_object [$block];
  400. $automatic_insertion = $obj->get_automatic_insertion();
  401. if ($block == 0 || !$obj->get_disable_insertion () && ($automatic_insertion == AI_AUTOMATIC_INSERTION_BEFORE_PARAGRAPH || $automatic_insertion == AI_AUTOMATIC_INSERTION_AFTER_PARAGRAPH)) {
  402. $block_tags = trim ($block_object [$block]->get_paragraph_tags ());
  403. $direction = $block_object [$block]->get_direction_type() == AI_DIRECTION_FROM_TOP ? 't' : 'b';
  404. $paragraph_min_words = intval ($obj->get_minimum_paragraph_words());
  405. $paragraph_max_words = intval ($obj->get_maximum_paragraph_words());
  406. $paragraph_text_type = $obj->get_paragraph_text_type ();
  407. $paragraph_text = trim (html_entity_decode ($obj->get_paragraph_text()));
  408. $inside_blockquote = $obj->get_count_inside_blockquote ();
  409. $count_inside_type = $obj->get_count_inside ();
  410. $count_inside_elements = $obj->get_count_inside_elements ();
  411. $that_contain_type = $obj->get_count_inside_elements_contain ();
  412. $that_contain_text = trim (html_entity_decode ($obj->get_count_inside_elements_text ()));
  413. if ($block_tags != '') {
  414. $found = false;
  415. foreach ($paragraph_blocks as $index => $paragraph_block) {
  416. if ($paragraph_block ['tags'] == $block_tags &&
  417. $paragraph_block ['direction'] == $direction &&
  418. $paragraph_block ['min'] == $paragraph_min_words &&
  419. $paragraph_block ['max'] == $paragraph_max_words &&
  420. $paragraph_block ['text_type'] == $paragraph_text_type &&
  421. $paragraph_block ['text'] == $paragraph_text &&
  422. $paragraph_block ['blockquote'] == $inside_blockquote &&
  423. $paragraph_block ['inside_type'] == $count_inside_type &&
  424. $paragraph_block ['inside_elemets'] == $count_inside_elements &&
  425. $paragraph_block ['contain_type'] == $that_contain_type &&
  426. $paragraph_block ['contain_text'] == $that_contain_text
  427. ) {
  428. $found = true;
  429. break;
  430. }
  431. }
  432. if ($found) array_push ($paragraph_blocks [$index]['blocks'], $block); else
  433. $paragraph_blocks []= array ('blocks' => array ($block),
  434. 'tags' => $block_tags,
  435. 'direction' => $direction,
  436. 'min' => $paragraph_min_words,
  437. 'max' => $paragraph_max_words,
  438. 'text_type' => $paragraph_text_type,
  439. 'text' => $paragraph_text,
  440. 'blockquote' => $inside_blockquote,
  441. 'inside_type' => $count_inside_type,
  442. 'inside_elemets' => $count_inside_elements,
  443. 'contain_type' => $that_contain_type,
  444. 'contain_text' => $that_contain_text,
  445. );
  446. }
  447. }
  448. }
  449. $no_paragraph_counting_inside = get_no_paragraph_counting_inside ();
  450. foreach ($paragraph_blocks as $index => $paragraph_block) {
  451. $debug_block_active = $debug_positions === '' && in_array ($ai_wp_data [AI_WP_DEBUG_BLOCK], $paragraph_block ['blocks']);
  452. $block_class = $debug_block_active ? ' on' : '';
  453. // $block_class = $debug_positions === '' && in_array ($ai_wp_data [AI_WP_DEBUG_BLOCK], $paragraph_block ['blocks']) ? ' on' : '';
  454. $ai_wp_data [AI_DEBUG_MENU_ITEMS][] = array (
  455. 'id' => 'ai-toolbar-positions-'.$index,
  456. 'parent' => 'ai-toolbar-positions',
  457. 'title' => '<span class="ab-icon'.$block_class.'"></span>'.
  458. $paragraph_block ['tags'].
  459. ($paragraph_block ['direction'] == 'b' ? ' <span class="dashicons dashicons-arrow-up-alt up-icon"></span>' : '').
  460. ($paragraph_block ['min'] != 0 ? ' min '.$paragraph_block ['min']. ' ' : '').
  461. ($paragraph_block ['max'] != 0 ? ' max '.$paragraph_block ['max']. ' ' : '').
  462. ($paragraph_block ['blockquote'] ? ' +[' . $no_paragraph_counting_inside . '] ' : '').
  463. ($paragraph_block ['text'] != '' ? ($paragraph_block ['text_type'] == AI_DO_NOT_CONTAIN ? ' !has ' : ' has ').' ['.htmlentities ($paragraph_block ['text']).']' : '').
  464. ($paragraph_block ['inside_elemets'] != '' ? ($paragraph_block ['inside_type'] == AI_COUNT_ONLY ? ' insEL' : ' !insEL ').' ['.$paragraph_block ['inside_elemets'].']' : '').
  465. ($paragraph_block ['contain_text'] != '' ? ($paragraph_block ['contain_type'] == AI_CONTAIN ? ' elHAS' : ' !elHAS ').' ['.htmlentities ($paragraph_block ['contain_text']).']' : ''),
  466. // 'href' => set_url_parameter (AI_URL_DEBUG_POSITIONS, $paragraph_block ['blocks'][0]),
  467. 'href' => set_url_parameter (AI_URL_DEBUG_POSITIONS, $debug_block_active ? '' : $paragraph_block ['blocks'][0]),
  468. );
  469. }
  470. $ai_wp_data [AI_DEBUG_MENU_ITEMS][] = array (
  471. 'id' => 'ai-toolbar-tags',
  472. 'parent' => 'ai-toolbar-settings',
  473. 'title' => '<span class="ab-icon'.$debug_tags_class.'"></span>' . _x('Show HTML Tags', 'Menu item', 'ad-inserter'),
  474. 'href' => set_url_parameter (AI_URL_DEBUG_TAGS, $debug_tags),
  475. );
  476. $ai_wp_data [AI_DEBUG_MENU_ITEMS][] = array (
  477. 'id' => 'ai-toolbar-no-insertion',
  478. 'parent' => 'ai-toolbar-settings',
  479. 'title' => '<span class="ab-icon'.$debug_no_insertion_class.'"></span>' . _x('Disable Insertion', 'Menu item', 'ad-inserter'),
  480. 'href' => set_url_parameter (AI_URL_DEBUG_NO_INSERTION, $debug_no_insertion),
  481. );
  482. if (defined ('AI_ADBLOCKING_DETECTION') && AI_ADBLOCKING_DETECTION) {
  483. if ($ai_wp_data [AI_ADB_DETECTION]) {
  484. $ai_wp_data [AI_DEBUG_MENU_ITEMS][] = array (
  485. 'id' => 'ai-toolbar-adb-status',
  486. 'parent' => 'ai-toolbar-settings',
  487. 'title' => '<span class="ab-icon'.$debug_ad_blocking_status_class.'"></span>' . _x('Ad Blocking Status', 'Menu item', 'ad-inserter'),
  488. 'href' => set_url_parameter (AI_URL_DEBUG_AD_BLOCKING_STATUS, $debug_ad_blocking_status),
  489. );
  490. $ai_wp_data [AI_DEBUG_MENU_ITEMS][] = array (
  491. 'id' => 'ai-toolbar-adb',
  492. 'parent' => 'ai-toolbar-settings',
  493. 'title' => '<span class="ab-icon'.$debug_ad_blocking_class.'"></span>' . _x('Simulate Ad Blocking', 'Menu item', 'ad-inserter'),
  494. 'href' => set_url_parameter (AI_URL_DEBUG_AD_BLOCKING, $debug_ad_blocking),
  495. );
  496. }
  497. }
  498. if (!defined ('AI_DEBUGGING_DEMO')) {
  499. $ai_wp_data [AI_DEBUG_MENU_ITEMS][] = array (
  500. 'id' => 'ai-toolbar-processing',
  501. 'parent' => 'ai-toolbar-settings',
  502. 'title' => '<span class="ab-icon'.$debug_processing_class.'"></span>' . _x('Log Processing', 'Menu item', 'ad-inserter'),
  503. 'href' => set_url_parameter (AI_URL_DEBUG_PROCESSING, $debug_processing),
  504. );
  505. $ai_wp_data [AI_DEBUG_MENU_ITEMS][] = array (
  506. 'id' => 'ai-toolbar-processing-fe',
  507. 'parent' => 'ai-toolbar-processing',
  508. 'title' => '<span class="ab-icon'.$debug_processing__fe_class.'"></span>' . _x('Show Log', 'Menu item', 'ad-inserter'),
  509. 'href' => set_url_parameter (AI_URL_DEBUG_PROCESSING_FE, $debug_processing_fe),
  510. );
  511. }
  512. }
  513. function ai_toolbar ($wp_admin_bar) {
  514. global $ai_wp_data;
  515. ai_toolbar_menu_items ();
  516. foreach ($ai_wp_data [AI_DEBUG_MENU_ITEMS] as $menu_item) {
  517. $wp_admin_bar->add_node ($menu_item);
  518. }
  519. }
  520. function set_user () {
  521. global $ai_wp_data;
  522. if ($ai_wp_data [AI_WP_USER_SET]) return;
  523. if (is_user_logged_in ()) $ai_wp_data [AI_WP_USER] |= AI_USER_LOGGED_IN;
  524. if (current_user_role () >= 5) $ai_wp_data [AI_WP_USER] |= AI_USER_ADMINISTRATOR;
  525. // if (isset ($_GET [AI_URL_DEBUG_USER]) && $_GET [AI_URL_DEBUG_USER] != 0) $ai_wp_data [AI_WP_USER] = $_GET [AI_URL_DEBUG_USER];
  526. $ai_wp_data [AI_WP_USER_SET] = true;
  527. }
  528. function set_page_type () {
  529. global $ai_wp_data, $wp_query;
  530. if ($ai_wp_data [AI_WP_PAGE_TYPE] != AI_PT_NONE) return;
  531. if (is_front_page ()) $ai_wp_data [AI_WP_PAGE_TYPE] = AI_PT_HOMEPAGE;
  532. elseif (is_single()) $ai_wp_data [AI_WP_PAGE_TYPE] = AI_PT_POST;
  533. elseif (is_page()) $ai_wp_data [AI_WP_PAGE_TYPE] = AI_PT_STATIC;
  534. elseif (is_feed()) $ai_wp_data [AI_WP_PAGE_TYPE] = AI_PT_FEED;
  535. elseif (is_category()) $ai_wp_data [AI_WP_PAGE_TYPE] = AI_PT_CATEGORY;
  536. elseif (is_archive() || (is_home () && !is_front_page ())) $ai_wp_data [AI_WP_PAGE_TYPE] = AI_PT_ARCHIVE;
  537. elseif (is_admin()) $ai_wp_data [AI_WP_PAGE_TYPE] = AI_PT_ADMIN; // Admin pages may also be search pages
  538. elseif (is_search()) $ai_wp_data [AI_WP_PAGE_TYPE] = AI_PT_SEARCH;
  539. elseif (is_404()) $ai_wp_data [AI_WP_PAGE_TYPE] = AI_PT_404;
  540. if (
  541. // AMP, AMP WP
  542. function_exists ('is_amp_endpoint') && is_amp_endpoint () ||
  543. // AMP WP
  544. function_exists ('is_amp_wp') && is_amp_wp ($wp_query) ||
  545. // AMP for WP - Accelerated Mobile Pages for WordPress
  546. function_exists ('ampforwp_is_amp_endpoint') && ampforwp_is_amp_endpoint () ||
  547. // WP AMP Ninja
  548. isset ($_GET ['wpamp']) ||
  549. // WP AMP - Accelerated Mobile Pages for WordPress
  550. function_exists ('is_wp_amp') && is_wp_amp () ||
  551. // Better AMP - WordPress Complete AMP
  552. function_exists ('is_better_amp') && is_better_amp ($wp_query) ||
  553. // PenCi Soledad AMP - WordPress Complete AMP
  554. function_exists ('is_penci_amp') && is_penci_amp ($wp_query)
  555. ) {
  556. $ai_wp_data [AI_WP_AMP_PAGE] = true;
  557. define ('AI_AMP_PAGE', true);
  558. }
  559. }
  560. function ai_log_message ($message) {
  561. global $ai_last_time, $ai_processing_log;
  562. $ai_processing_log []= rtrim (sprintf ("%4d %-50s", (microtime (true) - $ai_last_time) * 1000, $message));
  563. }
  564. function ai_log_filter_content ($content_string) {
  565. $content_string = preg_replace ("/\[\[AI_[A|B]P([\d].?)\]\]/", "", $content_string);
  566. return str_replace (array ("<!--", "-->", "\n", "\r"), array ("<!++", "++>", "*n", "*r"), $content_string);
  567. }
  568. function ai_log_content (&$content) {
  569. if (strlen ($content) < 100) ai_log (ai_log_filter_content ($content) . ' ['.number_of_words ($content).' words]'); else
  570. ai_log (ai_log_filter_content (html_entity_decode (substr ($content, 0, 60))) . ' ... ' . ai_log_filter_content (html_entity_decode (substr ($content, - 60))) . ' ['.number_of_words ($content).' words]');
  571. }
  572. function ai_filter_code ($code) {
  573. $code = preg_replace ("/\[\[AI_[A|B]P([\d].?)\]\]/", "", $code);
  574. return str_replace (array ("<!--", "-->"), array ("<!++", "++>"), $code);
  575. }
  576. function ai_dump_code ($code, $max_size = 0) {
  577. if ($max_size == 0) return ai_filter_code ($code); else
  578. if ($max_size != 0 && strlen ($code) < $max_size) return ai_filter_code ($code); else
  579. return ai_filter_code (html_entity_decode (substr ($code, 0, 120))) . ' ... ' . ai_filter_code (html_entity_decode (substr ($code, - 120)));
  580. }
  581. function ai_block_insertion_status ($block, $ai_last_check) {
  582. global $block_object;
  583. if ($block < 1 || $block > 96) $block = 0;
  584. if ($ai_last_check == AI_CHECK_INSERTED) return "INSERTED";
  585. $status = "FAILED CHECK: ";
  586. $obj = $block_object [$block];
  587. switch ($ai_last_check) {
  588. case AI_CHECK_PAGE_TYPE_FRONT_PAGE: $status .= "ENABLED ON HOMEPAGE"; break;
  589. case AI_CHECK_PAGE_TYPE_STATIC_PAGE: $status .= "ENABLED ON STATIC PAGE"; break;
  590. case AI_CHECK_PAGE_TYPE_POST: $status .= "ENABLED ON POST"; break;
  591. case AI_CHECK_PAGE_TYPE_CATEGORY: $status .= "ENABLED ON CATEGORY"; break;
  592. case AI_CHECK_PAGE_TYPE_SEARCH: $status .= "ENABLED ON SEARCH"; break;
  593. case AI_CHECK_PAGE_TYPE_ARCHIVE: $status .= "ENABLED ON ARCHIVE"; break;
  594. case AI_CHECK_PAGE_TYPE_FEED: $status .= "ENABLED ON FEED"; break;
  595. case AI_CHECK_PAGE_TYPE_404: $status .= "ENABLED ON 404"; break;
  596. case AI_CHECK_DESKTOP_DEVICES: $status .= "DESKTOP DEVICES"; break;
  597. case AI_CHECK_MOBILE_DEVICES: $status .= "MOBILE DEVICES"; break;
  598. case AI_CHECK_TABLET_DEVICES: $status .= "TABLET DEVICES"; break;
  599. case AI_CHECK_PHONE_DEVICES: $status .= "PHONE DEVICES"; break;
  600. case AI_CHECK_DESKTOP_TABLET_DEVICES: $status .= "DESKTOP TABLET DEVICES"; break;
  601. case AI_CHECK_DESKTOP_PHONE_DEVICES: $status .= "DESKTOP PHONE DEVICES"; break;
  602. case AI_CHECK_CATEGORY: $status .= "CATEGORY"; break;
  603. case AI_CHECK_TAG: $status .= "TAG"; break;
  604. case AI_CHECK_TAXONOMY: $status .= "TAXONOMY"; break;
  605. case AI_CHECK_ID: $status .= "ID"; break;
  606. case AI_CHECK_URL: $status .= "URL"; break;
  607. case AI_CHECK_URL_PARAMETER: $status .= "URL PARAMETER"; break;
  608. case AI_CHECK_REFERER: $status .= "REFERER ". $obj->get_ad_domain_list(); break;
  609. case AI_CHECK_CLIENT: $status .= "CLIENT ". $obj->get_client_list(); break;
  610. case AI_CHECK_IP_ADDRESS: $status .= "IP ADDRESS ". $obj->get_ad_ip_address_list(); break;
  611. case AI_CHECK_COUNTRY: $status .= "COUNTRY ". $obj->get_ad_country_list (true); break;
  612. case AI_CHECK_SCHEDULING: $status .= "SCHEDULING"; break;
  613. case AI_CHECK_CODE: $status .= "CODE EMPTY"; break;
  614. case AI_CHECK_LOGGED_IN_USER: $status .= "LOGGED-IN USER"; break;
  615. case AI_CHECK_NOT_LOGGED_IN_USER: $status .= "NOT LOGGED-IN USER"; break;
  616. case AI_CHECK_ADMINISTRATOR: $status .= "ADMINISTRATOR"; break;
  617. case AI_CHECK_INDIVIDUALLY_DISABLED: $status .= "INDIVIDUALLY DISABLED"; break;
  618. case AI_CHECK_INDIVIDUALLY_ENABLED: $status .= "INDIVIDUALLY ENABLED"; break;
  619. case AI_CHECK_DISABLED_MANUALLY: $status .= "DISABLED BY SHORTCODE"; break;
  620. case AI_CHECK_MAX_INSERTIONS: $status .= "MAX INSERTIONS " . $obj->get_maximum_insertions (); break;
  621. case AI_CHECK_MAX_PAGE_BLOCKS: $status .= "MAX PAGE BLOCKS " . get_max_page_blocks (); break;
  622. case AI_CHECK_FILTER: $status .= ($obj->get_inverted_filter() ? 'INVERTED ' : '') . "FILTER " . $obj->get_call_filter(); break;
  623. case AI_CHECK_PARAGRAPH_COUNTING: $status .= "PARAGRAPH COUNTING"; break;
  624. case AI_CHECK_IMAGE_COUNTING: $status .= "IMAGE COUNTING"; break;
  625. case AI_CHECK_MIN_NUMBER_OF_WORDS: $status .= "MIN NUMBER OF WORDS " . intval ($obj->get_minimum_words()); break;
  626. case AI_CHECK_MAX_NUMBER_OF_WORDS: $status .= "MAX NUMBER OF WORDS " . (intval ($obj->get_maximum_words()) == 0 ? 1000000 : intval ($obj->get_maximum_words())); break;
  627. case AI_CHECK_DEBUG_NO_INSERTION: $status .= "DEBUG NO INSERTION"; break;
  628. case AI_CHECK_MAX_IMPRESSIONS: $status .= "MAX IMPRESSIONS"; break;
  629. case AI_CHECK_LIMIT_IMPRESSIONS_PER_TIME_PERIOD: $status .= "LIMIT IMPRESSIONS PER TIME PERIOD"; break;
  630. case AI_CHECK_MAX_CLICKS: $status .= "MAX CLICKS"; break;
  631. case AI_CHECK_LIMIT_CLICKS_PER_TIME_PERIOD: $status .= "LIMIT CLICKS PER TIME PERIOD"; break;
  632. case AI_CHECK_INSERTION_NOT_DISABLED: $status .= "INSERTION PAUSED"; break;
  633. case AI_CHECK_PARAGRAPH_TAGS: $status .= "PARAGRAPH TAGS"; break;
  634. case AI_CHECK_PARAGRAPHS_WITH_TAGS: $status .= "PARAGRAPHS WITH TAGS"; break;
  635. case AI_CHECK_PARAGRAPHS_AFTER_NO_COUNTING_INSIDE: $status .= "PARAGRAPHS AFTER NO COUNTING INSIDE"; break;
  636. case AI_CHECK_PARAGRAPHS_AFTER_NO_COUNTING_INSIDE_ELEMENTS: $status .= "PARAGRAPHS AFTER NO COUNTING INSIDE ELEMENTS"; break;
  637. case AI_CHECK_PARAGRAPHS_AFTER_MIN_MAX_WORDS: $status .= "PARAGRAPHS AFTER MIN MAX WORDS"; break;
  638. case AI_CHECK_PARAGRAPHS_AFTER_TEXT: $status .= "PARAGRAPHS AFTER TEXT"; break;
  639. case AI_CHECK_PARAGRAPHS_AFTER_CLEARANCE: $status .= "PARAGRAPHS AFTER CLEARANCE"; break;
  640. case AI_CHECK_PARAGRAPHS_MIN_NUMBER: $status .= "PARAGRAPHS MIN NUMBER"; break;
  641. case AI_CHECK_PARAGRAPHS_MAX_NUMBER: $status .= "PARAGRAPHS MAX NUMBER"; break;
  642. case AI_CHECK_PARAGRAPH_NUMBER: $status .= "PARAGRAPH NUMBER " . $obj->get_paragraph_number(); break;
  643. case AI_CHECK_NO_PARAGRAPHS: $status .= "NO PARAGRAPHS"; break;
  644. case AI_CHECK_DO_NOT_INSERT: $status .= "PARAGRAPH CLEARANCE"; break;
  645. case AI_CHECK_AD_ABOVE: $status .= "PARAGRAPH CLEARANCE ABOVE"; break;
  646. case AI_CHECK_AD_BELOW: $status .= "PARAGRAPH CLEARANCE BELOW"; break;
  647. case AI_CHECK_SHORTCODE_ATTRIBUTES: $status .= "SHORTCODE ATTRIBUTES"; break;
  648. case AI_CHECK_ENABLED_PHP: $status .= "PHP FUNCTION ENABLED"; break;
  649. case AI_CHECK_ENABLED_SHORTCODE: $status .= "SHORTCODE ENABLED"; break;
  650. case AI_CHECK_ENABLED_WIDGET: $status .= "WIDGET ENABLED"; break;
  651. case AI_CUSTOM_FILTER_CHECK: $status .= "CUSTOM FILTER CHECK"; break;
  652. case AI_CHECK_NONE: $status = "BLOCK $block"; break;
  653. default: $status .= "?"; break;
  654. }
  655. $ai_last_check = AI_CHECK_NONE;
  656. return $status;
  657. }
  658. function ai_log_block_status ($block, $ai_last_check) {
  659. global $block_object, $block_insertion_log, $ad_inserter_globals, $ai_wp_data;
  660. if ($block >= 1 && $ai_last_check == AI_CHECK_INSERTED) {
  661. $obj = $block_object [$block];
  662. $global_name = AI_BLOCK_COUNTER_NAME . $block;
  663. if ($obj->check_code_insertions !== null) {
  664. $block_insertion_log [] = sprintf ("% 2d BLOCK % 2d %s %s%s", $block, $block, 'CHECK', '('.$obj->check_code_insertions . ')', $ad_inserter_globals [$global_name] != 1 ? '['.$ad_inserter_globals [$global_name] . ']' : '');
  665. return '';
  666. }
  667. elseif ($obj->no_insertion_text != '') {
  668. $block_insertion_log [] = sprintf ("% 2d BLOCK % 2d %s %s", $block, $block, $obj->no_insertion_text, $ad_inserter_globals [$global_name] != 1 ? '['.$ad_inserter_globals [$global_name] . ']' : '');
  669. return '';
  670. }
  671. }
  672. return ai_log_block_insertion_status ($block, $ai_last_check);
  673. }
  674. function ai_log_block_insertion_status ($block, $ai_last_check) {
  675. global $block_insertion_log, $ad_inserter_globals;
  676. if ($block < 1) return 'NO BLOCK SHORTCODE';
  677. $global_name = AI_BLOCK_COUNTER_NAME . $block;
  678. $block_status = ai_block_insertion_status ($block, $ai_last_check);
  679. $block_insertion_log [] = sprintf ("% 2d BLOCK % 2d %s %s", $block, $block, $block_status, $ai_last_check == AI_CHECK_INSERTED && $ad_inserter_globals [$global_name] != 1 ? '['.$ad_inserter_globals [$global_name] . ']' : '');
  680. return "BLOCK $block " . $block_status;
  681. }
  682. function ai_log ($message = "") {
  683. global $ai_last_time, $ai_processing_log;
  684. if ($message != "") {
  685. if ($message [strlen ($message) - 1] == "\n") {
  686. ai_log_message (str_replace ("\n", "", $message));
  687. $ai_processing_log []= "";
  688. } else ai_log_message ($message);
  689. } else $ai_processing_log []= "";
  690. $ai_last_time = microtime (true);
  691. }
  692. function remove_debug_parameters_from_url ($url = false) {
  693. if (defined ('AI_DEBUGGING_DEMO')) {
  694. $parameters = array (AI_URL_DEBUG, AI_URL_DEBUG_PROCESSING, AI_URL_DEBUG_PROCESSING_FE);
  695. } else {
  696. $parameters = array (
  697. AI_URL_DEBUG,
  698. AI_URL_DEBUG_PROCESSING,
  699. AI_URL_DEBUG_PROCESSING_FE,
  700. AI_URL_DEBUG_PHP,
  701. AI_URL_DEBUG_BLOCKS,
  702. AI_URL_DEBUG_USER,
  703. AI_URL_DEBUG_TAGS,
  704. AI_URL_DEBUG_POSITIONS,
  705. AI_URL_DEBUG_NO_INSERTION,
  706. AI_URL_DEBUG_JAVASCRIPT,
  707. AI_URL_DEBUG_AD_BLOCKING,
  708. AI_URL_DEBUG_AD_BLOCKING_STATUS,
  709. AI_URL_DEBUG_COUNTRY,
  710. AI_URL_DEBUG_IP_ADDRESS,
  711. AI_URL_DEBUG_DISABLE_CSS_CODE,
  712. AI_URL_DEBUG_DISABLE_JS_CODE,
  713. AI_URL_DEBUG_DISABLE_PHP_PROCESSING,
  714. AI_URL_DEBUG_DISABLE_BLOCK_INSERTIONS,
  715. AI_URL_DEBUG_DISABLE_HEADER_CODE,
  716. AI_URL_DEBUG_DISABLE_FOOTER_CODE,
  717. );
  718. if (defined ('AI_ADBLOCKING_DETECTION') && AI_ADBLOCKING_DETECTION) {
  719. $parameters = array_merge ($parameters, array (AI_URL_DEBUG_AD_BLOCKING, AI_URL_DEBUG_AD_BLOCKING_STATUS));
  720. }
  721. }
  722. return remove_query_arg ($parameters, $url);
  723. }
  724. function set_url_parameter ($parameter, $value) {
  725. return add_query_arg ($parameter, $value, remove_debug_parameters_from_url ());
  726. }
  727. function number_of_words (&$content) {
  728. $text = str_replace ("\r", "", $content);
  729. $text = str_replace (array ("\n", " "), " ", $text);
  730. $text = preg_replace('#<style.*?'.'>(.*?)</style>#i', '', $text);
  731. $text = preg_replace('#<script.*?'.'>(.*?)</script>#i', '', $text);
  732. $text = htmlspecialchars_decode ($text);
  733. $text = trim (strip_tags ($text));
  734. $text = preg_replace ('#\s+#', ' ', $text);
  735. if ($text == '') return 0;
  736. return count (explode (' ', $text));
  737. }
  738. function ai_loop_check ($query, $action) {
  739. global $ai_wp_data;
  740. $ai_wp_data [AI_CONTEXT] = $action == 'loop_start' ? AI_CONTEXT_BEFORE_POST : AI_CONTEXT_AFTER_POST;
  741. if ($ai_wp_data [AI_WP_AMP_PAGE]) return true;
  742. if ($action == 'loop_end' && !method_exists ($query, 'is_main_query') && method_exists ($wp_query, 'is_main_query')) {
  743. $query = $wp_query;
  744. }
  745. if (isset ($query) && method_exists ($query, 'is_main_query')) {
  746. if ($query->is_main_query()) {
  747. if (isset ($ai_wp_data [AI_HEAD]) && !$ai_wp_data [AI_HEAD]) {
  748. return true;
  749. }
  750. }
  751. }
  752. return false;
  753. }
  754. function ai_process_head_codes ($head) {
  755. global $ai_wp_data;
  756. if (!get_disable_header_code ()) {
  757. if (!empty ($ai_wp_data [AI_HEAD_CODES])) {
  758. $head = str_replace ("<!--[AI_HEAD_CODES]-->", implode ("\n", $ai_wp_data [AI_HEAD_CODES]) . "\n", $head);
  759. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_BLOCKS) != 0) {
  760. $head = str_replace ("&lt;!--[AI_HEAD_CODES]--&gt;", '<span style=\'color: #00f;\'>' . str_replace (array ('<', '>'), array ('&lt;', '&gt;'), implode ("\\n", $ai_wp_data [AI_HEAD_CODES])) . '</span>', $head);
  761. }
  762. }
  763. foreach ($ai_wp_data [AI_HEAD_GROUPS] as $group_name => $group_codes) {
  764. $group_code = implode ("\n", $group_codes);
  765. $head = str_replace ("<!--[AI_HEAD_GROUPS $group_name]-->", $group_code, $head);
  766. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_BLOCKS) != 0) {
  767. $head = str_replace ("&lt;!--[AI_HEAD_GROUPS $group_name]--&gt;", str_replace (array ('<', '>'), array ('<span style=\'color: #c0f;\'>&lt;', '&gt;</span>'), implode ("\\n", $group_codes)), $head);
  768. }
  769. }
  770. }
  771. $head = preg_replace ("#<!--\[AI(.+?)\]-->#", '', $head);
  772. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_BLOCKS) != 0) {
  773. $head = preg_replace ("#&lt;!--\[AI(.+?)\]--&gt;#", '', $head);
  774. }
  775. $head = preg_replace ("#<script .+js/ai\-jquery\.js.+></script>\n#", '', $head);
  776. return ($head);
  777. }
  778. function ai_buffering_start_hook () {
  779. global $ai_wp_data;
  780. if (defined ('AI_BUFFERING')) {
  781. if (get_output_buffering ()) {
  782. if ($ai_wp_data [AI_WP_PAGE_TYPE] != AI_PT_AJAX && !$ai_wp_data [AI_CODE_FOR_IFRAME]) {
  783. ai_buffering_start ();
  784. }
  785. }
  786. }
  787. }
  788. function ai_buffering_start () {
  789. global $ai_wp_data;
  790. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
  791. ai_log ("BUFFERING START: level " . ob_get_level () );
  792. }
  793. ob_start ();
  794. if (!defined ('AI_BUFFERING_START')) define ('AI_BUFFERING_START', true);
  795. }
  796. function ai_buffering_end () {
  797. global $ai_wp_data, $ai_total_plugin_time, $ai_db_options_extract, $block_object, $ad_inserter_globals;
  798. if (!defined ('AI_BUFFERING_START')) return;
  799. $page = ob_get_clean();
  800. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
  801. ai_log ("BUFFERING END: level " . ob_get_level ());
  802. $start_time = microtime (true);
  803. }
  804. $matches = preg_split ('/(<body.*?'.'>)/i', $page, - 1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
  805. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
  806. ai_log ("BUFFER body matches: " . count ($matches));
  807. ai_log ("PHP VERSION COMPARE to 5.4: " . (version_compare (phpversion (), "5.4", ">=") ? 'YES' : 'NO'));
  808. }
  809. if (version_compare (phpversion (), "5.4", ">=") && count ($matches) == 3) {
  810. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
  811. ai_log ("BUFFER PROCESSING");
  812. }
  813. $head = $matches [0];
  814. $body_tag = $matches [1];
  815. $body = $matches [2];
  816. if (isset ($ai_wp_data [AI_BODY_STYLE])) {
  817. if (preg_match ('#style=[\'"](.*?)[\'"]#i', $body_tag, $body_style)) {
  818. $old_style = $body_style [1];
  819. if ($old_style != '') {
  820. $old_style = trim ($old_style, ' ;');
  821. if ($old_style != '') {
  822. $old_style .= '; ';
  823. }
  824. }
  825. $new_style = $old_style . $ai_wp_data [AI_BODY_STYLE];
  826. $body_tag = str_ireplace ($body_style [0], 'style="'.$new_style.'"', $body_tag);
  827. } else {
  828. $body_tag = str_replace ('>', ' style="' . $ai_wp_data [AI_BODY_STYLE] . '">', $body_tag);
  829. }
  830. }
  831. if (isset ($ai_db_options_extract [HTML_ELEMENT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && class_exists ('DOMDocument')) {
  832. // $php_version = explode ('.', PHP_VERSION);
  833. // if ($php_version [0] > 5 || ($php_version [0] == 5 && $php_version [1] >= 3)) {
  834. // // phpQuery with anonymous functions
  835. // require_once ('includes/phpQuery.php');
  836. // } else {
  837. // // phpQuery with create_function
  838. // require_once ('includes/phpQuery_52.php');
  839. // }
  840. require_once ('includes/phpQuery.php');
  841. $no_closing_tag = array ('img', 'hr', 'br');
  842. $multibyte = $ai_wp_data [AI_MBSTRING_LOADED] && get_paragraph_counting_functions() == AI_MULTIBYTE_PARAGRAPH_COUNTING_FUNCTIONS;
  843. foreach ($ai_db_options_extract [HTML_ELEMENT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]] as $block) {
  844. $obj = $block_object [$block];
  845. $obj->clear_code_cache ();
  846. switch ($obj->get_automatic_insertion ()) {
  847. case AI_AUTOMATIC_INSERTION_BEFORE_HTML_ELEMENT:
  848. $insertion_position = 'before';
  849. break;
  850. case AI_AUTOMATIC_INSERTION_AFTER_HTML_ELEMENT:
  851. $insertion_position = 'after';
  852. break;
  853. case AI_AUTOMATIC_INSERTION_INSIDE_HTML_ELEMENT:
  854. switch ($obj->get_inside_element ()) {
  855. case AI_HTML_PREPEND_CONTENT:
  856. $insertion_position = 'prepend';
  857. break;
  858. case AI_HTML_APPEND_CONTENT:
  859. $insertion_position = 'append';
  860. break;
  861. case AI_HTML_REPLACE_CONTENT:
  862. $insertion_position = 'replace-content';
  863. break;
  864. case AI_HTML_REPLACE_ELEMENT:
  865. $insertion_position = 'replace-element';
  866. break;
  867. }
  868. break;
  869. }
  870. $selector = $obj->get_html_selector ();
  871. libxml_use_internal_errors (true);
  872. $content = phpQuery::newDocumentHTML ($body);
  873. libxml_use_internal_errors (false);
  874. foreach (pq ($selector) as $element) {
  875. if (in_array ($element->tagName, $no_closing_tag)) {
  876. switch ($insertion_position) {
  877. case 'replace-content':
  878. case 'prepend':
  879. case 'append':
  880. $insertion_position = 'after';
  881. break;
  882. }
  883. }
  884. switch ($insertion_position) {
  885. case 'before':
  886. pq ($element)->before (AI_MARKER_START.$element->tagName.AI_MARKER_END);
  887. break;
  888. case 'after':
  889. pq ($element)->after (AI_MARKER_START.$element->tagName.AI_MARKER_END);
  890. break;
  891. case 'prepend':
  892. pq ($element)->prepend (AI_MARKER_START.$element->tagName.AI_MARKER_END);
  893. break;
  894. case 'append':
  895. pq ($element)->append (AI_MARKER_START.$element->tagName.AI_MARKER_END);
  896. break;
  897. case 'replace-content':
  898. pq ($element)->prepend (AI_MARKER_START.'-'.$element->tagName.'-'.AI_MARKER_END);
  899. pq ($element)->append (AI_MARKER_START.'='.$element->tagName.'='.AI_MARKER_END);
  900. break;
  901. case 'replace-element':
  902. pq ($element)->before (AI_MARKER_START.'-'.$element->tagName.'-'.AI_MARKER_END);
  903. pq ($element)->after (AI_MARKER_START.'='.$element->tagName.'='.AI_MARKER_END);
  904. break;
  905. }
  906. }
  907. switch ($insertion_position) {
  908. case 'replace-content':
  909. case 'replace-element':
  910. $markers = preg_split ('/('.AI_MARKER_START.'-.*?-'.AI_MARKER_END.')/', $content->htmlOuter (), - 1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
  911. $markers2 = preg_split ('/('.AI_MARKER_START.'=.*?='.AI_MARKER_END.')/', $content->htmlOuter (), - 1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
  912. break;
  913. default:
  914. $markers = preg_split ('/('.AI_MARKER_START.'.*?'.AI_MARKER_END.')/', $content->htmlOuter (), - 1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
  915. break;
  916. }
  917. $content_before = '';
  918. $insertions = array ();
  919. foreach ($markers as $marker) {
  920. switch ($insertion_position) {
  921. case 'replace-content':
  922. case 'replace-element':
  923. $marker_start_string = AI_MARKER_START.'-';
  924. break;
  925. default:
  926. $marker_start_string = AI_MARKER_START;
  927. break;
  928. }
  929. if (strpos ($marker, $marker_start_string) === 0) {
  930. switch ($insertion_position) {
  931. case 'replace-content':
  932. case 'replace-element':
  933. $tag = str_replace (array (AI_MARKER_START.'-', '-'.AI_MARKER_END), '', $marker);
  934. break;
  935. default:
  936. $tag = str_replace (array (AI_MARKER_START, AI_MARKER_END), '', $marker);
  937. break;
  938. }
  939. switch ($insertion_position) {
  940. case 'before':
  941. case 'replace-element':
  942. $tag_string = "<{$tag}";
  943. break;
  944. case 'after':
  945. if (in_array ($tag, $no_closing_tag)) $tag_string = '>'; else $tag_string = "</{$tag}>";
  946. break;
  947. case 'prepend':
  948. case 'replace-content':
  949. $tag_string = "<{$tag}[^>]*>";
  950. break;
  951. case 'append':
  952. $tag_string = "</{$tag}>";
  953. break;
  954. }
  955. preg_match_all ("#{$tag_string}#i", $content_before, $tag_matches);
  956. switch ($insertion_position) {
  957. case 'before':
  958. case 'replace-element':
  959. $insertions []= array ($tag_string, count ($tag_matches [0]) + 1);
  960. break;
  961. case 'after':
  962. $insertions []= array ($tag_string, count ($tag_matches [0]));
  963. break;
  964. case 'replace-content':
  965. case 'prepend':
  966. $insertions []= array ($tag_string, count ($tag_matches [0]));
  967. break;
  968. case 'append':
  969. $insertions []= array ($tag_string, count ($tag_matches [0]) + 1);
  970. break;
  971. }
  972. continue;
  973. }
  974. $content_before .= $marker;
  975. }
  976. switch ($insertion_position) {
  977. case 'replace-content':
  978. case 'replace-element':
  979. $content_before = '';
  980. $insertions2 = array ();
  981. foreach ($markers2 as $marker) {
  982. if (strpos ($marker, AI_MARKER_START.'=') === 0) {
  983. $tag = str_replace (array (AI_MARKER_START.'=', '='.AI_MARKER_END), '', $marker);
  984. $tag_string = "</{$tag}>";
  985. preg_match_all ("#{$tag_string}#i", $content_before, $tag_matches);
  986. switch ($insertion_position) {
  987. case 'replace-content':
  988. $insertions2 []= array ($tag_string, count ($tag_matches [0]) + 1);
  989. break;
  990. case 'replace-element':
  991. $insertions2 []= array ($tag_string, count ($tag_matches [0]));
  992. break;
  993. }
  994. continue;
  995. }
  996. $content_before .= $marker;
  997. }
  998. break;
  999. }
  1000. $insertion_offsets = array ();
  1001. foreach ($insertions as $insertion) {
  1002. $tag = $insertion [0];
  1003. $tag_counter = $insertion [1];
  1004. preg_match_all ("#$tag#i", $body, $org_tag_matches, PREG_OFFSET_CAPTURE);
  1005. if (isset ($org_tag_matches [0][$tag_counter - 1])) {
  1006. switch ($insertion_position) {
  1007. case 'before':
  1008. case 'replace-element':
  1009. $insertion_offsets []= $org_tag_matches [0][$tag_counter - 1][1];
  1010. break;
  1011. case 'after':
  1012. $insertion_offsets []= $org_tag_matches [0][$tag_counter - 1][1] + strlen ($tag);
  1013. break;
  1014. case 'prepend':
  1015. case 'replace-content':
  1016. $insertion_offsets []= $org_tag_matches [0][$tag_counter - 1][1] + strlen ($org_tag_matches [0][$tag_counter - 1][0]);
  1017. break;
  1018. case 'append':
  1019. $insertion_offsets []= $org_tag_matches [0][$tag_counter - 1][1];
  1020. break;
  1021. }
  1022. }
  1023. }
  1024. sort ($insertion_offsets);
  1025. switch ($insertion_position) {
  1026. case 'replace-content':
  1027. case 'replace-element':
  1028. $insertion_offsets2 = array ();
  1029. foreach ($insertions2 as $insertion) {
  1030. $tag = $insertion [0];
  1031. $tag_counter = $insertion [1];
  1032. preg_match_all ("#$tag#i", $body, $org_tag_matches, PREG_OFFSET_CAPTURE);
  1033. if (isset ($org_tag_matches [0][$tag_counter - 1])) {
  1034. switch ($insertion_position) {
  1035. case 'replace-content':
  1036. $insertion_offsets2 []= $org_tag_matches [0][$tag_counter - 1][1];
  1037. break;
  1038. case 'replace-element':
  1039. $insertion_offsets2 []= $org_tag_matches [0][$tag_counter - 1][1] + strlen ($tag);
  1040. break;
  1041. }
  1042. }
  1043. }
  1044. sort ($insertion_offsets2);
  1045. break;
  1046. }
  1047. $new_content = '';
  1048. $current_offset = 0;
  1049. switch ($insertion_position) {
  1050. case 'before':
  1051. $action = 'before_html_element';
  1052. // translators: Debugging position name Before HTML element
  1053. $action_name = __('Before', 'ad-inserter') . ' ' . $selector;
  1054. break;
  1055. case 'after':
  1056. $action = 'after_html_element';
  1057. // translators: Debugging position name After HTML element
  1058. $action_name = __('After', 'ad-inserter') . ' ' . $selector;
  1059. break;
  1060. case 'prepend':
  1061. $action = 'prepend_html_element';
  1062. // translators: Debugging position name Prepend content of HTML element (before the content of the HTML element)
  1063. $action_name = __('Prepend content', 'ad-inserter') . ' ' . $selector;
  1064. break;
  1065. case 'append':
  1066. $action = 'append_html_element';
  1067. // translators: Debugging position name Append content of HTML element (after the content of the HTML element)
  1068. $action_name = __('Append content', 'ad-inserter') . ' ' . $selector;
  1069. break;
  1070. case 'replace-content':
  1071. $action = 'replace_content_html_element';
  1072. // translators: Debugging position name Replace content of HTML element
  1073. $action_name = __('Replace content', 'ad-inserter') . ' ' . $selector;
  1074. break;
  1075. case 'replace-element':
  1076. // translators: Debugging position name Replace HTML element
  1077. $action = 'replace_html_element';
  1078. $action_name = __('Replace', 'ad-inserter') . ' ' . $selector;
  1079. break;
  1080. }
  1081. $globals_name = 'AI_' . strtoupper ($action) . '_COUNTER';
  1082. unset ($ad_inserter_globals [$globals_name]);
  1083. $ai_db_options_extract [$action . CUSTOM_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]] = array ($block);
  1084. foreach ($insertion_offsets as $index => $insertion_offset) {
  1085. if ($multibyte)
  1086. $new_content .= mb_substr ($body, $current_offset, $insertion_offset - $current_offset);
  1087. $new_content .= substr ($body, $current_offset, $insertion_offset - $current_offset);
  1088. switch ($insertion_position) {
  1089. case 'replace-content':
  1090. case 'replace-element':
  1091. if (isset ($insertion_offsets2 [$index])) {
  1092. $current_offset = $insertion_offsets2 [$index];
  1093. } else $current_offset = $insertion_offset;
  1094. break;
  1095. default:
  1096. $current_offset = $insertion_offset;
  1097. break;
  1098. }
  1099. ob_start ();
  1100. // Dummy
  1101. ai_custom_hook ($action, AI_AUTOMATIC_INSERTION_DISABLED, $action_name);
  1102. $new_content .= ob_get_clean();
  1103. }
  1104. unset ($ai_db_options_extract [$action . CUSTOM_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]);
  1105. $new_content .= substr ($body, $current_offset);
  1106. $body = $new_content;
  1107. }
  1108. }
  1109. $head = ai_process_head_codes ($head);
  1110. echo $head, $body_tag;
  1111. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_POSITIONS) != 0) {
  1112. $class = AI_DEBUG_STATUS_CLASS.' status-ok';
  1113. // translators: Debugging message when output buffering is enabled
  1114. echo "<section class='$class'>" . __('OUTPUT BUFFERING', 'ad-inserter') . '</section>';
  1115. }
  1116. // translators: Debugging position
  1117. ai_custom_hook ('above_header', AI_AUTOMATIC_INSERTION_ABOVE_HEADER, 'Above Header', __('Above Header', 'ad-inserter'));
  1118. echo $body;
  1119. } else echo $page;
  1120. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
  1121. ai_log ("BUFFER PROCESSING END: ". number_format (1000 * (microtime (true) - $start_time), 2)." ms\n");
  1122. $ai_wp_data [AI_PROCESSING_TIME] = false;
  1123. }
  1124. }
  1125. function ai_post_check ($post, $action) {
  1126. global $ai_wp_data, $ad_inserter_globals;
  1127. if ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_POST) return false;
  1128. if ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_STATIC) return false;
  1129. // Don't use the hook before the wp_head hook ends
  1130. if (!isset ($ai_wp_data [AI_HEAD]) || $ai_wp_data [AI_HEAD]) {
  1131. return false;
  1132. }
  1133. // in_the_loop () is not used on AMP pages (however, AMP plugin uses it)
  1134. switch ($ai_wp_data [AI_WP_AMP_PAGE]) {
  1135. case true:
  1136. if ($ai_wp_data [AI_POST_POSITION] != AI_POST_POSITION_IN_POST) return false;
  1137. // include_once (ABSPATH . 'wp-admin/includes/plugin.php');
  1138. // if (is_plugin_active ('amp/amp.php')) {
  1139. // if (!in_the_loop()) return false;
  1140. // } else {
  1141. // // For other AMP plugins
  1142. // if ($ai_wp_data [AI_POST_POSITION] != AI_POST_POSITION_IN_POST) return false;
  1143. // }
  1144. break;
  1145. default:
  1146. if (!in_the_loop()) return false;
  1147. break;
  1148. }
  1149. // Skip insertion before the first post
  1150. if (!defined ('AI_POST_CHECK')) {
  1151. define ('AI_POST_CHECK', true);
  1152. return false;
  1153. }
  1154. $ai_wp_data [AI_CONTEXT] = AI_CONTEXT_BETWEEN_POSTS;
  1155. return true;
  1156. }
  1157. function ai_content_marker () {
  1158. global $ai_wp_data;
  1159. if ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_AJAX ||
  1160. get_disable_html_code ()) return;
  1161. echo '<span class="ai-content"></span>', "\n";
  1162. }
  1163. function ai_mark_loop_start () {
  1164. global $ai_wp_data;
  1165. $ai_wp_data [AI_POST_POSITION] = AI_POST_POSITION_IN_POST;
  1166. }
  1167. function ai_mark_loop_end () {
  1168. global $ai_wp_data;
  1169. $ai_wp_data [AI_POST_POSITION] = AI_POST_POSITION_AFTER_POST;
  1170. }
  1171. function ai_hook_function_loop_start ($hook_parameter) {
  1172. ai_custom_hook ('loop_start', AI_AUTOMATIC_INSERTION_BEFORE_POST, AI_TEXT_ENG_BEFORE_POST, AI_TEXT_BEFORE_POST, $hook_parameter, 'ai_loop_check');
  1173. }
  1174. function ai_hook_function_loop_end ($hook_parameter) {
  1175. ai_custom_hook ('loop_end', AI_AUTOMATIC_INSERTION_AFTER_POST, AI_TEXT_ENG_AFTER_POST, AI_TEXT_AFTER_POST, $hook_parameter, 'ai_loop_check');
  1176. }
  1177. function ai_hook_function_post ($hook_parameter) {
  1178. ai_custom_hook ('the_post', AI_AUTOMATIC_INSERTION_BETWEEN_POSTS, AI_TEXT_ENG_BETWEEN_POSTS, AI_TEXT_BETWEEN_POSTS, $hook_parameter, 'ai_post_check');
  1179. }
  1180. function ai_hook_function_footer () {
  1181. ai_custom_hook ('wp_footer', AI_AUTOMATIC_INSERTION_FOOTER, AI_TEXT_ENG_FOOTER, AI_TEXT_FOOTER);
  1182. }
  1183. // Code for PHP VERSION >= 5.3.0
  1184. //function ai_get_custom_hook_function ($action, $insertion_type, $name) {
  1185. // return function () use ($action, $insertion_type, $name) {
  1186. // ai_custom_hook ($action, $insertion_type, $name);
  1187. // };
  1188. //}
  1189. // Code for PHP VERSION < 5.3.0
  1190. function ai_custom_hook_function_0 () {
  1191. global $ai_custom_hooks;
  1192. ai_custom_hook ($ai_custom_hooks [0]['action'], AI_AUTOMATIC_INSERTION_CUSTOM_HOOK + 0, $ai_custom_hooks [0]['name']);
  1193. }
  1194. function ai_custom_hook_function_1 () {
  1195. global $ai_custom_hooks;
  1196. ai_custom_hook ($ai_custom_hooks [1]['action'], AI_AUTOMATIC_INSERTION_CUSTOM_HOOK + 1, $ai_custom_hooks [1]['name']);
  1197. }
  1198. function ai_custom_hook_function_2 () {
  1199. global $ai_custom_hooks;
  1200. ai_custom_hook ($ai_custom_hooks [2]['action'], AI_AUTOMATIC_INSERTION_CUSTOM_HOOK + 2, $ai_custom_hooks [2]['name']);
  1201. }
  1202. function ai_custom_hook_function_3 () {
  1203. global $ai_custom_hooks;
  1204. ai_custom_hook ($ai_custom_hooks [3]['action'], AI_AUTOMATIC_INSERTION_CUSTOM_HOOK + 3, $ai_custom_hooks [3]['name']);
  1205. }
  1206. function ai_custom_hook_function_4 () {
  1207. global $ai_custom_hooks;
  1208. ai_custom_hook ($ai_custom_hooks [4]['action'], AI_AUTOMATIC_INSERTION_CUSTOM_HOOK + 4, $ai_custom_hooks [4]['name']);
  1209. }
  1210. function ai_custom_hook_function_5 () {
  1211. global $ai_custom_hooks;
  1212. ai_custom_hook ($ai_custom_hooks [5]['action'], AI_AUTOMATIC_INSERTION_CUSTOM_HOOK + 5, $ai_custom_hooks [5]['name']);
  1213. }
  1214. function ai_custom_hook_function_6 () {
  1215. global $ai_custom_hooks;
  1216. ai_custom_hook ($ai_custom_hooks [6]['action'], AI_AUTOMATIC_INSERTION_CUSTOM_HOOK + 6, $ai_custom_hooks [6]['name']);
  1217. }
  1218. function ai_custom_hook_function_7 () {
  1219. global $ai_custom_hooks;
  1220. ai_custom_hook ($ai_custom_hooks [7]['action'], AI_AUTOMATIC_INSERTION_CUSTOM_HOOK + 7, $ai_custom_hooks [7]['name']);
  1221. }
  1222. function ai_custom_hook_function_8 () {
  1223. global $ai_custom_hooks;
  1224. ai_custom_hook ($ai_custom_hooks [8]['action'], AI_AUTOMATIC_INSERTION_CUSTOM_HOOK + 8, $ai_custom_hooks [8]['name']);
  1225. }
  1226. function ai_custom_hook_function_9 () {
  1227. global $ai_custom_hooks;
  1228. ai_custom_hook ($ai_custom_hooks [9]['action'], AI_AUTOMATIC_INSERTION_CUSTOM_HOOK + 9, $ai_custom_hooks [9]['name']);
  1229. }
  1230. function ai_custom_hook_function_10 () {
  1231. global $ai_custom_hooks;
  1232. ai_custom_hook ($ai_custom_hooks [10]['action'], AI_AUTOMATIC_INSERTION_CUSTOM_HOOK + 10, $ai_custom_hooks [10]['name']);
  1233. }
  1234. function ai_custom_hook_function_11 () {
  1235. global $ai_custom_hooks;
  1236. ai_custom_hook ($ai_custom_hooks [11]['action'], AI_AUTOMATIC_INSERTION_CUSTOM_HOOK + 11, $ai_custom_hooks [11]['name']);
  1237. }
  1238. function ai_custom_hook_function_12 () {
  1239. global $ai_custom_hooks;
  1240. ai_custom_hook ($ai_custom_hooks [12]['action'], AI_AUTOMATIC_INSERTION_CUSTOM_HOOK + 12, $ai_custom_hooks [12]['name']);
  1241. }
  1242. function ai_custom_hook_function_13 () {
  1243. global $ai_custom_hooks;
  1244. ai_custom_hook ($ai_custom_hooks [13]['action'], AI_AUTOMATIC_INSERTION_CUSTOM_HOOK + 13, $ai_custom_hooks [13]['name']);
  1245. }
  1246. function ai_custom_hook_function_14 () {
  1247. global $ai_custom_hooks;
  1248. ai_custom_hook ($ai_custom_hooks [14]['action'], AI_AUTOMATIC_INSERTION_CUSTOM_HOOK + 14, $ai_custom_hooks [14]['name']);
  1249. }
  1250. function ai_custom_hook_function_15 () {
  1251. global $ai_custom_hooks;
  1252. ai_custom_hook ($ai_custom_hooks [15]['action'], AI_AUTOMATIC_INSERTION_CUSTOM_HOOK + 15, $ai_custom_hooks [15]['name']);
  1253. }
  1254. function ai_custom_hook_function_16 () {
  1255. global $ai_custom_hooks;
  1256. ai_custom_hook ($ai_custom_hooks [16]['action'], AI_AUTOMATIC_INSERTION_CUSTOM_HOOK + 16, $ai_custom_hooks [16]['name']);
  1257. }
  1258. function ai_custom_hook_function_17 () {
  1259. global $ai_custom_hooks;
  1260. ai_custom_hook ($ai_custom_hooks [17]['action'], AI_AUTOMATIC_INSERTION_CUSTOM_HOOK + 17, $ai_custom_hooks [17]['name']);
  1261. }
  1262. function ai_custom_hook_function_18 () {
  1263. global $ai_custom_hooks;
  1264. ai_custom_hook ($ai_custom_hooks [18]['action'], AI_AUTOMATIC_INSERTION_CUSTOM_HOOK + 18, $ai_custom_hooks [18]['name']);
  1265. }
  1266. function ai_custom_hook_function_19 () {
  1267. global $ai_custom_hooks;
  1268. ai_custom_hook ($ai_custom_hooks [19]['action'], AI_AUTOMATIC_INSERTION_CUSTOM_HOOK + 19, $ai_custom_hooks [19]['name']);
  1269. }
  1270. function ai_wp_hook () {
  1271. global $ai_wp_data, $ai_db_options_extract, $ad_inserter_globals, $ai_total_plugin_time, $ai_walker, $ai_custom_hooks;
  1272. if (defined ('AI_WP_HOOK')) return;
  1273. define ('AI_WP_HOOK', true);
  1274. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
  1275. ai_log ("WP HOOK START");
  1276. $ai_wp_data [AI_PROCESSING_TIME] = true;
  1277. $start_time = microtime (true);
  1278. }
  1279. set_page_type ();
  1280. set_user ();
  1281. ai_http_header ();
  1282. if (($ai_wp_data [AI_WP_USER] & AI_USER_ADMINISTRATOR) != 0 && get_disable_caching ()) ai_disable_caching ();
  1283. if ($ai_wp_data [AI_WP_PAGE_TYPE] != AI_PT_ADMIN &&
  1284. ($ai_wp_data [AI_WP_USER] & AI_USER_ADMINISTRATOR) != 0 &&
  1285. get_admin_toolbar_debugging () &&
  1286. (!is_multisite() || is_main_site () || multisite_settings_page_enabled ()))
  1287. add_action ('admin_bar_menu', 'ai_toolbar', 9920);
  1288. $url_debugging = get_remote_debugging () || ($ai_wp_data [AI_WP_USER] & AI_USER_ADMINISTRATOR) != 0 || defined ('AI_DEBUGGING_DEMO');
  1289. if (!is_admin() || defined ('DOING_AJAX') || defined ('AI_DEBUGGING_DEMO')) {
  1290. if (isset ($_GET [AI_URL_DEBUG]) && $_GET [AI_URL_DEBUG] == 0) {
  1291. if (isset ($_COOKIE ['AI_WP_DEBUGGING'])) {
  1292. unset ($_COOKIE ['AI_WP_DEBUGGING']);
  1293. setcookie ('AI_WP_DEBUGGING', '', time() - (15 * 60), COOKIEPATH);
  1294. }
  1295. if (isset ($_COOKIE ['AI_WP_DEBUG_BLOCK'])) {
  1296. unset ($_COOKIE ['AI_WP_DEBUG_BLOCK']);
  1297. setcookie ('AI_WP_DEBUG_BLOCK', '', time() - (15 * 60), COOKIEPATH);
  1298. }
  1299. } else {
  1300. $ai_wp_data [AI_WP_DEBUGGING] = isset ($_COOKIE ['AI_WP_DEBUGGING']) ? $ai_wp_data [AI_WP_DEBUGGING] | ($_COOKIE ['AI_WP_DEBUGGING'] & ~AI_DEBUG_PROCESSING) : $ai_wp_data [AI_WP_DEBUGGING];
  1301. $ai_wp_data [AI_WP_DEBUG_BLOCK] = isset ($_COOKIE ['AI_WP_DEBUG_BLOCK']) ? $_COOKIE ['AI_WP_DEBUG_BLOCK'] : 0;
  1302. if (isset ($_GET [AI_URL_DEBUG_BLOCKS]))
  1303. if ($_GET [AI_URL_DEBUG_BLOCKS] && $url_debugging) $ai_wp_data [AI_WP_DEBUGGING] |= AI_DEBUG_BLOCKS; else $ai_wp_data [AI_WP_DEBUGGING] &= ~AI_DEBUG_BLOCKS;
  1304. if (isset ($_GET [AI_URL_DEBUG_TAGS]))
  1305. if ($_GET [AI_URL_DEBUG_TAGS] && $url_debugging) $ai_wp_data [AI_WP_DEBUGGING] |= AI_DEBUG_TAGS; else $ai_wp_data [AI_WP_DEBUGGING] &= ~AI_DEBUG_TAGS;
  1306. if (isset ($_GET [AI_URL_DEBUG_NO_INSERTION]))
  1307. if ($_GET [AI_URL_DEBUG_NO_INSERTION] && $url_debugging) $ai_wp_data [AI_WP_DEBUGGING] |= AI_DEBUG_NO_INSERTION; else $ai_wp_data [AI_WP_DEBUGGING] &= ~AI_DEBUG_NO_INSERTION;
  1308. if (isset ($_GET [AI_URL_DEBUG_AD_BLOCKING_STATUS]))
  1309. if ($_GET [AI_URL_DEBUG_AD_BLOCKING_STATUS] && $url_debugging) $ai_wp_data [AI_WP_DEBUGGING] |= AI_DEBUG_AD_BLOCKING_STATUS; else $ai_wp_data [AI_WP_DEBUGGING] &= ~AI_DEBUG_AD_BLOCKING_STATUS;
  1310. if (isset ($_GET [AI_URL_DEBUG_AD_BLOCKING]))
  1311. if ($_GET [AI_URL_DEBUG_AD_BLOCKING] && $url_debugging) $ai_wp_data [AI_WP_DEBUGGING] |= AI_DEBUG_AD_BLOCKING; else $ai_wp_data [AI_WP_DEBUGGING] &= ~AI_DEBUG_AD_BLOCKING;
  1312. if (isset ($_GET [AI_URL_DEBUG_POSITIONS])) {
  1313. $secret = isset ($_GET ['ai-secret']) && $_GET ['ai-secret'] == ai_secret_key ();
  1314. if ($secret) {
  1315. ai_disable_caching ();
  1316. }
  1317. if ($_GET [AI_URL_DEBUG_POSITIONS] !== '' && ($url_debugging || $secret)) $ai_wp_data [AI_WP_DEBUGGING] |= AI_DEBUG_POSITIONS; else $ai_wp_data [AI_WP_DEBUGGING] &= ~AI_DEBUG_POSITIONS;
  1318. if (is_numeric ($_GET [AI_URL_DEBUG_POSITIONS])) $ai_wp_data [AI_WP_DEBUG_BLOCK] = intval ($_GET [AI_URL_DEBUG_POSITIONS]);
  1319. if ($ai_wp_data [AI_WP_DEBUG_BLOCK] < 0 || $ai_wp_data [AI_WP_DEBUG_BLOCK] > 96) $ai_wp_data [AI_WP_DEBUG_BLOCK] = 0;
  1320. }
  1321. if (!defined ('AI_DEBUGGING_DEMO')) {
  1322. if ($ai_wp_data [AI_WP_DEBUGGING] != 0) {
  1323. if (!isset ($_GET ['no-cookie'])) {
  1324. setcookie ('AI_WP_DEBUGGING', $ai_wp_data [AI_WP_DEBUGGING], time() + AI_COOKIE_TIME, COOKIEPATH);
  1325. }
  1326. } else if (isset ($_COOKIE ['AI_WP_DEBUGGING'])) setcookie ('AI_WP_DEBUGGING', '', time() - (15 * 60), COOKIEPATH);
  1327. if ($ai_wp_data [AI_WP_DEBUG_BLOCK] != 0) {
  1328. if (!isset ($_GET ['no-cookie'])) {
  1329. setcookie ('AI_WP_DEBUG_BLOCK', $ai_wp_data [AI_WP_DEBUG_BLOCK], time() + AI_COOKIE_TIME, COOKIEPATH);
  1330. }
  1331. } else if (isset ($_COOKIE ['AI_WP_DEBUG_BLOCK'])) setcookie ('AI_WP_DEBUG_BLOCK', '', time() - (15 * 60), COOKIEPATH);
  1332. if ($ai_wp_data [AI_WP_DEBUGGING] != 0 || isset ($_GET [AI_URL_DEBUG])) {
  1333. ai_disable_caching ();
  1334. }
  1335. if ($ai_wp_data [AI_FRONTEND_JS_DEBUGGING] && ($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_BLOCKS) != 0 && get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_SERVER_SIDE_W3TC && !defined ('AI_NO_W3TC')) {
  1336. $ai_wp_data [AI_W3TC_DEBUGGING] = true;
  1337. }
  1338. } else {
  1339. if ($ai_wp_data [AI_WP_DEBUGGING] != 0) {
  1340. ai_disable_caching ();
  1341. }
  1342. }
  1343. }
  1344. }
  1345. if ($ai_wp_data [AI_HTML_ELEMENT_SELECTION]) {
  1346. add_filter ('show_admin_bar', '__return_false', 999999);
  1347. $ai_wp_data [AI_WP_DEBUGGING] = 0;
  1348. }
  1349. elseif (($ai_wp_data [AI_WP_USER] & AI_USER_LOGGED_IN) == 0 &&
  1350. ((get_remote_debugging () && ($ai_wp_data [AI_WP_DEBUGGING] != 0 || (isset ($_GET [AI_URL_DEBUG]) && $_GET [AI_URL_DEBUG] == 1))) ||
  1351. defined ('AI_DEBUGGING_DEMO'))) {
  1352. function ai_login_adminbar ($wp_admin_bar) {
  1353. $wp_admin_bar->add_menu (array ('id' => 'ai-toolbar-login', 'title' => _x('Log In', 'Menu item', 'ad-inserter'), 'href' => wp_login_url()));
  1354. }
  1355. add_filter ('show_admin_bar', '__return_true', 999999);
  1356. add_action ('admin_bar_menu', 'ai_toolbar', 9920);
  1357. if (!defined ('AI_DEBUGGING_DEMO')) {
  1358. add_action ('admin_bar_menu', 'ai_login_adminbar' );
  1359. }
  1360. }
  1361. if (($ai_wp_data [AI_WP_USER] & AI_USER_ADMINISTRATOR) != 0 && get_force_admin_toolbar ()) {
  1362. add_filter ('show_admin_bar', '__return_true', 999999);
  1363. }
  1364. $debug_positions = ($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_POSITIONS) != 0;
  1365. $debug_tags_positions = ($ai_wp_data [AI_WP_DEBUGGING] & (AI_DEBUG_POSITIONS | AI_DEBUG_TAGS)) != 0;
  1366. $debug_tags_positions_blocks = ($ai_wp_data [AI_WP_DEBUGGING] & (AI_DEBUG_POSITIONS | AI_DEBUG_TAGS | AI_DEBUG_BLOCKS)) != 0;
  1367. $plugin_priority = get_plugin_priority ();
  1368. if (isset ($ai_db_options_extract [CONTENT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [CONTENT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) != 0 || $debug_tags_positions)
  1369. add_filter ('the_content', 'ai_content_hook', $plugin_priority);
  1370. if (isset ($ai_db_options_extract [EXCERPT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [EXCERPT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) != 0 || $debug_tags_positions_blocks)
  1371. add_filter ('the_excerpt', 'ai_excerpt_hook', $plugin_priority);
  1372. add_action ('loop_start', 'ai_mark_loop_start');
  1373. if (isset ($ai_db_options_extract [LOOP_START_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [LOOP_START_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) != 0 || $debug_positions)
  1374. add_action ('loop_start', 'ai_hook_function_loop_start');
  1375. add_action ('loop_end', 'ai_mark_loop_end');
  1376. if (isset ($ai_db_options_extract [LOOP_END_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [LOOP_END_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) != 0 || $debug_positions)
  1377. add_action ('loop_end', 'ai_hook_function_loop_end');
  1378. if (isset ($ai_db_options_extract [POST_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [POST_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) != 0 || $debug_positions)
  1379. add_action ('the_post', 'ai_hook_function_post');
  1380. if ((isset ($ai_db_options_extract [BETWEEN_COMMENTS_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [BETWEEN_COMMENTS_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) != 0) ||
  1381. (isset ($ai_db_options_extract [BEFORE_COMMENTS_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [BEFORE_COMMENTS_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) != 0) ||
  1382. (isset ($ai_db_options_extract [AFTER_COMMENTS_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [AFTER_COMMENTS_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) != 0) ||
  1383. $debug_positions) {
  1384. $ai_wp_data [AI_NUMBER_OF_COMMENTS] = 0;
  1385. add_filter ('comments_array' , 'ai_comments_array', 10, 2);
  1386. add_filter ('wp_list_comments_args' , 'ai_wp_list_comments_args');
  1387. $ai_walker = new ai_Walker_Comment;
  1388. }
  1389. // Code for PHP VERSION >= 5.3.0
  1390. // foreach ($ai_custom_hooks as $index => $custom_hook) {
  1391. // if (isset ($ai_db_options_extract [$custom_hook ['action'] . CUSTOM_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [$custom_hook ['action'] . CUSTOM_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) != 0 || $debug_positions)
  1392. // add_action ($custom_hook ['action'], ai_get_custom_hook_function ($custom_hook ['action'], AI_AUTOMATIC_INSERTION_CUSTOM_HOOK + $custom_hook ['index'] - 1, $custom_hook ['name']), $custom_hook ['priority']);
  1393. // }
  1394. // Code for PHP VERSION < 5.3.0
  1395. foreach ($ai_custom_hooks as $index => $custom_hook) {
  1396. if ($index >= 20) break;
  1397. // Skip custom hooks on standard WP hooks - they will be processed anyway
  1398. switch ($custom_hook ['action']) {
  1399. case 'wp_footer':
  1400. // case 'wp_head': // no block processing on wp_head
  1401. case 'the_content':
  1402. case 'the_excerpt':
  1403. case 'loop_start':
  1404. case 'loop_end':
  1405. // case 'the_post': // ai_custom_hook distinguishes between custom hooks and Between posts
  1406. continue 2;
  1407. }
  1408. if (isset ($ai_db_options_extract [$custom_hook ['action'] . CUSTOM_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [$custom_hook ['action'] . CUSTOM_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) != 0 || $debug_positions)
  1409. add_action ($custom_hook ['action'], 'ai_custom_hook_function_' . $index, $custom_hook ['priority']);
  1410. }
  1411. if ($ai_wp_data [AI_STICK_TO_THE_CONTENT]) {
  1412. if (trim (get_main_content_element () == '')) {
  1413. if (!defined ('AI_CONTENT_MARKER_NO_LOOP_START')) {
  1414. add_action ('loop_start', 'ai_content_marker');
  1415. }
  1416. if (!defined ('AI_CONTENT_MARKER_NO_LOOP_END')) {
  1417. add_action ('loop_end', 'ai_content_marker');
  1418. }
  1419. if (!defined ('AI_CONTENT_MARKER_NO_GET_SIDEBAR')) {
  1420. add_action ('get_sidebar', 'ai_content_marker');
  1421. }
  1422. }
  1423. }
  1424. if ($ai_wp_data [AI_WP_AMP_PAGE] ) {
  1425. // AMP, Accelerated Mobile Pages
  1426. add_action ('amp_post_template_head', 'ai_amp_head_hook', 99999);
  1427. add_action ('amp_post_template_css', 'ai_amp_css_hook', 99999);
  1428. add_action ('wp_head', 'ai_amp_head_hook', 99999);
  1429. add_action ('wp_head', 'ai_amp_css_hook_style', 99999);
  1430. // WP AMP Ninja
  1431. add_action ('wpamp_custom_script', 'ai_amp_head_hook', 99999);
  1432. // No usable hook for custom CSS
  1433. // add_action ('wpamp_custom_style', 'ai_amp_css_hook', 99999);
  1434. // WP AMP - Accelerated Mobile Pages for WordPress
  1435. add_action ('amphtml_template_head', 'ai_amp_head_hook', 99999);
  1436. add_action ('amphtml_template_css', 'ai_amp_css_hook', 99999);
  1437. // Better AMP - WordPress Complete AMP
  1438. add_action ('better-amp/template/head', 'ai_amp_head_hook', 99999);
  1439. // No usable hook for custom CSS
  1440. // add_action ('better-amp/template/css', 'ai_amp_css_hook', 99999);
  1441. // AMP WP - Google AMP For WordPress
  1442. add_action ('amp_wp_template_head', 'ai_amp_head_hook', 99999);
  1443. // No usable hook for custom CSS
  1444. // add_action ('amp_wp_template_head', 'ai_amp_css_hook', 99999);
  1445. } else
  1446. // WP
  1447. add_action ('wp_head', 'ai_wp_head_hook', 99999);
  1448. $automatic_insertion_footer_hook = isset ($ai_db_options_extract [FOOTER_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [FOOTER_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) != 0 || $debug_positions;
  1449. if ($ai_wp_data [AI_WP_AMP_PAGE]) {
  1450. // AMP, Accelerated Mobile Pages
  1451. if ($automatic_insertion_footer_hook) {
  1452. add_action ('amp_post_template_footer', 'ai_hook_function_footer', 5);
  1453. add_action ('wp_footer', 'ai_hook_function_footer', 5);
  1454. }
  1455. add_action ('amp_post_template_footer', 'ai_amp_footer_hook', 5);
  1456. add_action ('wp_footer', 'ai_amp_footer_hook', 5);
  1457. // WP AMP Ninja
  1458. if ($automatic_insertion_footer_hook)
  1459. add_action ('wpamp_google_analytics_code', 'ai_hook_function_footer', 5);
  1460. add_action ('wpamp_google_analytics_code', 'ai_amp_footer_hook', 5);
  1461. // WP AMP - Accelerated Mobile Pages for WordPress
  1462. if ($automatic_insertion_footer_hook)
  1463. add_action ('amphtml_after_footer', 'ai_hook_function_footer', 5);
  1464. add_action ('amphtml_after_footer', 'ai_amp_footer_hook', 5);
  1465. // Better AMP - WordPress Complete AMP
  1466. if ($automatic_insertion_footer_hook)
  1467. add_action ('better-amp/template/footer', 'ai_hook_function_footer', 5);
  1468. add_action ('better-amp/template/footer', 'ai_amp_footer_hook', 5);
  1469. // AMP WP - Google AMP For WordPress
  1470. if ($automatic_insertion_footer_hook)
  1471. add_action ('amp_wp_template_footer', 'ai_hook_function_footer', 5);
  1472. add_action ('amp_wp_template_footer', 'ai_amp_footer_hook', 5);
  1473. } else {
  1474. // WP
  1475. if ($automatic_insertion_footer_hook)
  1476. add_action ('wp_footer', 'ai_hook_function_footer', 5);
  1477. add_action ('wp_footer', 'ai_wp_footer_hook_end_buffering', 5);
  1478. add_action ('wp_footer', 'ai_wp_footer_hook', 9999999);
  1479. }
  1480. if ($ai_wp_data [AI_WP_AMP_PAGE]) {
  1481. // No scripts on AMP pages
  1482. if (defined ('AI_ADBLOCKING_DETECTION') && AI_ADBLOCKING_DETECTION) {
  1483. $ai_wp_data [AI_ADB_DETECTION] = false;
  1484. $ai_wp_data [AI_TRACKING] = false;
  1485. }
  1486. }
  1487. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
  1488. $ai_total_plugin_time += microtime (true) - $start_time;
  1489. ai_log ("WP HOOK END: ". number_format (1000 * (microtime (true) - $start_time), 2)." ms\n");
  1490. $ai_wp_data [AI_PROCESSING_TIME] = false;
  1491. }
  1492. };
  1493. function ai_load_plugin_textdomain_hook () {
  1494. unload_textdomain ('ad-inserter');
  1495. load_plugin_textdomain ('ad-inserter', false, basename (dirname (__FILE__)) . '/languages/');
  1496. }
  1497. function ai_load_textdomain_mofile ($mo_file, $domain) {
  1498. if (strpos ($mo_file, 'ad-inserter') !== false) {
  1499. $path = explode ('/', $mo_file);
  1500. $new_mo_file = dirname (__FILE__) . '/languages/' . end ($path);
  1501. if (file_exists ($new_mo_file)) {
  1502. return ($new_mo_file);
  1503. }
  1504. }
  1505. return ($mo_file);
  1506. }
  1507. function ai_plugins_loaded () {
  1508. global $ai_wp_data, $ai_total_plugin_time;
  1509. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
  1510. ai_log ("PLUGINS LOADED START");
  1511. $ai_wp_data [AI_PROCESSING_TIME] = true;
  1512. $start_time = microtime (true);
  1513. }
  1514. add_shortcode ('adinserter', 'ai_process_shortcodes');
  1515. add_shortcode ('ADINSERTER', 'ai_process_shortcodes');
  1516. // TO DO: check referrer
  1517. add_filter ('pre_do_shortcode_tag', 'ai_pre_do_shortcode_tag', 10, 4);
  1518. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
  1519. $ai_total_plugin_time += microtime (true) - $start_time;
  1520. ai_log ("PLUGINS LOADED END: ". number_format (1000 * (microtime (true) - $start_time), 2)." ms\n");
  1521. $ai_wp_data [AI_PROCESSING_TIME] = false;
  1522. }
  1523. }
  1524. function ai_init_hook () {
  1525. global $block_object, $ai_wp_data, $ai_db_options_extract, $ai_total_plugin_time;
  1526. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
  1527. ai_log ("INIT HOOK START");
  1528. $ai_wp_data [AI_PROCESSING_TIME] = true;
  1529. $start_time = microtime (true);
  1530. }
  1531. if ($ai_wp_data [AI_DISABLE_TRANSLATION]) {
  1532. unload_textdomain ('ad-inserter');
  1533. }
  1534. require_once AD_INSERTER_PLUGIN_DIR.'strings.php';
  1535. if (defined ('DOING_AJAX') && DOING_AJAX) {
  1536. $ai_wp_data [AI_WP_PAGE_TYPE] = AI_PT_AJAX;
  1537. ai_load_extract ();
  1538. ai_wp_hook ();
  1539. }
  1540. if (defined ('AI_ADBLOCKING_DETECTION') && AI_ADBLOCKING_DETECTION) {
  1541. if ($ai_wp_data [AI_ADB_DETECTION]) {
  1542. if (function_exists ('ai_check_files')) ai_check_files ();
  1543. }
  1544. }
  1545. // add_shortcode ('adinserter', 'ai_process_shortcodes');
  1546. // add_shortcode ('ADINSERTER', 'ai_process_shortcodes');
  1547. // // TO DO: check referrer
  1548. // add_filter ('pre_do_shortcode_tag', 'ai_pre_do_shortcode_tag', 10, 4);
  1549. // if (defined ('AI_BUFFERING')) {
  1550. // if (get_output_buffering ()) {
  1551. // if ($ai_wp_data [AI_WP_PAGE_TYPE] != AI_PT_AJAX && !$ai_wp_data [AI_CODE_FOR_IFRAME]) {
  1552. // ai_buffering_start ();
  1553. // }
  1554. // }
  1555. // }
  1556. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
  1557. $ai_total_plugin_time += microtime (true) - $start_time;
  1558. ai_log ("INIT HOOK END: ". number_format (1000 * (microtime (true) - $start_time), 2)." ms\n");
  1559. $ai_wp_data [AI_PROCESSING_TIME] = false;
  1560. }
  1561. }
  1562. //function ai_upgrader_process_complete_hook ($upgrader_object, $options) {
  1563. // global $ai_db_options, $ai_db_options_extract;
  1564. // if (is_array ($options) && array_key_exists ('action', $options) && $options ['action'] == 'update' && array_key_exists ('type', $options)) {
  1565. // if ($options ['type'] == 'plugin' && array_key_exists ('plugins', $options) && is_array ($options ['plugins']) && !empty ($options ['plugins'])) {
  1566. // $this_plugin = plugin_basename (__FILE__);
  1567. // foreach ($options ['plugins'] as $plugin) {
  1568. // if ($plugin == $this_plugin) {
  1569. // if (defined ('AI_EXTRACT_GENERATED') && isset ($ai_db_options [AI_OPTION_GLOBAL]['VERSION'])) {
  1570. // $ai_db_options [AI_OPTION_EXTRACT] = $ai_db_options_extract;
  1571. // ai_update_option (AI_OPTION_NAME, $ai_db_options);
  1572. // }
  1573. // break;
  1574. // }
  1575. // }
  1576. // }
  1577. // }
  1578. //}
  1579. function ai_load_extract ($recreate = true) {
  1580. global $ai_db_options, $ai_db_options_extract, $version_string, $subversion_string;
  1581. if (isset ($ai_db_options_extract)) return true;
  1582. $expected_extract_version = $version_string . $subversion_string . '-' . '96';
  1583. if (function_exists ('ai_system_output_check')) {
  1584. $expected_extract_version .= 'P';
  1585. }
  1586. if (isset ($ai_db_options [AI_OPTION_EXTRACT]['VERSION']) && $ai_db_options [AI_OPTION_EXTRACT]['VERSION'] == $expected_extract_version) {
  1587. $ai_db_options_extract = $ai_db_options [AI_OPTION_EXTRACT];
  1588. return true;
  1589. } else {
  1590. if (($saved_extract = get_option (AI_EXTRACT_NAME)) === false || $saved_extract ['VERSION'] != $expected_extract_version) {
  1591. if ($recreate) {
  1592. $ai_db_options_extract = ai_generate_extract ($ai_db_options);
  1593. $ai_db_options [AI_OPTION_EXTRACT] = $ai_db_options_extract;
  1594. if (get_option (AI_OPTION_NAME) !== false)
  1595. update_option (AI_EXTRACT_NAME, $ai_db_options_extract);
  1596. return true;
  1597. }
  1598. } else {
  1599. $ai_db_options_extract = $saved_extract;
  1600. $ai_db_options [AI_OPTION_EXTRACT] = $ai_db_options_extract;
  1601. return true;
  1602. }
  1603. }
  1604. return false;
  1605. }
  1606. function ai_wp_loaded_hook () {
  1607. global $ai_total_plugin_time, $ai_wp_data;
  1608. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
  1609. ai_log ("WP LOADED HOOK START");
  1610. $ai_wp_data [AI_PROCESSING_TIME] = true;
  1611. $start_time = microtime (true);
  1612. }
  1613. ai_load_extract ();
  1614. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
  1615. $ai_total_plugin_time += microtime (true) - $start_time;
  1616. if (defined ('AI_EXTRACT_GENERATED')) ai_log ("EXTRACT GENERATED");
  1617. ai_log ("WP LOADED HOOK END: ". number_format (1000 * (microtime (true) - $start_time), 2)." ms\n");
  1618. $ai_wp_data [AI_PROCESSING_TIME] = false;
  1619. }
  1620. }
  1621. function ai_admin_menu_hook () {
  1622. global $ai_settings_page;
  1623. if (is_multisite() && !is_main_site () && !multisite_settings_page_enabled ()) return;
  1624. // translators: %s: Ad Inserter
  1625. $ai_settings_page = add_submenu_page ('options-general.php', sprintf (__('%s Settings', 'ad-inserter'), AD_INSERTER_NAME), AD_INSERTER_NAME, 'manage_options', basename (__FILE__), 'ai_settings');
  1626. add_action ('admin_enqueue_scripts', 'ai_admin_enqueue_scripts');
  1627. add_action ('admin_enqueue_scripts', 'ai_admin_enqueue_scripts_late', 99999);
  1628. add_action ('admin_enqueue_scripts', 'ai_admin_remove_scripts', 99999);
  1629. add_action ('admin_head', 'ai_admin_head');
  1630. add_filter ('clean_url', 'ai_clean_url', 999999, 2);
  1631. }
  1632. function ai_admin_head () {
  1633. global $ai_settings_page, $hook_suffix;
  1634. if ($hook_suffix == $ai_settings_page && wp_is_mobile()) {
  1635. echo '<meta name="viewport" content="width=762">', PHP_EOL;
  1636. }
  1637. }
  1638. function ai_admin_enqueue_scripts ($hook_suffix) {
  1639. global $ai_settings_page, $ai_admin_translations;
  1640. if ($hook_suffix == $ai_settings_page) {
  1641. wp_enqueue_style ('ai-admin-jquery-ui', plugins_url ('css/jquery-ui-1.10.3.custom.min.css', __FILE__), array (), null);
  1642. if (function_exists ('ai_admin_enqueue_scripts_1')) ai_admin_enqueue_scripts_1 ();
  1643. wp_enqueue_style ('ai-admin-multi-select', plugins_url ('css/multi-select.css', AD_INSERTER_FILE), array (), AD_INSERTER_VERSION);
  1644. wp_enqueue_style ('ai-image-picker', plugins_url ('css/image-picker.css', __FILE__), array (), AD_INSERTER_VERSION);
  1645. wp_add_inline_style ('ai-image-picker', '.thumbnail {border-radius: 6px;}');
  1646. wp_enqueue_style ('ai-combobox-css', plugins_url ('css/jquery.scombobox.min.css', __FILE__), array (), AD_INSERTER_VERSION);
  1647. if (function_exists ('ai_admin_enqueue_scripts_2')) ai_admin_enqueue_scripts_2 ();
  1648. wp_enqueue_script ('ai-multi-select', plugins_url ('includes/js/jquery.multi-select.js', AD_INSERTER_FILE ), array (), AD_INSERTER_VERSION, true);
  1649. wp_enqueue_script ('ai-quicksearch', plugins_url ('includes/js/jquery.quicksearch.js', AD_INSERTER_FILE ), array (), AD_INSERTER_VERSION, true);
  1650. // Located in the header to load datepicker js file to prevent error when async tags used
  1651. wp_enqueue_script ('ai-image-picker-js', plugins_url ('includes/js/image-picker.min.js', __FILE__ ), array (
  1652. 'jquery',
  1653. 'jquery-ui-datepicker',
  1654. ), AD_INSERTER_VERSION, false);
  1655. if (AI_SYNTAX_HIGHLIGHTING && !defined ('AI_SAFE_MODE')) {
  1656. wp_enqueue_script ('ai-ace', plugins_url ('includes/ace/ace.js', __FILE__ ), array (), AD_INSERTER_VERSION, true);
  1657. // wp_enqueue_script ('ai-ace-ext-modelist', plugins_url ('includes/ace/ext-modelist.js', __FILE__ ), array (), AD_INSERTER_VERSION, true);
  1658. wp_enqueue_script ('ai-ace-html', plugins_url ('includes/ace/mode-html.js', __FILE__ ), array (), AD_INSERTER_VERSION, true);
  1659. wp_enqueue_script ('ai-ace-php', plugins_url ('includes/ace/mode-php.js', __FILE__ ), array (), AD_INSERTER_VERSION, true);
  1660. if (get_syntax_highlighter_theme () == AI_SYNTAX_HIGHLIGHTER_THEME || isset ($_POST ["syntax-highlighter-theme"]) && $_POST ["syntax-highlighter-theme"] == AI_SYNTAX_HIGHLIGHTER_THEME)
  1661. wp_enqueue_script ('ai-ace-theme', plugins_url ('includes/ace/theme-ad_inserter.js', __FILE__ ), array (), AD_INSERTER_VERSION, true);
  1662. }
  1663. wp_enqueue_script ('ai-combobox', plugins_url ('includes/js/jquery.scombobox.min.js', __FILE__), array (
  1664. 'jquery',
  1665. ), AD_INSERTER_VERSION , true);
  1666. wp_enqueue_script ('ai-admin-js', plugins_url ('js/ad-inserter.js', __FILE__), array (
  1667. 'jquery',
  1668. 'jquery-ui-tabs',
  1669. 'jquery-ui-button',
  1670. 'jquery-ui-tooltip',
  1671. 'jquery-ui-datepicker',
  1672. 'jquery-ui-dialog',
  1673. ), AD_INSERTER_VERSION, true);
  1674. wp_localize_script ('ai-admin-js', 'ai_admin', $ai_admin_translations);
  1675. wp_enqueue_script ('ai-missed', plugins_url ('includes/js/missed.js', __FILE__), array (), AD_INSERTER_VERSION , true);
  1676. }
  1677. wp_enqueue_style ('ai-admin-gen', plugins_url ('css/ai-admin.css', __FILE__), array (), AD_INSERTER_VERSION);
  1678. wp_enqueue_script ('ai-admin-js-gen', plugins_url ('includes/js/ai-admin.js', __FILE__ ), array (), AD_INSERTER_VERSION, true);
  1679. }
  1680. function ai_admin_enqueue_scripts_late ($hook_suffix) {
  1681. global $ai_settings_page;
  1682. if ($hook_suffix == $ai_settings_page) {
  1683. // wp_enqueue_style ('ai-admin', plugins_url ('css/ad-inserter.css', __FILE__), array (), AD_INSERTER_VERSION);
  1684. wp_enqueue_style ('ai-admin', plugins_url ('css/ai-settings.css', __FILE__), array (), AD_INSERTER_VERSION);
  1685. wp_add_inline_style ('ai-admin', '.notice {margin: 5px 15px 15px 0;}');
  1686. }
  1687. }
  1688. function ai_admin_remove_scripts ($hook_suffix) {
  1689. global $ai_settings_page;
  1690. if ($hook_suffix == $ai_settings_page) {
  1691. // Prevent converting emojis to images
  1692. remove_action ('admin_print_scripts', 'print_emoji_detection_script');
  1693. // Fix for Publisher theme: remove scripts loaded on Ad Inserter admin page
  1694. wp_deregister_script ('ace-editor-script');
  1695. wp_dequeue_script ('publisher-admin');
  1696. // Fix for Shell ClubSmart theme (titan framework)
  1697. wp_dequeue_script ('tf-ace');
  1698. // Default settings
  1699. wp_dequeue_script ('tf-ace-theme-chrome');
  1700. wp_dequeue_script ('tf-ace-mode-css');
  1701. // Fix for JNews theme
  1702. wp_dequeue_style ('global-admin');
  1703. wp_dequeue_style ('selectize');
  1704. wp_dequeue_style ('select2');
  1705. wp_dequeue_style ('tooltipster');
  1706. wp_dequeue_style ('jnews-admin');
  1707. wp_dequeue_style ('vex');
  1708. // Fix for OptimizePress plugin: remove styles loaded on Ad Inserter admin page
  1709. wp_dequeue_style ('optimizepress-admin-assets');
  1710. wp_dequeue_style ('optimizepress-admin-common');
  1711. wp_dequeue_style ('optimizepress-tiny-mce-css');
  1712. wp_dequeue_style ('optimizepress-dashicons');
  1713. // Fix for WP Nav Manager plugin: remove styles loaded on Ad Inserter admin page
  1714. wp_dequeue_style ('wp-nav-manager-admin-style');
  1715. // Fix for Booking.com Product Helper plugin: remove styles loaded on Ad Inserter admin page
  1716. wp_dequeue_style ('bookingcom-product-helper-css');
  1717. // Fix for WP BotWatch plugin: remove styles loaded on Ad Inserter admin page
  1718. wp_dequeue_style ('wp-botwatch');
  1719. // Fix for All in One Schema.org Rich Snippets plugin: remove styles loaded on Ad Inserter admin page
  1720. wp_dequeue_style ('admin_style');
  1721. wp_deregister_style ('admin_style');
  1722. // Fix for ACF for AMP plugin: remove styles loaded on Ad Inserter admin page
  1723. wp_dequeue_style ('amp-acf-admin');
  1724. wp_deregister_style ('amp-acf-admin');
  1725. wp_dequeue_script ('ace_code_highlighter_js');
  1726. wp_dequeue_script ('ace_mode_js');
  1727. wp_dequeue_script ('custom_css_js');
  1728. wp_dequeue_script ('field-creator');
  1729. wp_dequeue_script ('amp_acf_field');
  1730. // Fix for WP Lightbox 2 plugin: remove styles loaded on Ad Inserter admin page
  1731. wp_dequeue_style ('jquery-ui-style');
  1732. wp_deregister_style ('jquery-ui-style');
  1733. // Fix for Widget Options plugin: remove styles loaded on Ad Inserter admin page
  1734. wp_dequeue_style ('widgetopts-jquery-ui');
  1735. wp_deregister_style ('widgetopts-jquery-ui');
  1736. }
  1737. }
  1738. function ai_set_footer_inline_scripts () {
  1739. global $ai_wp_data;
  1740. $adb_code = defined ('AI_ADBLOCKING_DETECTION') && AI_ADBLOCKING_DETECTION && $ai_wp_data [AI_ADB_DETECTION] && !isset ($ai_wp_data [AI_ADB_SHORTCODE_DISABLED]);
  1741. // Check again later in the footer
  1742. $ai_wp_data [AI_FOOTER_INLINE_SCRIPTS] =
  1743. get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW ||
  1744. get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_INSERT || // alerady in $ai_wp_data [AI_CLIENT_SIDE_INSERTION]
  1745. isset ($ai_wp_data [AI_CLIENT_SIDE_ROTATION]) ||
  1746. ($ai_wp_data [AI_TRACKING] && !isset ($ai_wp_data [AI_TRACKING_SHORTCODE_DISABLED])) ||
  1747. $ai_wp_data [AI_STICKY_WIDGETS] ||
  1748. $ai_wp_data [AI_STICK_TO_THE_CONTENT] ||
  1749. $ai_wp_data [AI_ANIMATION] ||
  1750. $ai_wp_data [AI_CLOSE_BUTTONS] ||
  1751. $ai_wp_data [AI_HTML_ELEMENT_SELECTION] ||
  1752. $ai_wp_data [AI_LAZY_LOADING] ||
  1753. $ai_wp_data [AI_CLIENT_SIDE_INSERTION] ||
  1754. $adb_code ||
  1755. ($ai_wp_data [AI_WP_DEBUGGING] & (AI_DEBUG_BLOCKS | AI_DEBUG_POSITIONS)) != 0 ||
  1756. $ai_wp_data [AI_FRONTEND_JS_DEBUGGING] ||
  1757. $ai_wp_data [AI_CHECK_BLOCK] ||
  1758. $ai_wp_data [AI_FOOTER_JS_CODE_DOM_READY] != '';
  1759. }
  1760. function ai_wp_enqueue_scripts_hook () {
  1761. global $ai_wp_data, $wp_version, $wp_scripts, $ai_front_translations;
  1762. // TEST
  1763. // wp_deregister_script ('jquery');
  1764. ai_set_footer_inline_scripts ();
  1765. if ($ai_wp_data [AI_FOOTER_INLINE_SCRIPTS] ||
  1766. ($ai_wp_data [AI_WP_DEBUGGING] & (AI_DEBUG_POSITIONS | AI_DEBUG_BLOCKS)) != 0 ||
  1767. !empty ($_GET) ||
  1768. get_remote_debugging () || ($ai_wp_data [AI_WP_USER] & AI_USER_ADMINISTRATOR) != 0 ||
  1769. $ai_wp_data [AI_ANIMATION]) {
  1770. // Load jQuery on frontend when needed
  1771. if (!get_wait_for_jquery () && isset ($wp_scripts->registered ['jquery'])) {
  1772. wp_enqueue_script ('jquery');
  1773. }
  1774. if ($ai_wp_data [AI_HTML_ELEMENT_SELECTION]) {
  1775. wp_enqueue_script ('ai-jquery-js', plugins_url ('includes/js/ai-jquery.js', __FILE__), array ('jquery', 'jquery-ui-button'), $wp_version . '+' . AD_INSERTER_VERSION);
  1776. wp_enqueue_style ('ai-html-jquery-ui', plugins_url ('css/jquery-ui-1.10.3.custom.min.css', __FILE__), array (), null);
  1777. }
  1778. // if (!$ai_wp_data [AI_WP_AMP_PAGE]) {
  1779. // wp_enqueue_script ('ai-jquery-js', plugins_url ('includes/js/ai-jquery.js', __FILE__), $jquery_required, $wp_version . '+' . AD_INSERTER_VERSION);
  1780. // wp_localize_script ('ai-jquery-js', 'ai_front', $ai_front_translations);
  1781. // }
  1782. if (!get_disable_css_code () && (get_remote_debugging () || ($ai_wp_data [AI_WP_USER] & AI_USER_ADMINISTRATOR) != 0)) {
  1783. wp_enqueue_style ('dashicons');
  1784. }
  1785. if (!get_disable_js_code () && $ai_wp_data [AI_ANIMATION]) {
  1786. if (defined ('AI_STICKY_SETTINGS') && AI_STICKY_SETTINGS) {
  1787. wp_enqueue_style ('ai-aos', plugins_url ('includes/aos/ai-aos.css', __FILE__), array (), AD_INSERTER_VERSION);
  1788. wp_enqueue_script ('ai-aos-js', plugins_url ('includes/aos/aos.js', AD_INSERTER_FILE ), array (), AD_INSERTER_VERSION, true);
  1789. }
  1790. }
  1791. }
  1792. }
  1793. function ai_clean_url ( $url, $original_url){
  1794. if (strpos ($url, 'async=') !== false && strpos ($url, '/plugins/ad-inserter') !== false) {
  1795. // $url = $original_url;
  1796. $url = str_replace ("' async='async", '', $url);
  1797. }
  1798. return $url;
  1799. }
  1800. function ai_get_client_side_styles () {
  1801. return
  1802. ".ai-rotate {position: relative;}\n" .
  1803. ".ai-rotate-hidden {visibility: hidden;}\n" .
  1804. ".ai-rotate-hidden-2 {position: absolute; top: 0; left: 0; width: 100%; height: 100%;}\n" .
  1805. ".ai-list-data, .ai-ip-data, .ai-fallback, .ai-list-block, .ai-list-block-ip {".AI_ALIGNMENT_CSS_HIDDEN_LIST."}\n";
  1806. ".ai-list-data, .ai-ip-data, .ai-fallback {min-width: 1px;}\n";
  1807. "";
  1808. }
  1809. function ai_get_admin_toolbar_debugging_styles () {
  1810. global $ai_wp_data;
  1811. $css = '';
  1812. if (((get_admin_toolbar_debugging () && ((get_remote_debugging () && $ai_wp_data [AI_WP_DEBUGGING] != 0) || ($ai_wp_data [AI_WP_USER] & AI_USER_LOGGED_IN) != 0)) || defined ('AI_DEBUGGING_DEMO')) && !$ai_wp_data [AI_CODE_FOR_IFRAME]) {
  1813. $css .= "#wp-admin-bar-ai-toolbar-settings .ab-icon:before {
  1814. content: '\\f111';
  1815. top: 2px;
  1816. color: rgba(240,245,250,.6)!important;
  1817. }
  1818. #wp-admin-bar-ai-toolbar-settings-default .ab-icon:before {
  1819. top: 0px;
  1820. }
  1821. #wp-admin-bar-ai-toolbar-settings .ab-icon.on:before {
  1822. color: #00f200!important;
  1823. }
  1824. #wp-admin-bar-ai-toolbar-settings .ab-icon.red:before {
  1825. color: #f22!important;
  1826. }
  1827. #wp-admin-bar-ai-toolbar-settings-default li, #wp-admin-bar-ai-toolbar-settings-default a,
  1828. #wp-admin-bar-ai-toolbar-settings-default li:hover, #wp-admin-bar-ai-toolbar-settings-default a:hover {
  1829. border: 1px solid transparent;
  1830. }
  1831. ul li#wp-admin-bar-ai-toolbar-status {
  1832. margin: 0 0 5px 0;
  1833. }
  1834. #wp-admin-bar-ai-toolbar-blocks .ab-icon:before {
  1835. content: '\\f135';
  1836. }
  1837. #wp-admin-bar-ai-toolbar-positions .ab-icon:before {
  1838. content: '\\f207';
  1839. }
  1840. #wp-admin-bar-ai-toolbar-positions-default .ab-icon:before {
  1841. content: '\\f522';
  1842. }
  1843. #wp-admin-bar-ai-toolbar-tags .ab-icon:before {
  1844. content: '\\f475';
  1845. }
  1846. #wp-admin-bar-ai-toolbar-no-insertion .ab-icon:before {
  1847. content: '\\f214';
  1848. }
  1849. #wp-admin-bar-ai-toolbar-adb-status .ab-icon:before {
  1850. content: '\\f223';
  1851. }
  1852. #wp-admin-bar-ai-toolbar-adb .ab-icon:before {
  1853. content: '\\f160';
  1854. }
  1855. #wp-admin-bar-ai-toolbar-processing .ab-icon:before {
  1856. content: '\\f464';
  1857. }
  1858. #wp-admin-bar-ai-toolbar-processing-fe .ab-icon:before {
  1859. content: '\\f464';
  1860. }
  1861. #wp-admin-bar-ai-toolbar-positions span.up-icon {
  1862. padding-top: 2px;
  1863. }
  1864. #wp-admin-bar-ai-toolbar-positions .up-icon:before {
  1865. font: 400 20px/1 dashicons;
  1866. }
  1867. .ai-insertion-status {
  1868. line-height: 26px!important;
  1869. height: 26px!important;
  1870. white-space: nowrap;
  1871. min-width: 140px;
  1872. }
  1873. #wp-admin-bar-ai-toolbar-settings .ab-sub-wrapper {
  1874. width: max-content;
  1875. width: -moz-max-content;
  1876. }
  1877. ";
  1878. }
  1879. if (get_admin_toolbar_mobile () && !$ai_wp_data [AI_CODE_FOR_IFRAME]) {
  1880. $css .= "@media screen and (max-width: 782px) {
  1881. #wpadminbar #wp-admin-bar-ai-toolbar-settings {
  1882. display: block;
  1883. position: static;
  1884. }
  1885. #wpadminbar #wp-admin-bar-ai-toolbar-settings > .ab-item {
  1886. white-space: nowrap;
  1887. overflow: hidden;
  1888. width: 52px;
  1889. padding: 0;
  1890. color: #a0a5aa;
  1891. position: relative;
  1892. }
  1893. #wpadminbar .quicklinks .menupop ul li .ab-item, #wpadminbar .quicklinks .menupop.hover ul li .ab-item {
  1894. min-height: 28px;
  1895. }
  1896. }
  1897. ";
  1898. }
  1899. return $css;
  1900. }
  1901. function add_head_inline_styles () {
  1902. global $ai_wp_data;
  1903. if (get_disable_css_code ()) return; // Needed for iframes? $ai_wp_data [AI_CODE_FOR_IFRAME]
  1904. $debugging =
  1905. $ai_wp_data [AI_WP_DEBUGGING] != 0 ||
  1906. (get_remote_debugging () || ($ai_wp_data [AI_WP_USER] & AI_USER_LOGGED_IN) != 0) && isset ($_GET [AI_URL_DEBUG_PROCESSING_FE]) && $_GET [AI_URL_DEBUG_PROCESSING_FE] != 0;
  1907. if ($ai_wp_data [AI_CLIENT_SIDE_DETECTION] ||
  1908. get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW ||
  1909. isset ($ai_wp_data [AI_CLIENT_SIDE_ROTATION]) ||
  1910. $ai_wp_data [AI_CLOSE_BUTTONS] ||
  1911. $ai_wp_data [AI_HTML_ELEMENT_SELECTION] ||
  1912. !get_inline_styles () ||
  1913. get_admin_toolbar_debugging () && (get_remote_debugging () || ($ai_wp_data [AI_WP_USER] & AI_USER_LOGGED_IN) != 0) ||
  1914. $debugging) {
  1915. echo "<style>\n";
  1916. if ($ai_wp_data [AI_CLIENT_SIDE_DETECTION] && !$ai_wp_data [AI_CODE_FOR_IFRAME]) echo get_viewport_css ();
  1917. if (get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW || get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_INSERT || isset ($ai_wp_data [AI_CLIENT_SIDE_ROTATION])) {
  1918. echo ai_get_client_side_styles ();
  1919. $ai_wp_data [AI_CLIENT_SIDE_CSS] = true;
  1920. }
  1921. if ($ai_wp_data [AI_CLOSE_BUTTONS] && !$ai_wp_data [AI_CODE_FOR_IFRAME]) {
  1922. echo ".ai-close {position: relative;}\n";
  1923. // echo ".ai-close-width {width: auto !important;}\n";
  1924. echo ".ai-close-button {position: absolute; top: -8px; right: -8px; width: 24px; height: 24px; background: url(".plugins_url ('css/images/close-button.png', AD_INSERTER_FILE).") no-repeat center center; cursor: pointer; z-index: 9; display: none;}\n";
  1925. echo ".ai-close-show {display: block;}\n";
  1926. echo ".ai-close-left {right: unset; left: -10px;}\n";
  1927. echo ".ai-close-bottom {top: unset; bottom: -11px;}\n";
  1928. echo ".ai-close-none {visibility: hidden;}\n";
  1929. }
  1930. // Before alignment CSS to not override alignment margin
  1931. if ($debugging) generate_debug_css_base ();
  1932. if (!get_inline_styles () && !$ai_wp_data [AI_CODE_FOR_IFRAME]) {
  1933. echo get_alignment_css ();
  1934. }
  1935. // After alignment CSS to override width
  1936. if ($ai_wp_data [AI_CLOSE_BUTTONS] && !$ai_wp_data [AI_CODE_FOR_IFRAME]) {
  1937. echo ".ai-close-fit {width: fit-content; width: -moz-fit-content;}\n";
  1938. }
  1939. if ($debugging) generate_debug_css ();
  1940. if ($ai_wp_data [AI_HTML_ELEMENT_SELECTION]) generate_selection_css ();
  1941. echo ai_get_admin_toolbar_debugging_styles ();
  1942. echo "</style>\n";
  1943. }
  1944. }
  1945. function ai_get_js ($js_name, $replace_js_data = true) {
  1946. global $ai_wp_data;
  1947. if ($ai_wp_data [AI_FRONTEND_JS_DEBUGGING]) {
  1948. $script = @file_get_contents (AD_INSERTER_PLUGIN_DIR."includes/js/$js_name.js");
  1949. } else $script = @file_get_contents (AD_INSERTER_PLUGIN_DIR."includes/js/$js_name.min.js");
  1950. if (!$replace_js_data) return $script;
  1951. // return ai_replace_js_data ($script, $js_name);
  1952. return ai_replace_js_data ($script);
  1953. }
  1954. function ai_randomize_properties ($style, $z_index_min = null, $z_index_max = null) {
  1955. $style_array = explode (';', trim ($style, ';'));
  1956. foreach ($style_array as $index => $property) {
  1957. $property = trim ($property);
  1958. if ($z_index_min != null && $z_index_max != null && strpos ($property, 'z-index') === 0) {
  1959. $style_array [$index] = 'z-index: ' . rand ($z_index_min, $z_index_max);
  1960. }
  1961. if (strpos ($property, 'opacity') === 0) {
  1962. $value = str_replace (array ('opacity', ':', ' ', ';'), '', $property);
  1963. if (is_numeric ($value)) {
  1964. $value = 100 * $value - 5 + rand (0, 10);
  1965. if ($value > 100) $value = 100;
  1966. $style_array [$index] = 'opacity: ' . ($value / 100);
  1967. }
  1968. }
  1969. elseif (strpos ($property, '50%') !== false) {
  1970. $style_array [$index] = str_replace ('50%', (47 + rand (0, 6)) . '.' . rand (1, 99) . '%', $style_array [$index]);
  1971. }
  1972. elseif (strpos ($property, '100%') !== false) {
  1973. $style_array [$index] = str_replace ('100%', '100.' . rand (1, 99) . '%', $style_array [$index]);
  1974. }
  1975. elseif (strpos ($property, '#000') !== false) {
  1976. $color = rand (0, 2) . rand (0, 9);
  1977. $style_array [$index] = str_replace ('#000', '#' . $color . $color . $color, $style_array [$index]);
  1978. }
  1979. }
  1980. shuffle ($style_array);
  1981. return trim (implode ('; ', $style_array)) . ';';
  1982. }
  1983. function ai_replace_js_data ($js) {
  1984. global $block_object, $ai_wp_data;
  1985. if (preg_match_all ('/AI_CONST_([_A-Z0-9]+)/', $js, $match)) {
  1986. foreach ($match [1] as $index => $constant) {
  1987. if (defined ($constant))
  1988. $js = str_replace ($match [0][$index], constant ($constant), $js);
  1989. }
  1990. }
  1991. if (preg_match_all ('/AI_DATA_([_A-Z0-9]+)/', $js, $match)) {
  1992. foreach ($match [1] as $index => $constant) {
  1993. if (defined ($constant) && isset ($ai_wp_data [constant ($constant)]))
  1994. $js = str_replace ($match [0][$index], $ai_wp_data [constant ($constant)], $js);
  1995. }
  1996. }
  1997. if (preg_match_all ('/AI_DATAB_([_A-Z0-9]+)/', $js, $match)) {
  1998. foreach ($match [1] as $index => $constant) {
  1999. if (defined ($constant) && isset ($ai_wp_data [constant ($constant)]))
  2000. $js = str_replace ($match [0][$index], $ai_wp_data [constant ($constant)] ? 1 : 0, $js);
  2001. }
  2002. }
  2003. if (preg_match_all ('/AI_DBG_([_A-Z0-9]+)/', $js, $match)) {
  2004. foreach ($match [1] as $index => $constant) {
  2005. if (defined ($constant))
  2006. $js = str_replace ($match [0][$index], ($ai_wp_data [AI_WP_DEBUGGING] & constant ($constant)) != 0 ? 1 : 0, $js);
  2007. }
  2008. }
  2009. if (preg_match_all ('/AI_FUNC_([_A-Z0-9]+)/', $js, $match)) {
  2010. foreach ($match [1] as $index => $function) {
  2011. $function = strtolower ($function);
  2012. if (function_exists ($function))
  2013. $js = str_replace ($match [0][$index], call_user_func ($function), $js);
  2014. }
  2015. }
  2016. if (preg_match_all ('/AI_FUNCH_([_A-Z0-9]+)/', $js, $match)) {
  2017. foreach ($match [1] as $index => $function) {
  2018. $function = strtolower ($function);
  2019. if (function_exists ($function))
  2020. $js = str_replace ($match [0][$index], html_entity_decode (call_user_func ($function)), $js);
  2021. }
  2022. }
  2023. if (preg_match_all ('/AI_FUNCB_([_A-Z0-9]+)/', $js, $match)) {
  2024. foreach ($match [1] as $index => $function) {
  2025. $function = strtolower ($function);
  2026. if (function_exists ($function))
  2027. $js = str_replace ($match [0][$index], call_user_func ($function) ? 1 : 0, $js);
  2028. }
  2029. }
  2030. if (preg_match_all ('/AI_FUNCT_([_A-Z0-9]+)/', $js, $match)) {
  2031. foreach ($match [1] as $index => $function) {
  2032. $function = strtolower ($function);
  2033. if (function_exists ($function))
  2034. $js = str_replace ($match [0][$index], call_user_func ($function, true), $js);
  2035. }
  2036. }
  2037. if (preg_match_all ('/AI_POST_([_A-Z0-9]+)/', $js, $match)) {
  2038. foreach ($match [1] as $index => $post) {
  2039. $post_name = strtolower ($post);
  2040. $js = str_replace ($match [0][$index], isset ($_POST [$post_name]) ? urldecode ($_POST [$post_name]) : '', $js);
  2041. }
  2042. }
  2043. if (defined ('AI_ADBLOCKING_DETECTION') && AI_ADBLOCKING_DETECTION) {
  2044. if (strpos ($js, 'AI_ADB_OVERLAY_WINDOW') !== false) {
  2045. $adb = $block_object [AI_ADB_MESSAGE_OPTION_NAME];
  2046. $tags = array ('div', 'span', 'ins', 'section', 'kbd');
  2047. $message_tag = $tags [rand (0, count ($tags) - 1)];
  2048. $overlay_tag = $tags [rand (0, count ($tags) - 1)];
  2049. $basic_adb_overlay_css = AI_BASIC_ADB_OVERLAY_CSS;
  2050. $basic_adb_message_css = AI_BASIC_ADB_MESSAGE_CSS;
  2051. if (strpos ($js, 'AI_ADB_STATUS_MESSAGE') === false) {
  2052. $basic_adb_overlay_css = str_replace ('pointer', 'no-drop', $basic_adb_overlay_css);
  2053. $basic_adb_message_css = str_replace ('pointer', 'no-drop', $basic_adb_message_css);
  2054. }
  2055. // $js = str_replace ('AI_ADB_OVERLAY_WINDOW', "jQuery ('<div>', {attr: {'id': 'ai-adb-overlay', 'style': b64d ('" . base64_encode (str_replace (array ("'", "\r", "\n"), array ("\'", '', ''), $basic_adb_overlay_css) . get_overlay_css ()) . "')}})", $js);
  2056. $overlay_code = "jQuery ('<".$overlay_tag.">', {attr: {'style': b64d ('" . base64_encode (str_replace (array ("'", "\r", "\n"), array ("\'", '', ''), ai_randomize_properties ($basic_adb_overlay_css, 10002, 14998)) . ai_randomize_properties (get_overlay_css ())) . "')}})";
  2057. for ($level = 1; $level <= 5; $level ++) {
  2058. switch (rand (1, 10)) {
  2059. case 1:
  2060. case 2:
  2061. case 3:
  2062. case 4:
  2063. $tag = 'div';
  2064. break;
  2065. case 5:
  2066. case 6:
  2067. case 7:
  2068. $tag = $tags [rand (0, count ($tags) - 1)];
  2069. break;
  2070. default:
  2071. continue 2;
  2072. }
  2073. $overlay_code .= ".append (jQuery ('<div>')).append (jQuery ('<div>', {attr: {'style': b64d ('" . base64_encode (str_replace (array ("'", "\r", "\n"), array ("\'", '', ''), ai_randomize_properties ($basic_adb_overlay_css, 100, 9999))) . "')}}))";
  2074. $overlay_code = "jQuery ('<".$tag.">').append (" . $overlay_code . ')';
  2075. if (rand (1, 10) > 5) $overlay_code .= ".append (jQuery ('<div>', {attr: {'style': b64d ('" . base64_encode (str_replace (array ("'", "\r", "\n"), array ("\'", '', ''), ai_randomize_properties ($basic_adb_overlay_css, 100, 9999))) . "')}}))";
  2076. if (rand (1, 10) > 5) $overlay_code .= ".append (jQuery ('<div>'))";
  2077. if (rand (1, 10) > 5) $overlay_code .= ".prepend (jQuery ('<div>', {attr: {'style': b64d ('" . base64_encode (str_replace (array ("'", "\r", "\n"), array ("\'", '', ''), ai_randomize_properties ($basic_adb_overlay_css, 100, 9999))) . "')}}))";
  2078. if (rand (1, 10) > 5) $overlay_code .= ".prepend (jQuery ('<div>'))";
  2079. }
  2080. $js = str_replace ('AI_ADB_OVERLAY_WINDOW', $overlay_code, $js);
  2081. // $js = str_replace ('AI_ADB_MESSAGE_WINDOW', "jQuery ('<div>', {attr: {'id': 'ai-adb-message', 'style': b64d ('" . base64_encode (str_replace (array ("'", "\r", "\n"), array ("\'", '', ''), $basic_adb_message_css) . get_message_css ()) . "')}, 'html': b64d ('" .
  2082. $message_code = "jQuery ('<".$message_tag.">', {attr: {'style': b64d ('" . base64_encode (str_replace (array ("'", "\r", "\n"), array ("\'", '', ''), ai_randomize_properties ($basic_adb_message_css, 14999, 19998)) . ai_randomize_properties (get_message_css ())) . "')}, 'html': b64d ('" .
  2083. base64_encode (str_replace (array ("'", "\r", "\n"), array ("\'", '', ''), do_shortcode ($adb->ai_getCode ()))) . "')})";
  2084. for ($level = 1; $level <= 5; $level ++) {
  2085. switch (rand (1, 10)) {
  2086. case 1:
  2087. case 2:
  2088. case 3:
  2089. $tag = 'div';
  2090. break;
  2091. case 4:
  2092. case 5:
  2093. $tag = 'p';
  2094. break;
  2095. case 6:
  2096. case 7:
  2097. $tag = $tags [rand (0, count ($tags) - 1)];
  2098. break;
  2099. default:
  2100. continue 2;
  2101. }
  2102. $message_code .= ".append (jQuery ('<p>')).append (jQuery ('<div>', {attr: {'style': b64d ('" . base64_encode (str_replace (array ("'", "\r", "\n"), array ("\'", '', ''), ai_randomize_properties ($basic_adb_message_css, 100, 9999))) . "')}}))";
  2103. $message_code = "jQuery ('<".$tag.">').append (" . $message_code . ')';
  2104. if (rand (1, 10) > 7) $message_code .= ".append (jQuery ('<div>', {attr: {'style': b64d ('" . base64_encode (str_replace (array ("'", "\r", "\n"), array ("\'", '', ''), ai_randomize_properties ($basic_adb_message_css, 100, 9999))) . "')}}))";
  2105. if (rand (1, 10) > 7) $message_code .= ".append (jQuery ('<p>'))";
  2106. if (rand (1, 10) > 7) $message_code .= ".prepend (jQuery ('<div>', {attr: {'style': b64d ('" . base64_encode (str_replace (array ("'", "\r", "\n"), array ("\'", '', ''), ai_randomize_properties ($basic_adb_message_css, 100, 9999))) . "')}}))";
  2107. if (rand (1, 10) > 7) $message_code .= ".prepend (jQuery ('<p>'))";
  2108. if (rand (1, 10) > 3) $message_code .= ".prepend (jQuery ('<p>'))";
  2109. }
  2110. $js = str_replace ('AI_ADB_MESSAGE_WINDOW', $message_code, $js);
  2111. $js = str_replace ('AI_ADB_SELECTORS', get_adb_selectors (true), $js);
  2112. $redirection_page = get_redirection_page ();
  2113. if ($redirection_page != 0) $url = get_permalink ($redirection_page); else $url = trim (get_custom_redirection_url ());
  2114. $js = str_replace ('AI_ADB_REDIRECTION_PAGE', $url, $js);
  2115. if (($ai_wp_data [AI_WP_DEBUGGING] & (AI_DEBUG_AD_BLOCKING_STATUS | AI_DEBUG_POSITIONS | AI_DEBUG_BLOCKS)) != 0) {
  2116. // translators: AD BLOCKING DETECTED, PAGE VIEWS: n - NO ACTION
  2117. $js = str_replace ('window.AI_ADB_STATUS_MESSAGE=1', '(jQuery("#ai-adb-status").text ("' . __('AD BLOCKING DETECTED, PAGE VIEWS', 'ad-inserter') . '" + ": " + window.ai_d1 + " - " + "' . __('NO ACTION', 'ad-inserter') . '"),jQuery("#ai-adb-bar").addClass ("adb-on"))', $js);
  2118. $js = str_replace ('window.AI_ADB_STATUS_MESSAGE=2', '(jQuery("#ai-adb-status").text ("' . __('AD BLOCKING DETECTED, COOKIE DETECTED - NO ACTION', 'ad-inserter') . '"),jQuery("#ai-adb-bar").addClass ("adb-on"))', $js);
  2119. $js = str_replace ('window.AI_ADB_STATUS_MESSAGE=3', '(jQuery("#ai-adb-status").text ("' . __('AD BLOCKING DETECTED - ACTION', 'ad-inserter') . '"),jQuery("#ai-adb-bar").addClass ("adb-on"))', $js);
  2120. $js = str_replace ('window.AI_ADB_STATUS_MESSAGE=4', '(jQuery("#ai-adb-status").text ("' . __('AD BLOCKING NOT DETECTED', 'ad-inserter') . '"),jQuery("#ai-adb-bar").addClass ("adb-off"))', $js);
  2121. $js = str_replace ('window.AI_ADB_STATUS_MESSAGE=5', '(jQuery("#ai-adb-status").text ("' . __('AD BLOCKING DETECTION COOKIES DELETED', 'ad-inserter') . '"))', $js);
  2122. $js = str_replace ('window.AI_ADB_STATUS_MESSAGE=6', '(jQuery("#ai-adb-status").text ("' . __('AD BLOCKING DETECTED - NO ACTION', 'ad-inserter') . '"),jQuery("#ai-adb-bar").addClass ("adb-on"))', $js);
  2123. } else {
  2124. $js = str_replace ('window.AI_ADB_STATUS_MESSAGE=1', '(0)', $js);
  2125. $js = str_replace ('window.AI_ADB_STATUS_MESSAGE=2', '(0)', $js);
  2126. $js = str_replace ('window.AI_ADB_STATUS_MESSAGE=3', '(0)', $js);
  2127. $js = str_replace ('window.AI_ADB_STATUS_MESSAGE=4', '(0)', $js);
  2128. $js = str_replace ('window.AI_ADB_STATUS_MESSAGE=5', '(0)', $js);
  2129. $js = str_replace ('window.AI_ADB_STATUS_MESSAGE=6', '(0)', $js);
  2130. }
  2131. }
  2132. }
  2133. $js = str_replace ('AI_ADB_ATTR_NAME', "b64d ('" . base64_encode ('data-'.(defined ('AI_ADB_ATTR') ? AI_ADB_ATTR : 'data-mask')) . "')", $js);
  2134. $js = str_replace ('AI_NONCE', wp_create_nonce ("adinserter_data"), $js);
  2135. $js = str_replace ('AI_AJAXURL', admin_url ('admin-ajax.php'), $js);
  2136. $js = str_replace ('AI_SITE_URL', wp_make_link_relative (get_site_url()), $js);
  2137. $js = str_replace ('AI_HOME_URL', home_url (), $js);
  2138. if (defined ('AI_STATISTICS') && AI_STATISTICS) {
  2139. $js = str_replace ('AI_INTERNAL_TRACKING', get_internal_tracking () == AI_ENABLED ? 1 : 0, $js);
  2140. $js = str_replace ('AI_EXTERNAL_TRACKING', get_external_tracking () == AI_ENABLED ? 1 : 0, $js);
  2141. $js = str_replace ('AI_EXT_CATEGORY', get_external_tracking_category (), $js);
  2142. $js = str_replace ('AI_EXT_ACTION', get_external_tracking_action (), $js);
  2143. $js = str_replace ('AI_EXT_LABEL', get_external_tracking_label (), $js);
  2144. $js = str_replace ('AI_TRACK_PAGEVIEWS', get_track_pageviews () == AI_TRACKING_ENABLED && $ai_wp_data [AI_WP_PAGE_TYPE] != AI_PT_AJAX && !$ai_wp_data [AI_CODE_FOR_IFRAME] ? 1 : 0, $js);
  2145. $js = str_replace ('AI_ADVANCED_CLICK_DETECTION', get_click_detection () == AI_CLICK_DETECTION_ADVANCED ? 1 : 0, $js);
  2146. if (!isset ($ai_wp_data [AI_VIEWPORT_WIDTHS])) {
  2147. $viewport_data = array ();
  2148. for ($viewport = 1; $viewport <= 6; $viewport ++) {
  2149. $viewport_name = get_viewport_name ($viewport);
  2150. $viewport_width = get_viewport_width ($viewport);
  2151. if ($viewport_name != '') {
  2152. $viewport_data []= array ('index' => $viewport, 'name' => $viewport_name, 'width' => $viewport_width);
  2153. }
  2154. }
  2155. usort ($viewport_data, 'ai_compare_viewport');
  2156. $viewport_widthss = array ();
  2157. $viewport_indexes = array ();
  2158. $viewport_names = array ();
  2159. foreach ($viewport_data as $viewport) {
  2160. $viewport_widthss []= $viewport ['width'];
  2161. $viewport_indexes []= $viewport ['index'];
  2162. $viewport_names []= $viewport ['name'];
  2163. }
  2164. $ai_wp_data [AI_VIEWPORT_WIDTHS] = $viewport_widthss;
  2165. $ai_wp_data [AI_VIEWPORT_INDEXES] = $viewport_indexes;
  2166. $ai_wp_data [AI_VIEWPORT_NAMES] = $viewport_names;
  2167. }
  2168. $js = str_replace ('AI_VIEWPORT_WIDTHS', '[' . implode (',', $ai_wp_data [AI_VIEWPORT_WIDTHS]) . ']', $js);
  2169. $js = str_replace ('AI_VIEWPORT_INDEXES', '[' . implode (',', $ai_wp_data [AI_VIEWPORT_INDEXES]) . ']', $js);
  2170. $js = str_replace ('AI_VIEWPORT_NAMES', base64_encode ('["' . implode ('","', $ai_wp_data [AI_VIEWPORT_NAMES]) . '"]'), $js);
  2171. }
  2172. // Deprecated
  2173. $js = str_replace ('AI_BLOCK_CLASS_NAME', get_block_class_name (true), $js);
  2174. if (function_exists ('ai_replace_js_data_2')) ai_replace_js_data_2 ($js); else {
  2175. $js = str_replace ('AI_ADB_CONTENT_CSS_BEGIN_CLASS', 'wp-slider0-pre90', $js);
  2176. $js = str_replace ('AI_ADB_CONTENT_CSS_END_CLASS', 'wp-slider1-pre91', $js);
  2177. $js = str_replace ('AI_ADB_CONTENT_DELETE_BEGIN_CLASS', 'wp-slider2-pre92', $js);
  2178. $js = str_replace ('AI_ADB_CONTENT_DELETE_END_CLASS', 'wp-slider3-pre93', $js);
  2179. $js = str_replace ('AI_ADB_CONTENT_REPLACE_BEGIN_CLASS', 'wp-slider4-pre94', $js);
  2180. $js = str_replace ('AI_ADB_CONTENT_REPLACE_END_CLASS', 'wp-slider5-pre95', $js);
  2181. $js = str_replace ('ai-adb-url', AD_INSERTER_PLUGIN_URL . 'js/', $js);
  2182. }
  2183. return $js;
  2184. }
  2185. function ai_adb_code () {
  2186. return ai_get_js ('ai-adb', false);
  2187. }
  2188. //function ai_ao_override_js_replacetag ($replacetag) {
  2189. // return array ("<span ai-ao></span>","replace");
  2190. //}
  2191. function add_footer_inline_scripts () {
  2192. global $ai_wp_data, $wp_version;
  2193. if (get_disable_js_code ()) return;
  2194. $adb_code = defined ('AI_ADBLOCKING_DETECTION') && AI_ADBLOCKING_DETECTION && $ai_wp_data [AI_ADB_DETECTION] && !isset ($ai_wp_data [AI_ADB_SHORTCODE_DISABLED]);
  2195. if ($adb_code) {
  2196. if (function_exists ('add_footer_inline_scripts_1')) add_footer_inline_scripts_1 (); else {
  2197. echo '<!-- Code for ad blocking detection -->', "\n";
  2198. echo '<!--noptimize-->', "\n";
  2199. if (!defined ('AI_ADB_NO_BANNER_AD')) {
  2200. echo '<div id="banner-advert-container" class="ad-inserter infolinks-ad" style="position:absolute; z-index: -10; height: 1px; width: 1px; top: -1px; left: -1px;"><img id="adsense" class="SponsorAds adsense" src="', AD_INSERTER_PLUGIN_IMAGES_URL, 'ads.png" alt="pixel"></div>', "\n";
  2201. }
  2202. if (!defined ('AI_ADB_NO_ADNXS')) {
  2203. echo '<img id="ai-adb-adnxs" src="" style="position:absolute; z-index: -10; width: 1px; height: 1px; top: -1px; left: -1px;">', "\n";
  2204. }
  2205. if (!defined ('AI_ADB_NO_GOOGLE_ANALYTICS')) {
  2206. echo '<script async id="ai-adb-ga" src="https://www.google-analytics.com/analytics.js"></script>', "\n";
  2207. }
  2208. if (!defined ('AI_ADB_NO_MEDIA_NET')) {
  2209. echo '<script async id="ai-adb-mn" src="//contextual.media.net/dmedianet.js"></script>', "\n";
  2210. }
  2211. if (!defined ('AI_ADB_NO_ADS_JS')) {
  2212. echo '<script async id="ai-adb-ads" src="', plugins_url ('js/ads.js', __FILE__ ), "?ver=", AD_INSERTER_VERSION, '"></script>', "\n";
  2213. }
  2214. if (!defined ('AI_ADB_NO_SPONSORS_JS')) {
  2215. echo '<script async id="ai-adb-sponsors" src="', plugins_url ('js/sponsors.js', __FILE__ ), "?ver=", AD_INSERTER_VERSION, '"></script>', "\n";
  2216. }
  2217. echo '<!--/noptimize-->', "\n";
  2218. echo '<!-- Code for ad blocking detection END -->', "\n";
  2219. }
  2220. }
  2221. // Use updated flags
  2222. ai_set_footer_inline_scripts ();
  2223. if ($ai_wp_data [AI_FOOTER_INLINE_SCRIPTS]) {
  2224. echo "<script>\n";
  2225. $client_side_dynamic_blocks = get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW || get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_INSERT;
  2226. $wait_for_jquery = get_wait_for_jquery ();
  2227. ob_start ();
  2228. echo ai_front_translations_code ();
  2229. if ($ai_wp_data [AI_FRONTEND_JS_DEBUGGING]) {
  2230. $js_code = "";
  2231. if (function_exists ('add_footer_inline_scripts_3')) {
  2232. $js_code .= add_footer_inline_scripts_3 ($js_code);
  2233. }
  2234. $js_code .= "ai_debugging = true;\n";
  2235. echo $js_code;
  2236. }
  2237. if ($client_side_dynamic_blocks ||
  2238. $ai_wp_data [AI_CLIENT_SIDE_DETECTION] ||
  2239. $ai_wp_data [AI_CLIENT_SIDE_INSERTION] ||
  2240. isset ($ai_wp_data [AI_CLIENT_SIDE_ROTATION]) ||
  2241. $ai_wp_data [AI_CLIENT_SIDE_DETECTION] ||
  2242. ($ai_wp_data [AI_CLOSE_BUTTONS] && !$ai_wp_data [AI_CODE_FOR_IFRAME]) ||
  2243. $ai_wp_data [AI_CHECK_BLOCK] ||
  2244. $ai_wp_data [AI_LAZY_LOADING] ||
  2245. ($ai_wp_data [AI_TRACKING] && !isset ($ai_wp_data [AI_TRACKING_SHORTCODE_DISABLED])) ||
  2246. $adb_code
  2247. ) {
  2248. echo ai_get_js ('ai-base64');
  2249. }
  2250. // Wait for jQuery
  2251. if ($wait_for_jquery && !$ai_wp_data [AI_CODE_FOR_IFRAME]) {
  2252. $jquery_ready_code = explode ("AI_JS_CODE=1", ai_get_js ('ai-wait-jquery', false));
  2253. echo $jquery_ready_code [0];
  2254. }
  2255. if ($ai_wp_data [AI_STICKY_WIDGETS] && get_sticky_widget_mode() == AI_STICKY_WIDGET_MODE_JS) {
  2256. // echo ai_get_js ('ResizeSensor');
  2257. echo ai_get_js ('theia-sticky-sidebar');
  2258. }
  2259. if ($ai_wp_data [AI_STICKY_WIDGETS] && !$ai_wp_data [AI_CODE_FOR_IFRAME]) {
  2260. echo ai_get_js ('ai-sidebar');
  2261. }
  2262. if (($ai_wp_data [AI_CLOSE_BUTTONS] && !$ai_wp_data [AI_CODE_FOR_IFRAME]) ||
  2263. $ai_wp_data [AI_CHECK_BLOCK] ||
  2264. ($ai_wp_data [AI_TRACKING] && !isset ($ai_wp_data [AI_TRACKING_SHORTCODE_DISABLED])) ||
  2265. $adb_code ||
  2266. $client_side_dynamic_blocks ||
  2267. $ai_wp_data [AI_CLIENT_SIDE_DETECTION] ||
  2268. $ai_wp_data [AI_CLIENT_SIDE_INSERTION]) {
  2269. echo ai_get_js ('ai-cookie');
  2270. }
  2271. if (($ai_wp_data [AI_CLIENT_SIDE_INSERTION] /*|| $ai_wp_data [AI_CLOSE_BUTTONS] */|| $ai_wp_data [AI_CHECK_BLOCK]) /*&& !$ai_wp_data [AI_CODE_FOR_IFRAME]*/) {
  2272. echo ai_get_js ('ai-insert');
  2273. }
  2274. if (function_exists ('add_footer_inline_scripts_2') && !$ai_wp_data [AI_CODE_FOR_IFRAME]) {
  2275. if ($ai_wp_data [AI_LAZY_LOADING]) {
  2276. echo ai_get_js ('ai-load');
  2277. }
  2278. if ($ai_wp_data [AI_STICK_TO_THE_CONTENT] || $ai_wp_data [AI_ANIMATION]) {
  2279. echo ai_get_js ('ai-sticky');
  2280. }
  2281. }
  2282. if ($client_side_dynamic_blocks || isset ($ai_wp_data [AI_CLIENT_SIDE_ROTATION])) {
  2283. echo ai_get_js ('ai-rotation');
  2284. }
  2285. // VIEWPORT separators or CHECK viewport
  2286. if ($client_side_dynamic_blocks || $ai_wp_data [AI_CLIENT_SIDE_DETECTION] || $ai_wp_data [AI_CLIENT_SIDE_INSERTION] || $adb_code) {
  2287. if ($ai_wp_data [AI_MOBILE_DETECT_JS] || $adb_code) {
  2288. echo ai_get_js ('ai-mobile-detect');
  2289. }
  2290. echo ai_get_js ('ai-lists');
  2291. }
  2292. if ($ai_wp_data [AI_CLOSE_BUTTONS] && !$ai_wp_data [AI_CODE_FOR_IFRAME]) {
  2293. echo ai_get_js ('ai-close');
  2294. }
  2295. if ($ai_wp_data [AI_HTML_ELEMENT_SELECTION]) {
  2296. echo ai_get_js ('ai-select');
  2297. }
  2298. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_BLOCKS) != 0) {
  2299. if (defined ('AI_ADSENSE_OVERLAY') && !(isset ($_GET ["hide-debug-labels"]) && $_GET ["hide-debug-labels"] == 1)) {
  2300. echo ai_get_js ('ai-ads');
  2301. }
  2302. echo ai_get_js ('ai-auto-ads', false);
  2303. }
  2304. if ($adb_code) {
  2305. if (!function_exists ('add_footer_inline_scripts_2')) echo ai_replace_js_data (ai_adb_code ());
  2306. }
  2307. if (function_exists ('add_footer_inline_scripts_2')) {
  2308. add_footer_inline_scripts_2 ();
  2309. }
  2310. if ($ai_wp_data [AI_FOOTER_JS_CODE_DOM_READY] != '') {
  2311. $ai_wp_data [AI_FOOTER_JS_CODE_DOM_READY] = ai_get_js ('ai-errors', false) . $ai_wp_data [AI_FOOTER_JS_CODE_DOM_READY];
  2312. if ($ai_wp_data [AI_FRONTEND_JS_DEBUGGING]) {
  2313. $ai_wp_data [AI_FOOTER_JS_CODE_DOM_READY] = " var ai_debug = typeof ai_debugging !== 'undefined';
  2314. if (typeof ai_debugging !== 'undefined') console.log ('AI DOM READY JS CODE RUN');
  2315. " . $ai_wp_data [AI_FOOTER_JS_CODE_DOM_READY] . " if (typeof ai_debugging !== 'undefined') console.log ('AI DOM READY JS CODE END');
  2316. ";
  2317. }
  2318. echo ai_js_dom_ready ("\n".$ai_wp_data [AI_FOOTER_JS_CODE_DOM_READY], false);
  2319. }
  2320. echo ("\nai_js_code = true;\n");
  2321. // Wait for jQuery - for iframe pages it is always loaded
  2322. if ($wait_for_jquery && !$ai_wp_data [AI_CODE_FOR_IFRAME]) {
  2323. global $wp_scripts;
  2324. if (isset ($wp_scripts->registered ['jquery']->ver)) {
  2325. $ver = $wp_scripts->registered ['jquery']->ver;
  2326. } else {
  2327. $ver = $wp_version;
  2328. }
  2329. echo str_replace (array (
  2330. 'AI_JS_JQUERY0',
  2331. 'AI_JS_JQUERY1',
  2332. // "AI_JS_CODE=2"
  2333. ), array (
  2334. includes_url ('js/jquery/jquery.js') . '?ver=' . $ver,
  2335. includes_url ('js/jquery/jquery-migrate.min.js') . '?ver=' . $wp_version,
  2336. // trim (ai_front_translations_code ())
  2337. ), $jquery_ready_code [1]);
  2338. }
  2339. $footer_js_code = ob_get_clean ();
  2340. if (function_exists ('check_footer_inline_scripts')) {
  2341. $footer_js_code = check_footer_inline_scripts ($footer_js_code);
  2342. }
  2343. echo $footer_js_code;
  2344. echo "\n</script>\n";
  2345. }
  2346. }
  2347. function ai_admin_notice_hook () {
  2348. global $current_screen, $ai_db_options, $ai_wp_data, $ai_db_options_extract;
  2349. global $ai_settings_page, $hook_suffix;
  2350. // $sidebar_widgets = wp_get_sidebars_widgets();
  2351. // $sidebars_with_deprecated_widgets = array ();
  2352. // foreach ($sidebar_widgets as $sidebar_widget_index => $sidebar_widget) {
  2353. // if (is_array ($sidebar_widget))
  2354. // foreach ($sidebar_widget as $widget) {
  2355. // if (preg_match ("/ai_widget([\d]+)/", $widget, $widget_number)) {
  2356. // if (isset ($widget_number [1]) && is_numeric ($widget_number [1])) {
  2357. // $is_widget = $ai_db_options [$widget_number [1]][AI_OPTION_AUTOMATIC_INSERTION] == AD_SELECT_WIDGET;
  2358. // } else $is_widget = false;
  2359. // $sidebar_name = $GLOBALS ['wp_registered_sidebars'][$sidebar_widget_index]['name'];
  2360. // if ($is_widget && $sidebar_name != "")
  2361. // $sidebars_with_deprecated_widgets [$sidebar_widget_index] = $sidebar_name;
  2362. // }
  2363. // }
  2364. // }
  2365. // if (!empty ($sidebars_with_deprecated_widgets)) {
  2366. // echo "<div class='notice notice-warning'><p><strong>Warning</strong>: You are using deprecated Ad Inserter widgets in the following sidebars: ",
  2367. // implode (", ", $sidebars_with_deprecated_widgets),
  2368. // ". Please replace them with the new 'Ad Inserter' code block widget. See <a href='https://wordpress.org/plugins/ad-inserter/faq/' target='_blank'>FAQ</a> for details.</p></div>";
  2369. // }
  2370. if (function_exists ('ai_admin_notices')) ai_admin_notices (); else {
  2371. if (/*$hook_suffix == $ai_settings_page &&*/ is_super_admin () && !wp_is_mobile () && isset ($ai_wp_data [AI_DAYS_SINCE_INSTAL])) {
  2372. if (isset ($ai_db_options_extract [AI_EXTRACT_USED_BLOCKS]) && is_string ($ai_db_options_extract [AI_EXTRACT_USED_BLOCKS]) && strlen ($ai_db_options_extract [AI_EXTRACT_USED_BLOCKS]) != 0) {
  2373. $used_blocks = count (unserialize ($ai_db_options_extract [AI_EXTRACT_USED_BLOCKS]));
  2374. } else $used_blocks = 0;
  2375. $notice_option = get_option ('ai-notice-review');
  2376. if ($notice_option === false && $ai_wp_data [AI_DAYS_SINCE_INSTAL] > 20) $notice_option = 'later';
  2377. if (($notice_option === false && $used_blocks >= 2 && $ai_wp_data [AI_DAYS_SINCE_INSTAL] > 2) || ($notice_option == 'later' && $used_blocks >= 2 && $ai_wp_data [AI_DAYS_SINCE_INSTAL] > 20)) {
  2378. if ($notice_option == 'later') {
  2379. // Translators: 1: number of blocks, 2: Ad Inserter
  2380. $message = sprintf (_n('Hey, you are now using %1$s %2$s block.', 'Hey, you are now using %1$s %2$s blocks.', $used_blocks, 'ad-inserter'), "<strong>{$used_blocks}</strong>", "<strong>Ad Inserter</strong>");
  2381. $option = '<div class="ai-notice-text-button ai-notice-dismiss" data-notice="no">
  2382. <button class="button-primary ai-notice-dismiss" data-notice="no">
  2383. <a href="https://adinserter.pro/contact?ref=notice#help" class="ai-notice-dismiss" target="_blank" data-notice="no">' . __("Please help me to solve a problem first", "ad-inserter") . '</a>
  2384. </button>
  2385. </div><div class="ai-notice-text-button ai-notice-dismiss" data-notice="no">
  2386. <button class="button-primary ai-notice-dismiss" data-notice="no">
  2387. ' . __("Maybe later", "ad-inserter") . '
  2388. </button>
  2389. </div>';
  2390. } else {
  2391. // Translators: %s: Ad Inserter
  2392. $message = sprintf (__("Hey, you are using %s and I hope you're happy with it.", 'ad-inserter'), '<strong>Ad Inserter</strong>');
  2393. $option = '<div class="ai-notice-text-button ai-notice-dismiss" data-notice="later">
  2394. <button class="button-primary ai-notice-dismiss" data-notice="later">
  2395. <a href="https://adinserter.pro/contact?ref=notice#help" class="ai-notice-dismiss" target="_blank" data-notice="later">' . __("OK, but please help me with the settings first", "ad-inserter") . '</a>
  2396. </button>
  2397. </div>';
  2398. }
  2399. ?>
  2400. <div class="notice notice-info ai-notice ai-no-phone" style="display: none;" data-notice="review" data-value="<?php echo base64_encode (wp_create_nonce ("adinserter_data")); ?>" nonce="<?php echo wp_create_nonce ("adinserter_data"); ?>" >
  2401. <div class="ai-notice-element">
  2402. <img src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>icon-50x50.jpg" style="width: 50px; margin: 5px 10px 0px 10px;" />
  2403. </div>
  2404. <div class="ai-notice-element" style="width: 100%; padding: 0 10px 0;">
  2405. <p><?php
  2406. echo $message, ' ';
  2407. _e("Please take a moment to rate the plugin. When you rate it with 5 stars it's like saying 'Thank you'. Somebody will be happy.", 'ad-inserter');
  2408. echo '<br />';
  2409. _e("Positive reviews are a great incentive to fix bugs and to add new features for better monetization of your website.", 'ad-inserter');
  2410. ?></p>
  2411. </div>
  2412. <div class="ai-notice-element ai-notice-buttons last">
  2413. <div class="ai-notice-text-button ai-notice-dismiss" data-notice="yes">
  2414. <button class="button-primary ai-notice-dismiss" data-notice="yes">
  2415. <a href="https://wordpress.org/support/plugin/ad-inserter/reviews/?filter=5#new-post" class="ai-notice-dismiss" target="_blank" data-notice="yes"><?php _e ("Sure", 'ad-inserter'); ?></a>
  2416. </button>
  2417. </div>
  2418. <?php echo $option; ?>
  2419. </div>
  2420. </div>
  2421. <?php
  2422. }
  2423. }
  2424. }
  2425. if ($hook_suffix == $ai_settings_page) {
  2426. if (ai_ampforwp_check_disabled ()) {
  2427. echo '<div class="notice notice-warning is-dismissible" style="margin: 5px 15px 2px 0px;"><p>',
  2428. /* translators: 1: AMPforWP Plugin Manager, 2: Ad Inserter */
  2429. sprintf (__('Warning: %1$s %3$s disabled %4$s %2$s on AMP pages.', 'ad-inserter'), 'AMPforWP Plugin Manager', AD_INSERTER_NAME, '<a href="https://adinserter.pro/documentation/amp-pages#ampforwp" target="_blank" style="text-decoration: none; box-shadow: 0 0 0;">', '</a>'),
  2430. '</p></div>';
  2431. }
  2432. if (version_compare (phpversion (), "5.6", "<")) {
  2433. echo '<div class="notice notice-warning is-dismissible" style="margin: 5px 15px 2px 0px;"><p>',
  2434. /* translators: 1: Ad Inserter, 2, 3: HTML tags */
  2435. sprintf (__('Warning: %1$s requires PHP 5.6 or newer. %2$s Please update! %3$s', 'ad-inserter'), AD_INSERTER_NAME, '<a href="https://wordpress.org/support/update-php/" target="_blank" style="text-decoration: none; box-shadow: 0 0 0;">', '</a>'),
  2436. '</p></div>';
  2437. }
  2438. }
  2439. }
  2440. function ai_plugin_action_links ($links) {
  2441. if (is_multisite() && !is_main_site () && !multisite_settings_page_enabled ()) return $links;
  2442. $settings_link = '<a href="'.admin_url ('options-general.php?page=ad-inserter.php').'">'._x('Settings', 'Menu item', 'ad-inserter') . '</a>';
  2443. array_unshift ($links, $settings_link);
  2444. return $links;
  2445. }
  2446. function ai_after_plugin_row_1 ($plugin_file, $plugin_data, $status) {
  2447. global $ad_inserter_globals;
  2448. if (ai_ampforwp_check_disabled ()) {
  2449. $plugins_css = "\n" . '<style>
  2450. .plugins tr.active[data-slug=ad-inserter] th, .plugins tr.active[data-slug=ad-inserter] td {box-shadow: none;}
  2451. </style>'."\n";
  2452. echo $plugins_css;
  2453. echo '<tr class="plugin-update-tr active';
  2454. if (isset ($plugin_data ['update']) && $plugin_data ['update']) echo ' update';
  2455. echo '"><td colspan="3" class="plugin-update colspanchange ai-message"><div class="update-message notice inline notice-warning notice-alt"><p> ',
  2456. /* translators: 1: AMPforWP Plugin Manager, 2: Ad Inserter, 3, 4: HTML tags */
  2457. sprintf (__('Warning: %1$s %3$s disabled %4$s %2$s on AMP pages.', 'ad-inserter'), 'AMPforWP Plugin Manager', AD_INSERTER_NAME, '<a href="https://adinserter.pro/documentation/amp-pages#ampforwp" target="_blank" style="text-decoration: none; box-shadow: 0 0 0;">', '</a>'),
  2458. '</p></div></td></tr>';
  2459. }
  2460. }
  2461. function ai_set_plugin_meta ($links, $file) {
  2462. if ($file == plugin_basename (__FILE__)) {
  2463. if (is_multisite() && !is_main_site ()) {
  2464. foreach ($links as $index => $link) {
  2465. if (stripos ($link, "update") !== false) unset ($links [$index]);
  2466. }
  2467. }
  2468. if (!is_multisite () || is_main_site ()) {
  2469. $inserted = '<a href="'.admin_url ('options-general.php?page=ad-inserter.php&ai-safe-mode').'" title="'.__('Load settings page in safe mode to avoid collisions with other plugins or theme', 'ad-inserter').'">' . __('Safe mode', 'ad-inserter') . '</a>';
  2470. array_splice ($links, 4, 0, $inserted);
  2471. if (function_exists ('ai_set_plugin_meta_2')) {
  2472. ai_set_plugin_meta_2 ($links);
  2473. }
  2474. elseif (file_exists (AD_INSERTER_PLUGIN_DIR.'includes/js/ai-load.js')) {
  2475. $inserted = 'WP';
  2476. array_splice ($links, 1, 0, $inserted);
  2477. }
  2478. }
  2479. }
  2480. return $links;
  2481. }
  2482. function current_user_role ($user_role_name = "") {
  2483. $role_values = array ("super-admin" => 6, "administrator" => 5, "editor" => 4, "author" => 3, "contributor" => 2, "subscriber" => 1);
  2484. global $wp_roles;
  2485. if ($user_role_name != "") {
  2486. return isset ($role_values [$user_role_name]) ? $role_values [$user_role_name] : 0;
  2487. }
  2488. $user_role = 0;
  2489. $current_user = wp_get_current_user();
  2490. $roles = $current_user->roles;
  2491. // Fix for empty roles
  2492. if (isset ($current_user->caps) && count ($current_user->caps) != 0) {
  2493. $caps = $current_user->caps;
  2494. foreach ($role_values as $role_name => $role_value) {
  2495. if (isset ($caps [$role_name]) && $caps [$role_name]) $roles []= $role_name;
  2496. }
  2497. }
  2498. foreach ($roles as $role) {
  2499. $current_user_role = isset ($role_values [$role]) ? $role_values [$role] : 0;
  2500. if ($current_user_role > $user_role) $user_role = $current_user_role;
  2501. }
  2502. return $user_role;
  2503. }
  2504. function ai_current_user_role_ok () {
  2505. return current_user_role () >= current_user_role (get_minimum_user_role ());
  2506. }
  2507. function ai_add_meta_box_hook() {
  2508. global $ai_wp_data, $block_object;
  2509. if (!ai_current_user_role_ok ()) return;
  2510. if (is_multisite() && !is_main_site () && !multisite_exceptions_enabled ()) return;
  2511. $exceptions_posts = false;
  2512. $exceptions_pages = false;
  2513. for ($block = 1; $block <= 96; $block ++) {
  2514. $obj = $block_object [$block];
  2515. if ($obj->get_exceptions_enabled ()) {
  2516. if ($obj->get_display_settings_post ()) {
  2517. $exceptions_posts = true;
  2518. }
  2519. if ($obj->get_display_settings_page ()) {
  2520. $exceptions_pages = true;
  2521. }
  2522. if ($exceptions_posts && $exceptions_pages) {
  2523. break;
  2524. }
  2525. }
  2526. }
  2527. $screens = array ();
  2528. if ($exceptions_posts) {
  2529. $screens []= 'post';
  2530. }
  2531. if ($exceptions_pages) {
  2532. $screens []= 'page';
  2533. }
  2534. if (empty ($screens)) return;
  2535. $args = array (
  2536. 'public' => true,
  2537. '_builtin' => false
  2538. );
  2539. $custom_post_types = get_post_types ($args, 'names', 'and');
  2540. $screens = array_values (array_merge ($screens, $custom_post_types));
  2541. foreach ($screens as $screen) {
  2542. add_meta_box (
  2543. 'adinserter_sectionid',
  2544. // translators: %s: Ad Inserter
  2545. sprintf (_x('%s Individual Exceptions', 'Meta box name', 'ad-inserter'), AD_INSERTER_NAME),
  2546. 'ai_meta_box_callback',
  2547. $screen
  2548. );
  2549. }
  2550. }
  2551. function ai_meta_box_callback ($post) {
  2552. global $block_object;
  2553. // Add an nonce field so we can check for it later.
  2554. wp_nonce_field ('adinserter_meta_box', 'adinserter_meta_box_nonce');
  2555. $post_type = get_post_type ($post);
  2556. $post_type_object = get_post_type_object ($post_type);
  2557. $page_type_name = $post_type_object->labels->name;
  2558. $page_type_name1 = $post_type_object->labels->singular_name;
  2559. /*
  2560. * Use get_post_meta() to retrieve an existing value
  2561. * from the database and use the value for the form.
  2562. */
  2563. $post_meta = get_post_meta ($post->ID, '_adinserter_block_exceptions', true);
  2564. $selected_blocks = explode (",", $post_meta);
  2565. ob_start ();
  2566. echo '<table>';
  2567. echo '<thead style="font-weight: bold;">';
  2568. echo ' <td>', __('Block', 'ad-inserter') . '</td>';
  2569. echo ' <td style="padding: 0 10px 0 10px;">', __('Name', 'ad-inserter') . '</td>';
  2570. // echo ' <td style="padding: 0 10px 0 10px;">', __('Automatic insertion', 'ad-inserter') . '</td>';
  2571. echo ' <td style="padding: 0 10px 0 10px;">', __('Default insertion', 'ad-inserter') . '</td>';
  2572. // translators: For this post or page
  2573. if ($post_type == 'page')
  2574. echo ' <td style="padding: 0 10px 0 10px;">', _x('For this', 'Page', 'ad-inserter'), ' ', $page_type_name1, '</td>'; else
  2575. echo ' <td style="padding: 0 10px 0 10px;">', _x('For this', 'Post', 'ad-inserter'), ' ', $page_type_name1, '</td>';
  2576. echo '</thead>';
  2577. echo '<tbody>';
  2578. $rows = 0;
  2579. for ($block = 1; $block <= 96; $block ++) {
  2580. $obj = $block_object [$block];
  2581. $exceptions_enabled = $obj->get_exceptions_enabled ();
  2582. $exceptions_function = $obj->get_exceptions_function ();
  2583. if ($post_type == 'page') {
  2584. $page_name1 = _x('pages', 'Enabled/disabled on all', 'ad-inserter');
  2585. $general_enabled = $obj->get_display_settings_page();
  2586. } else {
  2587. $page_name1 = _x('posts', 'Enabled/disabled on all', 'ad-inserter');
  2588. $general_enabled = $obj->get_display_settings_post();
  2589. }
  2590. if (!$general_enabled || !$exceptions_enabled) continue;
  2591. $individual_option_enabled = $general_enabled && $exceptions_enabled;
  2592. $individual_text_enabled = $exceptions_function == AI_DEFAULT_INSERTION_ENABLED;
  2593. if ($rows % 2 != 0) $background = "#F0F0F0"; else $background = "#FFF";
  2594. echo '<tr style="background: ', $background, ';">';
  2595. echo ' <td style="text-align: right; padding: 0 10px 0 0;">', $obj->number, '</td>';
  2596. echo ' <td style="padding: 0 10px 0 10px;"><a href="', admin_url ('options-general.php?page=ad-inserter.php'), '&start=' . (intval (($block - 1) / 16) * 16 + 1), '&tab=', $block, '" style="text-decoration: none; box-shadow: 0 0 0;" target="_blank">', $obj->get_ad_name(), '</a></td>';
  2597. // echo ' <td style="padding: 0 10px 0 10px;">', $obj->get_automatic_insertion_text(), '</td>';
  2598. echo ' <td style="padding: 0 10px 0 10px; text-align: left;">';
  2599. if ($individual_option_enabled) {
  2600. if ($individual_text_enabled) echo __('Enabled', 'ad-inserter'); else echo __('Disabled', 'ad-inserter');
  2601. } else {
  2602. if ($general_enabled) echo __('No individual exceptions', 'ad-inserter'); else
  2603. // translators: Not enabled for pages or posts
  2604. echo __('Not enabled for', 'ad-inserter') . ' ', $page_name1;
  2605. }
  2606. echo ' </td>';
  2607. echo ' <td style="padding: 0 10px 0 10px; text-align: left;">';
  2608. if ($individual_option_enabled) {
  2609. echo '<input type="checkbox" style="border-radius: 5px;" name="adinserter_selected_block_', $block, '" id="ai-selected-block-', $block, '" value="1"', in_array ($block, $selected_blocks) ? ' checked': '', ' />';
  2610. echo '<label for="ai-selected-block-', $block, '">';
  2611. if (!$individual_text_enabled) echo __('Enabled', 'ad-inserter'); else echo __('Disabled', 'ad-inserter');
  2612. echo '</label>';
  2613. } else {
  2614. if (in_array ($block, $selected_blocks)) {
  2615. echo '<span style="margin-left: 6px;">&bull;</span>';
  2616. }
  2617. }
  2618. echo ' </td>';
  2619. echo '</tr>';
  2620. $rows ++;
  2621. }
  2622. echo '</tbody>';
  2623. echo '</table>';
  2624. $exceptions_table = ob_get_clean ();
  2625. if ($rows == 0) {
  2626. // translators: No individual exceptions enabled for pages or posts
  2627. echo '<p><strong>', __('No block has individual exceptions enabled', 'ad-inserter'), '</strong></p>';
  2628. } else echo $exceptions_table;
  2629. // translators: 1: Ad Inserter Settings (page), 2: Tag / Archive pages
  2630. echo '<p>', //;
  2631. sprintf (__('Default insertion can be configured for each block on %1$s page - button next to %2$s checkbox.', 'ad-inserter'),
  2632. // translators: %s: Ad Inserter
  2633. '<a href="' . admin_url ('options-general.php?page=ad-inserter.php') . '" style="text-decoration: none; box-shadow: 0 0 0;" target="_blank">' . sprintf (__('%s Settings', 'ad-inserter'), AD_INSERTER_NAME) . '</a>',
  2634. '<strong>'.__('Tag / Archive pages', 'ad-inserter').'</strong>'), '<br />',
  2635. __('When individual exceptions for a block are enabled, a checkbox will be listed here to change default insertion for this post or page.', 'ad-inserter'), '<br />',
  2636. __('This way you can individually enable or disable blocks on specific posts or pages.', 'ad-inserter'), '<br />';
  2637. printf (__('For more information check page %s', 'ad-inserter'),
  2638. // translators: Ad Inserter Exceptions documentation page
  2639. '<a href="https://adinserter.pro/documentation/individual-post-and-page-exceptions" style="text-decoration: none; box-shadow: 0 0 0;" target="_blank">Ad Inserter ' . __('Individual Exceptions', 'ad-inserter') . '</a>.</p>');
  2640. }
  2641. function ai_save_meta_box_data_hook ($post_id) {
  2642. // Check if our nonce is set.
  2643. if (!isset ($_POST ['adinserter_meta_box_nonce'])) return;
  2644. // Verify that the nonce is valid.
  2645. if (!wp_verify_nonce ($_POST ['adinserter_meta_box_nonce'], 'adinserter_meta_box')) return;
  2646. // If this is an autosave, our form has not been submitted, so we don't want to do anything.
  2647. if (defined ('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
  2648. // Check the user's permissions.
  2649. if (isset ($_POST ['post_type'])) {
  2650. if ($_POST ['post_type'] == 'page') {
  2651. if (!current_user_can ('edit_page', $post_id)) return;
  2652. } else {
  2653. if (!current_user_can ('edit_post', $post_id)) return;
  2654. }
  2655. }
  2656. /* OK, it's safe for us to save the data now. */
  2657. $selected = array ();
  2658. for ($block = 1; $block <= 96; $block ++) {
  2659. $option_name = 'adinserter_selected_block_' . $block;
  2660. if (isset ($_POST [$option_name]) && $_POST [$option_name]) $selected []= $block;
  2661. }
  2662. if (!empty ($selected)) {
  2663. // Update the meta field in the database.
  2664. update_post_meta ($post_id, '_adinserter_block_exceptions', implode (",", $selected));
  2665. } else delete_post_meta ($post_id, '_adinserter_block_exceptions');
  2666. }
  2667. function ai_widgets_init_hook () {
  2668. if (is_multisite() && !is_main_site () && !multisite_widgets_enabled ()) return;
  2669. register_widget ('ai_widget');
  2670. }
  2671. function get_page_type_debug_info ($text = '') {
  2672. global $ai_wp_data;
  2673. switch ($ai_wp_data [AI_WP_PAGE_TYPE]) {
  2674. case AI_PT_STATIC:
  2675. $page_type = __('STATIC PAGE', 'ad-inserter');
  2676. break;
  2677. case AI_PT_POST:
  2678. $page_type = __('POST', 'ad-inserter');
  2679. break;
  2680. case AI_PT_HOMEPAGE:
  2681. $page_type = __('HOMEPAGE', 'ad-inserter');
  2682. break;
  2683. case AI_PT_CATEGORY:
  2684. $page_type = __('CATEGORY PAGE', 'ad-inserter');
  2685. break;
  2686. case AI_PT_SEARCH:
  2687. $page_type = __('SEARCH PAGE', 'ad-inserter');
  2688. break;
  2689. case AI_PT_ARCHIVE:
  2690. $page_type = __('ARCHIVE PAGE', 'ad-inserter');
  2691. break;
  2692. case AI_PT_404:
  2693. $page_type = __('ERROR 404 PAGE', 'ad-inserter');
  2694. break;
  2695. case AI_PT_AJAX:
  2696. $page_type = __('AJAX CALL', 'ad-inserter');
  2697. break;
  2698. default:
  2699. $page_type = __('UNKNOWN PAGE TYPE', 'ad-inserter');
  2700. break;
  2701. }
  2702. $class = AI_DEBUG_PAGE_TYPE_CLASS;
  2703. $page_type = "<section class='$class'>".$text.$page_type."</section>";
  2704. return $page_type;
  2705. }
  2706. function get_adb_status_debug_info () {
  2707. global $ai_wp_data;
  2708. $page_type = '';
  2709. if (defined ('AI_ADBLOCKING_DETECTION') && AI_ADBLOCKING_DETECTION) {
  2710. if ($ai_wp_data [AI_ADB_DETECTION]) {
  2711. $title = __('Click to delete ad blocking detection cokies', 'ad-inserter');
  2712. $status = __('AD BLOCKING STATUS UNKNOWN', 'ad-inserter');
  2713. $events = '';
  2714. if (isset ($_GET ['ai-debug-adb-events']) && $_GET ['ai-debug-adb-events']) {
  2715. $events = "<span id='ai-adb-events'></span>";
  2716. }
  2717. $page_type = "<section id='ai-adb-bar' class='".AI_DEBUG_STATUS_CLASS.' '.AI_DEBUG_ADB_CLASS."' title='$title'><span id='ai-adb-status'>$status</span>$events</section>";
  2718. }
  2719. }
  2720. return $page_type;
  2721. }
  2722. function ai_header_noindex () {
  2723. global $ai_wp_data;
  2724. if ($ai_wp_data [AI_WP_DEBUGGING] != 0 || $ai_wp_data [AI_CODE_FOR_IFRAME]) {
  2725. echo '<meta name="robots" content="noindex">';
  2726. if ($ai_wp_data [AI_WP_DEBUGGING] != 0) {
  2727. echo ' <!-- ', AD_INSERTER_NAME, ' debugging enabled (', substr ('00000000' . strtoupper (decbin ($ai_wp_data [AI_WP_DEBUGGING])), - 8), ') -->';
  2728. }
  2729. echo "\n";
  2730. }
  2731. }
  2732. function get_code_debug_block ($name, $message, $right_text, $code, $inserted_code, $javascript = false) {
  2733. if (strpos ($code, 'enable_page_level_ads') !== false)
  2734. // translators: %s: AdSense Auto Ads
  2735. $message = sprintf (__('Code for %s detected - Code will automatically insert AdSense ads at optimal positions', 'ad-inserter') . ' ',
  2736. '<a style="text-decoration: none; color: #fff; font-weight: bold; box-shadow: none;" href="https://adinserter.pro/documentation/adsense-ads#auto-ads" target="_blank">AdSense Auto Ads</a>');
  2737. $debug_script = new ai_block_labels ('ai-debug-script');
  2738. $debug_block_start = $debug_script->block_start ();
  2739. $debug_block_start .= $debug_script->bar ($name, '', $message, $right_text);
  2740. if ($javascript) $debug_block_start = str_replace (array ('"', "\n", "\r"), array ("'", "\\n", ''), $debug_block_start);
  2741. $debug_block_end = $debug_script->block_end ();
  2742. if ($javascript) $debug_block_end = str_replace (array ('"', "\n", "\r"), array ("'", "\\n", ''), $debug_block_end);
  2743. $html_code = htmlspecialchars ($code);
  2744. if ($javascript) $html_code = str_replace (array ("\n", "\r"), array ("\\n", ''), $html_code);
  2745. $html_inserted_code = htmlspecialchars ($inserted_code);
  2746. if ($javascript) $html_inserted_code = str_replace (array ("\n", "\r"), array ("\\n", ''), $html_inserted_code);
  2747. return $debug_block_start . "<pre class='ai-debug-code ai-code-org'>" . $html_code . "</pre><pre class='ai-debug-code ai-code-inserted'>" . $html_inserted_code . "</pre><div style='clear: both;'></div>" . $debug_block_end;
  2748. }
  2749. function ai_http_header () {
  2750. global $block_object, $ai_wp_data;
  2751. $ai_wp_data [AI_CONTEXT] = AI_CONTEXT_HTTP_HEADER;
  2752. $obj = $block_object [AI_HEADER_OPTION_NAME];
  2753. $obj->clear_code_cache ();
  2754. if ($obj->get_enable_manual ()) {
  2755. if ($ai_wp_data [AI_WP_PAGE_TYPE] != AI_PT_404 || $obj->get_enable_404()) {
  2756. $processed_code = do_shortcode ($obj->ai_getCode ());
  2757. if (strpos ($processed_code, AD_HTTP_SEPARATOR) !== false) {
  2758. $codes = explode (AD_HTTP_SEPARATOR, $processed_code);
  2759. $processed_code = $codes [0];
  2760. } else $processed_code = '';
  2761. $header_lines = explode ("\n", $processed_code);
  2762. foreach ($header_lines as $header_line) {
  2763. if (trim ($header_line) != '' && strpos ($header_line, ':') !== false) {
  2764. header (trim ($header_line));
  2765. }
  2766. }
  2767. }
  2768. }
  2769. }
  2770. function ai_wp_head_hook () {
  2771. global $block_object, $ai_wp_data, $ai_total_plugin_time/*, $ai_front_translations*/;
  2772. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
  2773. ai_log ("HEAD HOOK START");
  2774. $ai_wp_data [AI_PROCESSING_TIME] = true;
  2775. $start_time = microtime (true);
  2776. }
  2777. $ai_wp_data [AI_HEAD] = true;
  2778. if (defined ('AI_BUFFERING')) {
  2779. if (get_output_buffering ()) {
  2780. if ($ai_wp_data [AI_WP_PAGE_TYPE] != AI_PT_AJAX && !$ai_wp_data [AI_CODE_FOR_IFRAME]) {
  2781. ai_buffering_start ();
  2782. }
  2783. }
  2784. }
  2785. if (!get_disable_js_code () &&
  2786. (get_remote_debugging () || ($ai_wp_data [AI_WP_USER] & AI_USER_LOGGED_IN) != 0) &&
  2787. (($ai_wp_data [AI_WP_DEBUGGING] & (AI_DEBUG_POSITIONS | AI_DEBUG_BLOCKS)) != 0 || (isset ($_GET [AI_URL_DEBUG_PROCESSING_FE]) && $_GET [AI_URL_DEBUG_PROCESSING_FE] != 0))) {
  2788. echo "<script>\n", ai_get_js ('ai-errors-head', false), "</script>\n";
  2789. }
  2790. $ai_wp_data [AI_CONTEXT] = AI_CONTEXT_NONE;
  2791. ai_header_noindex ();
  2792. add_head_inline_styles ();
  2793. $header_code = '';
  2794. $header = $block_object [AI_HEADER_OPTION_NAME];
  2795. if ($header->get_enable_manual ()) {
  2796. if (!$header->get_debug_disable_insertion () && !get_disable_header_code ()) {
  2797. if ($header->check_server_side_detection ()) {
  2798. if ($ai_wp_data [AI_WP_PAGE_TYPE] != AI_PT_404 || $header->get_enable_404()) {
  2799. $processed_code = do_shortcode ($header->ai_getCode ());
  2800. if (strpos ($processed_code, AD_HTTP_SEPARATOR) !== false) {
  2801. $codes = explode (AD_HTTP_SEPARATOR, $processed_code);
  2802. $processed_code = ltrim ($codes [1]);
  2803. }
  2804. if (strpos ($processed_code, AD_AMP_SEPARATOR) !== false) {
  2805. $codes = explode (AD_AMP_SEPARATOR, $processed_code);
  2806. $processed_code = $codes [0];
  2807. } elseif ($ai_wp_data [AI_WP_AMP_PAGE]) $processed_code = '';
  2808. $header_code = $processed_code;
  2809. echo $processed_code;
  2810. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
  2811. if (strlen ($processed_code) != 0)
  2812. ai_log ("HEAD CODE: " . strlen ($processed_code) . ' characters');
  2813. }
  2814. }
  2815. }
  2816. } else {
  2817. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
  2818. ai_log ('HEAD CODE DEBUG NO INSERTION');
  2819. }
  2820. }
  2821. }
  2822. if (defined ('AI_BUFFERING')) {
  2823. if (get_output_buffering () && !get_disable_header_code ()) {
  2824. $ai_head_codes = "<!--[AI_HEAD_CODES]-->";
  2825. echo $ai_head_codes;
  2826. // $header_code .= $ai_head_codes; // Don't count this code
  2827. }
  2828. }
  2829. if (!$ai_wp_data [AI_CODE_FOR_IFRAME]) {
  2830. if ($ai_wp_data [AI_WP_DEBUGGING] != 0 && isset ($_GET ['ai-debug-code']) && !defined ('AI_DEBUGGING_DEMO')) {
  2831. if (is_numeric ($_GET ['ai-debug-code']) && $_GET ['ai-debug-code'] >= 1 && $_GET ['ai-debug-code'] <= 96) {
  2832. $obj = $block_object [$_GET ['ai-debug-code']];
  2833. $block_name = $obj->number . ' &nbsp; ' . $obj->get_ad_name ();
  2834. if (!$header->get_debug_disable_insertion ()) {
  2835. $ai_wp_debugging = $ai_wp_data [AI_WP_DEBUGGING];
  2836. $ai_wp_data [AI_WP_DEBUGGING] = 0;
  2837. $code_for_insertion = $obj->get_code_for_insertion ();
  2838. $ai_wp_data [AI_WP_DEBUGGING] = $ai_wp_debugging;
  2839. } else $code_for_insertion = '';
  2840. $ai_wp_data [AI_FOOTER_JS_CODE_DOM_READY] .= " jQuery('body').prepend (\"" . get_code_debug_block (' ' . $block_name, '', __('Code for insertion', 'ad-inserter') . ' ' . strlen ($code_for_insertion) . ' ' . _n('character', 'characters', strlen ($code_for_insertion), 'ad-inserter') . ' ', $obj->ai_getCode (), $code_for_insertion, true) . "\");
  2841. ";
  2842. }
  2843. }
  2844. if (!get_disable_js_code () && $ai_wp_data [AI_IFRAMES]) {
  2845. echo "<script>\n", ai_get_js ('ai-iframes', false), "</script>\n";
  2846. }
  2847. if (!get_disable_js_code () && ($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_POSITIONS) != 0) {
  2848. $ai_wp_data [AI_FOOTER_JS_CODE_DOM_READY] .= ' setTimeout (function(){jQuery(\'body\').prepend ("' . get_page_type_debug_info () . '");}, 1);
  2849. ';
  2850. }
  2851. if (!get_disable_header_code () && isset ($_GET ['ai-debug-code']) && !defined ('AI_DEBUGGING_DEMO')) {
  2852. $ai_wp_data [AI_FOOTER_JS_CODE_DOM_READY] .= " jQuery('body').prepend (\"" . get_code_debug_block (' ' . __('Header code', 'ad-inserter') . ' ' . ($header->get_enable_manual () ? '' : ' ' . _x('DISABLED', 'Header code', 'ad-inserter')), '&lt;head&gt;...&lt;/head&gt;', strlen ($header_code) . ' ' . _n('character inserted', 'characters inserted', strlen ($header_code), 'ad-inserter') . ' ', $header->ai_getCode (), $header_code, true) . "\");
  2853. ";
  2854. }
  2855. }
  2856. // After Header code info
  2857. if (!$ai_wp_data [AI_CODE_FOR_IFRAME]) {
  2858. if (defined ('AI_ADBLOCKING_DETECTION') && AI_ADBLOCKING_DETECTION) {
  2859. // No scripts on AMP pages
  2860. if (($ai_wp_data [AI_WP_DEBUGGING] & (AI_DEBUG_AD_BLOCKING_STATUS | AI_DEBUG_POSITIONS | AI_DEBUG_BLOCKS)) != 0 && $ai_wp_data [AI_ADB_DETECTION]) {
  2861. $ai_wp_data [AI_FOOTER_JS_CODE_DOM_READY] .= " jQuery('body').prepend (\"" . get_adb_status_debug_info () . "\");
  2862. ";
  2863. }
  2864. }
  2865. if (($ai_wp_data [AI_WP_DEBUGGING] & (AI_DEBUG_AD_BLOCKING_STATUS | AI_DEBUG_BLOCKS)) != 0) {
  2866. $ai_wp_data [AI_FOOTER_JS_CODE_DOM_READY] .= " jQuery('body').prepend (\"<section id='ai-iab-tcf-bar' class='".AI_DEBUG_STATUS_CLASS."' style='cursor: pointer; display: none;' title='". __('Click to delete the cokie for the consents', 'ad-inserter') ."'>IAB TCF 2.0 <span id='ai-iab-tcf-status'></span></section>\");
  2867. ";
  2868. }
  2869. }
  2870. // if (!get_disable_js_code () && $ai_wp_data [AI_CODE_FOR_IFRAME]) {
  2871. // echo '<script>', "\n", ai_front_translations_code (), '</script>', "\n";
  2872. // }
  2873. $ai_wp_data [AI_HEAD] = false;
  2874. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
  2875. $ai_total_plugin_time += microtime (true) - $start_time;
  2876. ai_log ("HEAD HOOK END: ". number_format (1000 * (microtime (true) - $start_time), 2)." ms\n");
  2877. $ai_wp_data [AI_PROCESSING_TIME] = false;
  2878. }
  2879. }
  2880. function ai_amp_head_hook () {
  2881. global $block_object, $ai_wp_data, $ai_total_plugin_time;
  2882. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
  2883. ai_log ("AMP HEAD HOOK START");
  2884. $ai_wp_data [AI_PROCESSING_TIME] = true;
  2885. $start_time = microtime (true);
  2886. }
  2887. $ai_wp_data [AI_HEAD] = true;
  2888. if (defined ('AI_BUFFERING')) {
  2889. if (get_output_buffering ()) {
  2890. if ($ai_wp_data [AI_WP_PAGE_TYPE] != AI_PT_AJAX) {
  2891. ai_buffering_start ();
  2892. }
  2893. }
  2894. }
  2895. $ai_wp_data [AI_CONTEXT] = AI_CONTEXT_NONE;
  2896. ai_header_noindex ();
  2897. $header = $block_object [AI_HEADER_OPTION_NAME];
  2898. if ($header->get_enable_manual ()) {
  2899. if (!$header->get_debug_disable_insertion () && !get_disable_header_code ()) {
  2900. if ($header->check_server_side_detection ()) {
  2901. if ($ai_wp_data [AI_WP_PAGE_TYPE] != AI_PT_404 || $header->get_enable_404()) {
  2902. $processed_code = do_shortcode ($header->ai_getCode ());
  2903. if (strpos ($processed_code, AD_HTTP_SEPARATOR) !== false) {
  2904. $codes = explode (AD_HTTP_SEPARATOR, $processed_code);
  2905. $processed_code = ltrim ($codes [1]);
  2906. }
  2907. // ai_log ("ai_amp_head_hook ");
  2908. if (strpos ($processed_code, AD_AMP_SEPARATOR) !== false) {
  2909. $codes = explode (AD_AMP_SEPARATOR, $processed_code);
  2910. $processed_code = ltrim ($codes [1]);
  2911. echo $processed_code;
  2912. // ai_log ("ai_amp_head_hook " . $processed_code);
  2913. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
  2914. if (strlen ($processed_code) != 0)
  2915. ai_log ("HEAD CODE: " . strlen ($processed_code) . ' bytes');
  2916. }
  2917. }
  2918. }
  2919. }
  2920. }
  2921. }
  2922. if (defined ('AI_BUFFERING')) {
  2923. if (get_output_buffering () && !get_disable_header_code ()) {
  2924. $ai_head_codes = "<!--[AI_HEAD_CODES]-->";
  2925. echo $ai_head_codes;
  2926. }
  2927. }
  2928. $ai_wp_data [AI_HEAD] = false;
  2929. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
  2930. $ai_total_plugin_time += microtime (true) - $start_time;
  2931. ai_log ("AMP HEAD HOOK END: ". number_format (1000 * (microtime (true) - $start_time), 2)." ms\n");
  2932. $ai_wp_data [AI_PROCESSING_TIME] = false;
  2933. }
  2934. }
  2935. function ai_front_translations_code () {
  2936. global $ai_front_translations;
  2937. $object_name = 'ai_front';
  2938. $l10n = $ai_front_translations;
  2939. $code = '/* <![CDATA[ */
  2940. ';
  2941. foreach ($l10n as $key => $value) {
  2942. if (!is_scalar ($value)) continue;
  2943. $l10n [$key] = html_entity_decode ((string) $value, ENT_QUOTES, 'UTF-8');
  2944. }
  2945. // $code .= "var $object_name = " . wp_json_encode ($l10n) . ";\n";
  2946. $code .= "$object_name = " . wp_json_encode ($l10n) . ";\n";
  2947. $code .= '/* ]]> */
  2948. ';
  2949. return ($code);
  2950. }
  2951. function ai_amp_css_hook () {
  2952. global $ai_wp_data;
  2953. if (get_disable_css_code ()) return;
  2954. $ai_wp_data [AI_AMP_CSS] = 'AMP CSS HOOK';
  2955. if ($ai_wp_data [AI_CLIENT_SIDE_DETECTION] && !$ai_wp_data [AI_CODE_FOR_IFRAME]) {
  2956. $viewport_css = get_viewport_css ();
  2957. $viewport_css = str_replace ('!important', '', $viewport_css);
  2958. echo $viewport_css;
  2959. }
  2960. if (defined ('AI_AMP_HEADER_STYLES') && AI_AMP_HEADER_STYLES || $ai_wp_data [AI_WP_DEBUGGING] != 0) {
  2961. if (defined ('AI_AMP_HEADER_STYLES') && AI_AMP_HEADER_STYLES) {
  2962. if ($ai_wp_data [AI_WP_DEBUGGING] != 0) generate_debug_css_base ();
  2963. echo get_alignment_css ();
  2964. echo str_replace ('!important', '', ai_get_admin_toolbar_debugging_styles ());
  2965. echo ".ai-align-left * {margin: 0 auto 0 0; text-align: left;}\n";
  2966. echo ".ai-align-right * {margin: 0 0 0 auto; text-align: right;}\n";
  2967. echo ".ai-center * {margin: 0 auto; text-align: center; }\n";
  2968. }
  2969. if ($ai_wp_data [AI_WP_DEBUGGING] != 0) generate_debug_css ();
  2970. }
  2971. }
  2972. function ai_amp_css_hook_style () {
  2973. echo "<style>\n";
  2974. ai_amp_css_hook ();
  2975. echo "</style>\n";
  2976. }
  2977. function ai_wp_footer_hook_end_buffering () {
  2978. global $ai_wp_data, $ai_total_plugin_time;
  2979. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
  2980. ai_log ("FOOTER HOOK TO END BUFFERING START");
  2981. $ai_wp_data [AI_PROCESSING_TIME] = true;
  2982. $start_time = microtime (true);
  2983. }
  2984. if (defined ('AI_BUFFERING')) {
  2985. if (get_output_buffering ()) {
  2986. if ($ai_wp_data [AI_WP_PAGE_TYPE] != AI_PT_AJAX && !$ai_wp_data [AI_CODE_FOR_IFRAME]) {
  2987. ai_buffering_end ();
  2988. }
  2989. }
  2990. }
  2991. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
  2992. $ai_total_plugin_time += microtime (true) - $start_time;
  2993. ai_log ("FOOTER HOOK TO END BUFFERING END: ". number_format (1000 * (microtime (true) - $start_time), 2)." ms\n");
  2994. $ai_wp_data [AI_PROCESSING_TIME] = false;
  2995. }
  2996. }
  2997. function ai_wp_footer_hook () {
  2998. global $block_object, $ai_wp_data, $ad_inserter_globals, $ai_total_plugin_time;
  2999. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
  3000. ai_log ("FOOTER HOOK START");
  3001. $ai_wp_data [AI_PROCESSING_TIME] = true;
  3002. $start_time = microtime (true);
  3003. }
  3004. // if (defined ('AI_BUFFERING')) {
  3005. // if (get_output_buffering ()) {
  3006. // if ($ai_wp_data [AI_WP_PAGE_TYPE] != AI_PT_AJAX && !$ai_wp_data [AI_CODE_FOR_IFRAME]) {
  3007. // ai_buffering_end ();
  3008. // }
  3009. // }
  3010. // }
  3011. if ($ai_wp_data [AI_DISABLE_CACHING]) ai_disable_caching ();
  3012. $ai_wp_data [AI_CONTEXT] = AI_CONTEXT_FOOTER;
  3013. $footer_code = '';
  3014. $footer = $block_object [AI_FOOTER_OPTION_NAME];
  3015. $footer->clear_code_cache ();
  3016. if ($footer->get_enable_manual ()) {
  3017. if (!$footer->get_debug_disable_insertion () && !get_disable_footer_code ()) {
  3018. if ($footer->check_server_side_detection ()) {
  3019. if ($ai_wp_data [AI_WP_PAGE_TYPE] != AI_PT_404 || $footer->get_enable_404()) {
  3020. $processed_code = do_shortcode ($footer->ai_getCode ());
  3021. if (strpos ($processed_code, AD_AMP_SEPARATOR) !== false) {
  3022. $codes = explode (AD_AMP_SEPARATOR, $processed_code);
  3023. $processed_code = $codes [0];
  3024. } elseif ($ai_wp_data [AI_WP_AMP_PAGE]) $processed_code = '';
  3025. $footer_code = $processed_code;
  3026. echo $processed_code;
  3027. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
  3028. if (strlen ($processed_code) != 0)
  3029. ai_log ("FOOTER CODE: " . strlen ($processed_code) . ' characters');
  3030. }
  3031. }
  3032. }
  3033. } else {
  3034. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
  3035. ai_log ('FOOTER CODE DEBUG NO INSERTION');
  3036. }
  3037. }
  3038. }
  3039. if (!$ai_wp_data [AI_CODE_FOR_IFRAME]) {
  3040. if (!get_disable_footer_code () && isset ($_GET ['ai-debug-code']) && !defined ('AI_DEBUGGING_DEMO')) {
  3041. echo get_code_debug_block (' ' . __('Footer code', 'ad-inserter') . ' ' . ($footer->get_enable_manual () ? '' : ' ' . _x('DISABLED', 'Footer code', 'ad-inserter')), '...&lt;/body&gt;', strlen ($footer_code).' ' . _n('character inserted', 'characters inserted', strlen ($footer_code), 'ad-inserter'), $footer->ai_getCode (), $footer_code);
  3042. }
  3043. if (!get_disable_js_code () &&
  3044. (get_remote_debugging () || ($ai_wp_data [AI_WP_USER] & AI_USER_LOGGED_IN) != 0) &&
  3045. (($ai_wp_data [AI_WP_DEBUGGING] & (AI_DEBUG_POSITIONS | AI_DEBUG_BLOCKS)) != 0 || (isset ($_GET [AI_URL_DEBUG_PROCESSING_FE]) && $_GET [AI_URL_DEBUG_PROCESSING_FE] != 0))) {
  3046. $class_0 = AI_DEBUG_STATUS_CLASS.' status-error';
  3047. $class_1 = AI_DEBUG_STATUS_CLASS.' status-ok';
  3048. $javascript_text = "<section class='ai-js-0 $class_0'>" . __('JAVASCRIPT NOT WORKING', 'ad-inserter') . "</section><section class='ai-js-1 $class_1' style='display: none;'>" . __('NO JAVASCRIPT ERRORS', 'ad-inserter') . "</section><section class='ai-js-2 $class_0' style='display: none;'>" . __('JAVASCRIPT ERRORS', 'ad-inserter') . "</section>";
  3049. $ai_wp_data [AI_FOOTER_JS_CODE_DOM_READY] .= str_replace ('AI_HTML_CODE', $javascript_text, ai_get_js ('ai-errors-footer', false));
  3050. echo $javascript_text, "\n";
  3051. echo get_page_type_debug_info () , "\n";
  3052. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0 && isset ($_GET [AI_URL_DEBUG_PROCESSING_FE]) && $_GET [AI_URL_DEBUG_PROCESSING_FE] != 0) {
  3053. echo "\n<pre class='ai-processing-log'>\n\n";
  3054. ai_write_debug_info (true);
  3055. echo "\n</pre>\n";
  3056. }
  3057. }
  3058. }
  3059. if (!(defined ('DOING_AJAX') && DOING_AJAX) || $ai_wp_data [AI_CODE_FOR_IFRAME]) {
  3060. add_footer_inline_scripts ();
  3061. if (function_exists ('ai_add_footer_html')) {
  3062. ai_add_footer_html ();
  3063. }
  3064. }
  3065. if (function_exists ('ai_debug_header')) {
  3066. $ai_option_footer = get_option ('ad_inserter' . '_' . base64_decode ('cHJvX2xp'.'Y2Vuc2U='));
  3067. $ai_option_footer_name = implode ('_', array ('AI', 'STATUS'));
  3068. if ($ai_option_footer !== false && is_string ($ai_option_footer) && isset ($ad_inserter_globals [$ai_option_footer_name]) && $ad_inserter_globals [$ai_option_footer_name] == 1) {
  3069. echo '<div style="display: none;">', base64_decode ('RW5hYmxlIHJlZm'.'VycmVyIGFuZCBjbGljayBjb29ra'.'WUgdG8gc2Vhc'.'mNoIGZvciA='), substr ($ai_option_footer, 0, 14), "</div>\n";
  3070. }
  3071. }
  3072. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
  3073. $ai_total_plugin_time += microtime (true) - $start_time;
  3074. ai_log ("FOOTER HOOK END: ". number_format (1000 * (microtime (true) - $start_time), 2)." ms\n");
  3075. $ai_wp_data [AI_PROCESSING_TIME] = false;
  3076. }
  3077. }
  3078. function ai_amp_footer_hook () {
  3079. global $block_object, $ai_wp_data, $ai_total_plugin_time;
  3080. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
  3081. ai_log ("AMP FOOTER HOOK START");
  3082. $ai_wp_data [AI_PROCESSING_TIME] = true;
  3083. $start_time = microtime (true);
  3084. }
  3085. if (defined ('AI_BUFFERING')) {
  3086. if (get_output_buffering ()) {
  3087. if ($ai_wp_data [AI_WP_PAGE_TYPE] != AI_PT_AJAX) {
  3088. ai_buffering_end ();
  3089. }
  3090. }
  3091. }
  3092. $ai_wp_data [AI_CONTEXT] = AI_CONTEXT_FOOTER;
  3093. $footer = $block_object [AI_FOOTER_OPTION_NAME];
  3094. $footer->clear_code_cache ();
  3095. if ($footer->get_enable_manual ()) {
  3096. if (!$footer->get_debug_disable_insertion () && !get_disable_footer_code ()) {
  3097. if ($footer->check_server_side_detection ()) {
  3098. if ($ai_wp_data [AI_WP_PAGE_TYPE] != AI_PT_404 || $footer->get_enable_404()) {
  3099. $processed_code = do_shortcode ($footer->ai_getCode ());
  3100. if (strpos ($processed_code, AD_AMP_SEPARATOR) !== false) {
  3101. $codes = explode (AD_AMP_SEPARATOR, $processed_code);
  3102. $processed_code = ltrim ($codes [1]);
  3103. echo $processed_code;
  3104. }
  3105. }
  3106. }
  3107. }
  3108. }
  3109. if (!isset ($ai_wp_data [AI_AMP_CSS])) {
  3110. if (ai_amp_plugin_custom_css ()) {
  3111. ai_amp_css_hook_style ();
  3112. $ai_wp_data [AI_AMP_CSS] = 'AMP FOOTER STYLE';
  3113. }
  3114. }
  3115. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_POSITIONS) != 0) {
  3116. echo get_page_type_debug_info ('AMP ') , "\n";
  3117. }
  3118. if ((get_remote_debugging () || ($ai_wp_data [AI_WP_USER] & AI_USER_LOGGED_IN) != 0) &&
  3119. ($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0 &&
  3120. isset ($_GET [AI_URL_DEBUG_PROCESSING_FE]) && $_GET [AI_URL_DEBUG_PROCESSING_FE] != 0) {
  3121. echo "\n<pre class='ai-processing-log'>\n\n";
  3122. ai_write_debug_info (true);
  3123. echo "\n</pre>\n";
  3124. }
  3125. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
  3126. $ai_total_plugin_time += microtime (true) - $start_time;
  3127. ai_log ("AMP FOOTER HOOK END: ". number_format (1000 * (microtime (true) - $start_time), 2)." ms\n");
  3128. $ai_wp_data [AI_PROCESSING_TIME] = false;
  3129. }
  3130. }
  3131. function ai_write_debug_info ($write_processing_log = false) {
  3132. global $block_object, $ai_last_time, $ai_total_plugin_time, $ai_total_block_php_time, $ai_total_hook_php_time, $ai_processing_log, $ai_db_options_extract, $ai_wp_data, $ai_db_options, $block_insertion_log,
  3133. $ai_custom_hooks, $version_string, $subversion_string, $filter_hooks;
  3134. ob_start ();
  3135. echo sprintf ("%-25s%s", AD_INSERTER_NAME, AD_INSERTER_VERSION);
  3136. if (function_exists ('ai_debug_header')) {
  3137. $ai_option = get_option ('ad_inserter' . '_' . base64_decode ('cHJvX2xpY2Vuc2U='));
  3138. if ($ai_option !== false && is_string ($ai_option)) {
  3139. echo ', ', substr ($ai_option, 0, 12);
  3140. }
  3141. ai_debug_header ();
  3142. }
  3143. echo "\n\n";
  3144. if (($install_timestamp = get_option (AI_INSTALL_NAME)) !== false) {
  3145. echo "INSTALLED: ", date ("Y-m-d H:i:s", $install_timestamp + get_option ('gmt_offset') * 3600);
  3146. if (isset ($ai_wp_data [AI_INSTALL_TIME_DIFFERENCE])) {
  3147. printf (' (%04d-%02d-%02d %02d:%02d:%02d, %d days ago)', $ai_wp_data [AI_INSTALL_TIME_DIFFERENCE]->y,
  3148. $ai_wp_data [AI_INSTALL_TIME_DIFFERENCE]->m,
  3149. $ai_wp_data [AI_INSTALL_TIME_DIFFERENCE]->d,
  3150. $ai_wp_data [AI_INSTALL_TIME_DIFFERENCE]->h,
  3151. $ai_wp_data [AI_INSTALL_TIME_DIFFERENCE]->i,
  3152. $ai_wp_data [AI_INSTALL_TIME_DIFFERENCE]->s,
  3153. isset ($ai_wp_data [AI_DAYS_SINCE_INSTAL]) ? $ai_wp_data [AI_DAYS_SINCE_INSTAL] : null);
  3154. }
  3155. echo "\n";
  3156. }
  3157. echo "GENERATED (WP time): ", date ("Y-m-d H:i:s", time() + get_option ('gmt_offset') * 3600), "\n";
  3158. echo "GENERATED (Server time): ", date ("Y-m-d H:i:s", time()), "\n";
  3159. echo "PLUGIN CODE PROCESSING: ", number_format (($ai_total_plugin_time - $ai_total_block_php_time - $ai_total_hook_php_time) * 1000, 2, '.' , ''), " ms\n";
  3160. echo "PLUGIN HOOKS PROCESSING: ", number_format ($ai_total_hook_php_time * 1000, 2, '.' , ''), " ms\n";
  3161. echo "BLOCK CODE PROCESSING: ", number_format ($ai_total_block_php_time * 1000, 2, '.' , ''), " ms\n";
  3162. echo "TOTAL PROCESSING TIME: ", number_format ($ai_total_plugin_time * 1000, 2, '.' , ''), " ms\n";
  3163. // echo "MEMORY USED: ", number_format (memory_get_usage (true) / 1024 / 1024, 2, '.' , ''), " MB\n";
  3164. // echo "PEAK MEMORY USED: ", number_format (memory_get_peak_usage (true) / 1024 / 1024, 2, '.' , ''), " MB\n";
  3165. echo "SETTINGS: ";
  3166. if (isset ($ai_db_options [AI_OPTION_GLOBAL]['VERSION']))
  3167. echo (int) ($ai_db_options [AI_OPTION_GLOBAL]['VERSION'][0].$ai_db_options [AI_OPTION_GLOBAL]['VERSION'][1]), '.',
  3168. (int) ($ai_db_options [AI_OPTION_GLOBAL]['VERSION'][2].$ai_db_options [AI_OPTION_GLOBAL]['VERSION'][3]), '.',
  3169. (int) ($ai_db_options [AI_OPTION_GLOBAL]['VERSION'][4].$ai_db_options [AI_OPTION_GLOBAL]['VERSION'][5]);
  3170. echo "\n";
  3171. echo "SETTINGS SIZE: ", strlen (serialize (ai_get_option (AI_OPTION_NAME))), "\n";
  3172. echo "SETTINGS TIMESTAMP: ";
  3173. echo isset ($ai_db_options [AI_OPTION_GLOBAL]['TIMESTAMP']) ? date ("Y-m-d H:i:s", $ai_db_options [AI_OPTION_GLOBAL]['TIMESTAMP'] + get_option ('gmt_offset') * 3600) : "", "\n";
  3174. $expected_extract_version = $version_string . $subversion_string . '-' . '96';
  3175. if (function_exists ('ai_system_output_check')) {
  3176. $expected_extract_version .= 'P';
  3177. }
  3178. $extract_source = '';
  3179. $saved_settings = ai_get_option (AI_OPTION_NAME);
  3180. if (isset ($saved_settings [AI_OPTION_EXTRACT]['VERSION']) && $saved_settings [AI_OPTION_EXTRACT]['VERSION'] == $expected_extract_version) {
  3181. $saved_extract = $saved_settings [AI_OPTION_EXTRACT];
  3182. $extract_source = 'SAVED SETTINGS';
  3183. } else {
  3184. $saved_extract = get_option (AI_EXTRACT_NAME);
  3185. $extract_source = defined ('AI_EXTRACT_GENERATED') ? "REGENERATED" : 'SAVED EXTRACT';
  3186. }
  3187. echo "SETTINGS EXTRACT: ";
  3188. if (isset ($saved_extract ['VERSION'])) {
  3189. $extract_subversion_blocks = explode ('-', $saved_extract ['VERSION']);
  3190. array_shift ($extract_subversion_blocks);
  3191. echo (int) ($saved_extract ['VERSION'][0].$saved_extract ['VERSION'][1]), '.',
  3192. (int) ($saved_extract ['VERSION'][2].$saved_extract ['VERSION'][3]), '.',
  3193. (int) ($saved_extract ['VERSION'][4].$saved_extract ['VERSION'][5]), '-', implode ('-', $extract_subversion_blocks);
  3194. }
  3195. echo"\n";
  3196. echo "EXTRACT TIMESTAMP: ";
  3197. echo isset ($saved_extract ['TIMESTAMP']) ? date ("Y-m-d H:i:s", $saved_extract ['TIMESTAMP'] + get_option ('gmt_offset') * 3600) : "", "\n";
  3198. echo "EXTRACT SOURCE: ", $extract_source, "\n";
  3199. echo "USER: ";
  3200. if (($ai_wp_data [AI_WP_USER] & AI_USER_LOGGED_IN) == AI_USER_LOGGED_IN) echo "LOGGED-IN "; else echo "NOT LOGGED-IN ";
  3201. if (($ai_wp_data [AI_WP_USER] & AI_USER_ADMINISTRATOR) == AI_USER_ADMINISTRATOR) echo "ADMINISTRATOR";
  3202. $current_user = wp_get_current_user();
  3203. echo "\n";
  3204. echo "USERNAME: ", $current_user->user_login, "\n";
  3205. echo 'USER ROLES: ', implode (', ', $current_user->roles), "\n";
  3206. echo 'MIN.USER FOR EXCEPTIONS: ', get_minimum_user_role (), "\n";
  3207. echo "PAGE TYPE: ";
  3208. switch ($ai_wp_data [AI_WP_PAGE_TYPE]) {
  3209. case AI_PT_STATIC: echo "STATIC PAGE"; break;
  3210. case AI_PT_POST: echo "POST"; break;
  3211. case AI_PT_HOMEPAGE: echo "HOMEPAGE"; break;
  3212. case AI_PT_CATEGORY: echo "CATEGORY PAGE"; break;
  3213. case AI_PT_ARCHIVE: echo "ARCHIVE PAGE"; break;
  3214. case AI_PT_SEARCH: echo "SEARCH PAGE"; break;
  3215. case AI_PT_404: echo "404 PAGE"; break;
  3216. case AI_PT_ADMIN: echo "ADMIN"; break;
  3217. case AI_PT_FEED: echo "FEED"; break;
  3218. case AI_PT_AJAX: echo "AJAX"; break;
  3219. case AI_PT_ANY: echo "ANY ?"; break;
  3220. case AI_PT_NONE: echo "NONE ?"; break;
  3221. default: echo "?"; break;
  3222. }
  3223. echo "\n";
  3224. switch ($ai_wp_data [AI_WP_PAGE_TYPE]) {
  3225. case AI_PT_STATIC:
  3226. case AI_PT_POST:
  3227. $queried_object_id = '';
  3228. $queried_object = get_queried_object ();
  3229. if ($queried_object) {
  3230. $queried_object_id = $queried_object->ID;
  3231. }
  3232. echo 'PUBLISHED: ', date ("Y-m-d H:i:s", get_the_date ('U')), "\n";
  3233. echo 'ID: ', ai_get_post_id ();
  3234. echo " (get_the_ID: ", get_the_ID (), ", get_queried_object: ", $queried_object_id, ")";
  3235. echo "\n";
  3236. echo 'POST TYPE: ', get_post_type (), "\n";
  3237. echo 'AUTHOR: ', strtolower (get_the_author_meta ('user_login')), "\n";
  3238. $category_data = get_the_category();
  3239. $categories = array ();
  3240. foreach ($category_data as $category) {
  3241. $categories []= $category->name . ' ('.$category->slug.')';
  3242. }
  3243. echo 'CATEGORIES: ', implode (', ', $categories), "\n";
  3244. $category_data = get_categories ();
  3245. $categories = array ();
  3246. foreach ($category_data as $category) {
  3247. if (ai_post_is_in_child_categories ($category->slug)) {
  3248. $categories []= $category->name . ' ('.$category->slug.')';
  3249. }
  3250. }
  3251. echo 'PARENT CATEGORIES: ', implode (', ', $categories), "\n";
  3252. echo 'PRIMARY CATEGORY: ', ai_primary_category (), "\n";
  3253. $tag_data = wp_get_post_tags (get_the_ID());
  3254. $tags = array ();
  3255. foreach ($tag_data as $tag) {
  3256. $tags []= $tag->name . ' ('.$tag->slug.')';
  3257. }
  3258. echo 'TAGS: ', implode (', ', $tags), "\n";
  3259. $taxonomies = array ();
  3260. $taxonomy_names = get_post_taxonomies ();
  3261. foreach ($taxonomy_names as $taxonomy_name) {
  3262. $terms = get_the_terms (0, $taxonomy_name);
  3263. if (is_array ($terms)) {
  3264. foreach ($terms as $term) {
  3265. $taxonomies [] = strtolower ($term->taxonomy) . ':' . strtolower ($term->slug);
  3266. }
  3267. }
  3268. }
  3269. echo 'TAXONOMIES: ', implode (', ', $taxonomies), "\n";
  3270. $taxonomy_data = get_taxonomies ();
  3271. $taxonomies = array ();
  3272. foreach ($taxonomy_data as $taxonomy) {
  3273. $terms = get_terms ($taxonomy);
  3274. foreach ($terms as $term) {
  3275. if (ai_post_is_in_child_taxonomies ($taxonomy, $term->slug)) {
  3276. $taxonomies []= $term->name . ' ('.$taxonomy.':'.$term->slug.')';
  3277. }
  3278. }
  3279. }
  3280. echo 'PARENT TAXONOMIES: ', implode (', ', $taxonomies), "\n";
  3281. if (isset ($_GET [AI_URL_DEBUG_META])) {
  3282. $post_meta = get_post_meta (get_the_ID());
  3283. $meta_string = array ();
  3284. foreach ($post_meta as $key => $post_meta_field) {
  3285. foreach ($post_meta_field as $post_meta_field_item) {
  3286. $meta_string []= $key . ':' . $post_meta_field_item;
  3287. }
  3288. }
  3289. echo 'POST META: ', str_replace (array ("<!--", "-->", "\n", "\r"), array ("[!--", "--]", "*n", "*r"), implode (', ', $meta_string)), "\n";
  3290. }
  3291. break;
  3292. case AI_PT_CATEGORY:
  3293. $category_data = get_queried_object();
  3294. $categories = array ();
  3295. if ($category_data instanceof WP_Term) {
  3296. $categories []= $category_data->slug;
  3297. }
  3298. echo 'CATEGORY: ', implode (', ', $categories), "\n";
  3299. break;
  3300. case AI_PT_ARCHIVE:
  3301. $tag_data = wp_get_post_tags (get_the_ID());
  3302. $tags = array ();
  3303. foreach ($tag_data as $tag) {
  3304. $tags []= $tag->slug;
  3305. }
  3306. echo 'TAG: ', implode (', ', $tags), "\n";
  3307. break;
  3308. }
  3309. echo 'AMP PAGE: ', ($ai_wp_data [AI_WP_AMP_PAGE] ? 'YES' : 'NO'), "\n";
  3310. if ($ai_wp_data [AI_WP_AMP_PAGE]) {
  3311. echo 'AMP CSS: ', (isset ($ai_wp_data [AI_AMP_CSS]) ? $ai_wp_data [AI_AMP_CSS] : ''), "\n";
  3312. }
  3313. echo 'URL: ', $ai_wp_data [AI_WP_URL], "\n";
  3314. echo 'REFERER: ', isset ($_SERVER['HTTP_REFERER']) ? strtolower (parse_url ($_SERVER['HTTP_REFERER'], PHP_URL_HOST)) . ' ('. remove_debug_parameters_from_url ($_SERVER['HTTP_REFERER']).')' : "", "\n";
  3315. if (function_exists ('ai_debug')) ai_debug ();
  3316. if ($ai_wp_data [AI_CLIENT_SIDE_DETECTION] || 1) {
  3317. for ($viewport = 1; $viewport <= 6; $viewport ++) {
  3318. $viewport_name = get_viewport_name ($viewport);
  3319. $viewport_width = get_viewport_width ($viewport);
  3320. if ($viewport_name != '') {
  3321. echo 'VIEWPORT ', $viewport, ': ', sprintf ("%-16s min width %s", $viewport_name.' ', $viewport_width), " px\n";
  3322. }
  3323. }
  3324. }
  3325. echo 'SERVER-SIDE DETECTION: ', $ai_wp_data [AI_SERVER_SIDE_DETECTION] ? 'USED' : "NOT USED", "\n";
  3326. if ($ai_wp_data [AI_SERVER_SIDE_DETECTION]) {
  3327. echo 'SERVER-SIDE DEVICE: ';
  3328. if (AI_DESKTOP) echo "DESKTOP\n";
  3329. elseif (AI_TABLET) echo "TABLET\n";
  3330. elseif (AI_PHONE) echo "PHONE\n";
  3331. else echo "?\n";
  3332. }
  3333. echo 'CLIENT-SIDE DETECTION: ', $ai_wp_data [AI_CLIENT_SIDE_DETECTION] ? 'USED' : "NOT USED", "\n";
  3334. echo 'DISABLE CACHING: ', $ai_wp_data [AI_DISABLE_CACHING] ? 'USED' : "NOT USED", "\n";
  3335. echo 'STICKY WIDGETS: ', $ai_wp_data [AI_STICKY_WIDGETS] ? 'USED' : "NOT USED", "\n";
  3336. if (function_exists ('ai_debug_features')) ai_debug_features ();
  3337. echo 'PHP PROCESSING DISABLED: ', defined ('AI_NO_PHP_PROCESSING') ? 'YES' : "NO", "\n";
  3338. $enabled_custom_hooks = array ();
  3339. foreach ($ai_custom_hooks as $ai_custom_hook) {
  3340. $hook = $ai_custom_hook ['index'];
  3341. $enabled_custom_hooks [] = $ai_custom_hook ['action'];
  3342. }
  3343. for ($hook = 1; $hook <= 20; $hook ++) {
  3344. $name = str_replace (array ('&lt;', '&gt;'), array ('<', '>'), get_hook_name ($hook));
  3345. $action = get_hook_action ($hook);
  3346. if (get_hook_enabled ($hook) /*&& $name != '' && $action != ''*/) {
  3347. $priority = get_hook_priority ($hook);
  3348. echo 'CUSTOM HOOK ', sprintf ("%2d", $hook), ': ', sprintf ("%-30s %-35s %d %s", $name, $action, $priority, !in_array ($action, $enabled_custom_hooks) ? 'INVALID' : ''), "\n";
  3349. }
  3350. }
  3351. echo 'BLOCK CLASS NAME: ', get_block_class_name (), "\n";
  3352. echo 'INLINE STYLES: ', get_inline_styles () ? 'ENABLED' : 'DISABLED', "\n";
  3353. echo 'DYNAMIC BLOCKS: ';
  3354. switch (get_dynamic_blocks()) {
  3355. case AI_DYNAMIC_BLOCKS_SERVER_SIDE:
  3356. echo AI_TEXT_ENG_SERVER_SIDE;
  3357. break;
  3358. case AI_DYNAMIC_BLOCKS_SERVER_SIDE_W3TC:
  3359. echo AI_TEXT_ENG_SERVER_SIDE_W3TC;
  3360. break;
  3361. case AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW:
  3362. echo AI_TEXT_ENG_CLIENT_SIDE_SHOW;
  3363. break;
  3364. case AI_DYNAMIC_BLOCKS_CLIENT_SIDE_INSERT:
  3365. echo AI_TEXT_ENG_CLIENT_SIDE_INSERT;
  3366. break;
  3367. }
  3368. echo "\n";
  3369. echo 'STICKY WIDGET MODE: ';
  3370. switch (get_sticky_widget_mode ()) {
  3371. case AI_STICKY_WIDGET_MODE_CSS:
  3372. echo AI_TEXT_CSS;
  3373. break;
  3374. case AI_STICKY_WIDGET_MODE_JS:
  3375. echo AI_TEXT_JS;
  3376. break;
  3377. }
  3378. echo "\n";
  3379. echo 'PARAGRAPH COUNTING: ';
  3380. switch (get_paragraph_counting_functions()) {
  3381. case AI_STANDARD_PARAGRAPH_COUNTING_FUNCTIONS:
  3382. echo AI_TEXT_ENG_STANDARD;
  3383. break;
  3384. case AI_MULTIBYTE_PARAGRAPH_COUNTING_FUNCTIONS:
  3385. echo AI_TEXT_ENG_MULTIBYTE;
  3386. break;
  3387. }
  3388. echo "\n";
  3389. echo 'NO PAR. COUNTING INSIDE: ', get_no_paragraph_counting_inside (), "\n";
  3390. if (defined ('AI_BUFFERING')) {
  3391. echo 'OUTPUT BUFFERING: ';
  3392. switch (get_output_buffering()) {
  3393. case AI_OUTPUT_BUFFERING_DISABLED:
  3394. echo AI_TEXT_ENG_DISABLED;
  3395. break;
  3396. case AI_OUTPUT_BUFFERING_ENABLED:
  3397. echo AI_TEXT_ENG_ENABLED;
  3398. break;
  3399. }
  3400. echo "\n";
  3401. }
  3402. echo 'AD LABEL: ', get_ad_label (), "\n";
  3403. if (defined ('AI_STICKY_SETTINGS') && AI_STICKY_SETTINGS) {
  3404. echo 'MAIN CONTENT: ', get_main_content_element (), "\n";
  3405. }
  3406. echo 'PLUGIN PRIORITY: ', get_plugin_priority (), "\n";
  3407. echo 'TAB SETUP DELAY: ', get_tab_setup_delay (), "\n";
  3408. echo 'ADMIN DISABLE CACHING: ', get_disable_caching () ? 'ENABLED' : 'DISABLED', "\n";
  3409. echo 'WAIT FOR JQUERY: ', get_wait_for_jquery () ? 'ENABLED' : 'DISABLED', "\n";
  3410. echo 'DO NOT CACHE CONSTANTS: ', defined ('DONOTCACHEPAGE') ? 'DONOTCACHEPAGE ' : '', defined ('DONOTCACHEOBJECT') ? 'DONOTCACHEOBJECT ' : '', defined ('DONOTCACHEDB') ? 'DONOTCACHEDB ' : '', "\n";
  3411. $virtual_ads_txt = get_option (AI_ADS_TXT_NAME);
  3412. $virtual_ads_txt_lines = explode ("\n", $virtual_ads_txt);
  3413. echo 'VIRTUAL ADS.TXT: ', $virtual_ads_txt !== false ? count ($virtual_ads_txt_lines). ' LINES' : 'NOT USED', "\n";
  3414. echo 'HEADER: ', $block_object [AI_HEADER_OPTION_NAME]->get_enable_manual () ? 'ENABLED' : 'DISABLED', "\n";
  3415. echo 'FOOTER: ', $block_object [AI_FOOTER_OPTION_NAME]->get_enable_manual () ? 'ENABLED' : 'DISABLED', "\n";
  3416. if (defined ('AI_ADBLOCKING_DETECTION') && AI_ADBLOCKING_DETECTION) {
  3417. echo 'AD BLOCKING DETECTION: ', $ai_wp_data [AI_ADB_DETECTION] ? 'ENABLED' : 'DISABLED', "\n";
  3418. echo 'DISABLED BY SHORTCODE: ', isset ($ai_wp_data [AI_ADB_SHORTCODE_DISABLED]) ? 'YES' : "NO", "\n";
  3419. if ($ai_wp_data [AI_ADB_DETECTION]) {
  3420. echo 'ADB ACTION: ';
  3421. switch (get_adb_action (true)) {
  3422. case AI_ADB_ACTION_NONE:
  3423. echo AI_TEXT_ENG_NONE;
  3424. break;
  3425. case AI_ADB_ACTION_MESSAGE:
  3426. echo AI_TEXT_ENG_POPUP_MESSAGE;
  3427. break;
  3428. case AI_ADB_ACTION_REDIRECTION:
  3429. echo AI_TEXT_ENG_REDIRECTION;
  3430. break;
  3431. }
  3432. echo "\n";
  3433. echo 'ADB NO ACTION: ';
  3434. switch (get_adb_no_action (true)) {
  3435. case AI_ADB_NO_ACTION_NONE:
  3436. echo AI_TEXT_ENG_NONE;
  3437. break;
  3438. case AI_ADB_NO_ACTION_LOGGED_IN:
  3439. echo AI_TEXT_ENG_DISPLAY_LOGGED_IN_USERS;
  3440. break;
  3441. case AI_ADB_NO_ACTION_ADMINISTRATORS:
  3442. echo AI_TEXT_ENG_DISPLAY_ADMINISTRATORS;
  3443. break;
  3444. }
  3445. echo "\n";
  3446. echo 'ADB DELAY ACTION: ', get_delay_action (), "\n";
  3447. echo 'ADB NO ACTION PERIOD: ', get_no_action_period (), "\n";
  3448. echo 'ADB SELECTORS: ', get_adb_selectors (true), "\n";
  3449. if (function_exists ('ai_debug')) {
  3450. echo 'ADB DETECTION: ', get_adb_detection () == AI_ADB_DETECTION_ADVANCED ? 'ADVANCED' : 'STANDARD', "\n";
  3451. }
  3452. $redirection_page = get_redirection_page ();
  3453. echo 'ADB REDIRECTION PAGE: ', $redirection_page != 0 ? get_the_title ($redirection_page) . ' (' . get_permalink ($redirection_page) . ')' : 'Custom Url', "\n";
  3454. echo 'ADB REDIRECTION URL: ', get_custom_redirection_url (), "\n";
  3455. echo 'ADB MESSAGE: ', str_replace (array ("<!--", "-->"), array ("<!++", "++>"), $block_object [AI_ADB_MESSAGE_OPTION_NAME]->ai_getCode ()), "\n";
  3456. echo 'ADB MESSAGE CSS: ', get_message_css (), "\n";
  3457. echo 'ADB OVERLAY CSS: ', get_overlay_css (), "\n";
  3458. echo 'ADB UNDISMISSIBLE: ', get_undismissible_message (true) ? 'ON' : 'OFF', "\n";
  3459. }
  3460. }
  3461. if (isset ($ai_wp_data [AI_CLIENTS]) && isset ($ai_wp_data [AI_AGENT])) {
  3462. if (isset ($_SERVER ['HTTP_USER_AGENT'])) {
  3463. echo 'USER AGENT: ', $_SERVER ['HTTP_USER_AGENT'], "\n";
  3464. }
  3465. $agent = $ai_wp_data [AI_AGENT];
  3466. if (!empty ($ai_wp_data [AI_CLIENTS])) {
  3467. $ai_wp_data [AI_CLIENTS] = array_unique ($ai_wp_data [AI_CLIENTS]);
  3468. foreach ($ai_wp_data [AI_CLIENTS] as $client) {
  3469. echo sprintf (" %-23s", $client.':'), check_client_list ($client, true) ? 'YES' : 'NO', "\n";
  3470. }
  3471. }
  3472. }
  3473. if (!empty ($filter_hooks)) {
  3474. echo "\n";
  3475. foreach ($filter_hooks as $filter_hook) {
  3476. echo "ACTIVE FILTER HOOK: ";
  3477. foreach ($filter_hook as $index => $filter_hook_data) {
  3478. if ($index != 0) echo ", ";
  3479. echo $filter_hook_data;
  3480. }
  3481. echo "\n";
  3482. }
  3483. }
  3484. echo "\n";
  3485. // if ($block_object [AI_HEADER_OPTION_NAME]->get_enable_manual ()) {
  3486. // echo "HEADER CODE ========================================================\n";
  3487. // echo ai_dump_code ($block_object [AI_HEADER_OPTION_NAME]->ai_getCode ());
  3488. // echo "\n====================================================================\n\n";
  3489. // }
  3490. // if ($block_object [AI_FOOTER_OPTION_NAME]->get_enable_manual ()) {
  3491. // echo "FOOTER CODE ========================================================\n";
  3492. // echo ai_dump_code ($block_object [AI_FOOTER_OPTION_NAME]->ai_getCode ());
  3493. // echo "\n====================================================================\n\n";
  3494. // }
  3495. $default = new ai_Block (1);
  3496. echo "BLOCK SETTINGS Po Pa Hp Cp Ap Sp AM Aj Fe 404 Wi Sh PHP\n";
  3497. for ($block = 1; $block <= 96; $block ++) {
  3498. $obj = $block_object [$block];
  3499. $settings = "";
  3500. $insertion_settings = '';
  3501. $alignment_settings = '';
  3502. $default_settings = true;
  3503. // $display_type = '';
  3504. foreach (array_keys ($default->wp_options) as $key){
  3505. switch ($key) {
  3506. case AI_OPTION_CODE:
  3507. case AI_OPTION_BLOCK_NAME:
  3508. continue 2;
  3509. case AI_OPTION_DISPLAY_ON_PAGES:
  3510. case AI_OPTION_DISPLAY_ON_POSTS:
  3511. case AI_OPTION_DISPLAY_ON_HOMEPAGE:
  3512. case AI_OPTION_DISPLAY_ON_CATEGORY_PAGES:
  3513. case AI_OPTION_DISPLAY_ON_SEARCH_PAGES:
  3514. case AI_OPTION_DISPLAY_ON_ARCHIVE_PAGES:
  3515. case AI_OPTION_ENABLE_AMP:
  3516. case AI_OPTION_ENABLE_AJAX:
  3517. case AI_OPTION_ENABLE_FEED:
  3518. case AI_OPTION_ENABLE_404:
  3519. case AI_OPTION_ENABLE_MANUAL:
  3520. case AI_OPTION_ENABLE_WIDGET:
  3521. case AI_OPTION_ENABLE_PHP_CALL:
  3522. if ($obj->wp_options [$key] != $default->wp_options [$key]) $default_settings = false;
  3523. continue 2;
  3524. }
  3525. // if (gettype ($obj->wp_options [$key]) == 'string' && gettype ($default->wp_options [$key]) == 'integer') {
  3526. // $default->wp_options [$key] = strval ($default->wp_options [$key]);
  3527. // }
  3528. // elseif (gettype ($obj->wp_options [$key]) == 'integer' && gettype ($default->wp_options [$key]) == 'string') {
  3529. // $default->wp_options [$key] = intval ($default->wp_options [$key]);
  3530. // }
  3531. // if ($obj->wp_options [$key] !== $default->wp_options [$key]) {
  3532. if ($obj->wp_options [$key] != $default->wp_options [$key]) {
  3533. $default_settings = false;
  3534. switch ($key) {
  3535. case AI_OPTION_AUTOMATIC_INSERTION:
  3536. $insertion_settings = $obj->get_automatic_insertion_text (false, false);
  3537. break;
  3538. case AI_OPTION_SERVER_SIDE_INSERTION:
  3539. $settings .= "[" . $key . ": " . $obj->get_automatic_insertion_text (true, false) . ']';
  3540. break;
  3541. case AI_OPTION_ALIGNMENT_TYPE:
  3542. $alignment_settings = $obj->get_alignment_type_text (false);
  3543. break;
  3544. case AI_OPTION_ENABLED_ON_WHICH_PAGES:
  3545. $settings .= "[" . $key . ": " . $obj->get_ad_enabled_on_which_pages_text (false) . ']';
  3546. break;
  3547. case AI_OPTION_ENABLED_ON_WHICH_POSTS:
  3548. $settings .= "[" . $key . ": " . $obj->get_ad_enabled_on_which_posts_text (false) . ']';
  3549. break;
  3550. case AI_OPTION_EXCEPTIONS_FUNCTION:
  3551. $settings .= "[" . $key . ": " . $obj->get_exceptions_function_text (false) . ']';
  3552. break;
  3553. case AI_OPTION_FILTER_TYPE:
  3554. $settings .= "[" . $key . ": " . $obj->get_filter_type_text (false) . ']';
  3555. break;
  3556. case AI_OPTION_AVOID_ACTION:
  3557. $settings .= "[" . $key . ": " . $obj->get_avoid_action_text (false) . ']';
  3558. break;
  3559. case AI_OPTION_AVOID_DIRECTION:
  3560. $settings .= "[" . $key . ": " . $obj->get_avoid_direction_text (false) . ']';
  3561. break;
  3562. case AI_OPTION_DIRECTION_TYPE:
  3563. $settings .= "[" . $key . ": " . $obj->get_direction_type_text (false) . ']';
  3564. break;
  3565. case AI_OPTION_PARAGRAPH_TEXT_TYPE:
  3566. $settings .= "[" . $key . ": " . $obj->get_paragraph_text_type_text (false) . ']';
  3567. break;
  3568. case AI_OPTION_COUNT_INSIDE:
  3569. $settings .= "[" . $key . ": " . $obj->get_count_inside_text (false) . ']';
  3570. break;
  3571. case AI_OPTION_COUNT_INSIDE_ELEMENTS_CONTAIN:
  3572. $settings .= "[" . $key . ": " . $obj->get_count_inside_elements_contain_text (false) . ']';
  3573. break;
  3574. case AI_OPTION_DISPLAY_FOR_USERS:
  3575. $settings .= "[" . $key . ": " . $obj->get_display_for_users_text (false) . ']';
  3576. break;
  3577. case AI_OPTION_DISPLAY_FOR_DEVICES:
  3578. $settings .= "[" . $key . ": " . $obj->get_display_for_devices_text (false) . ']';
  3579. break;
  3580. case AI_OPTION_PARAGRAPH_TEXT:
  3581. case AI_OPTION_COUNT_INSIDE_ELEMENTS_TEXT:
  3582. case AI_OPTION_AVOID_TEXT_ABOVE:
  3583. case AI_OPTION_AVOID_TEXT_BELOW:
  3584. case AI_OPTION_HTML_SELECTOR:
  3585. if ($write_processing_log)
  3586. $settings .= "[" . $key . ": " . ai_log_filter_content (html_entity_decode ($obj->wp_options [$key])) . ']'; else
  3587. $settings .= "[" . $key . ": " . $obj->wp_options [$key] . ']';
  3588. break;
  3589. default:
  3590. $settings .= "[" . $key . ": " . $obj->wp_options [$key] . ']';
  3591. break;
  3592. }
  3593. // $settings .= ' ['.gettype ($obj->wp_options [$key]).':'.$obj->wp_options [$key].'#'.gettype ($default->wp_options [$key]).':'.$default->wp_options [$key].'] ';
  3594. } else
  3595. switch ($key) {
  3596. case AI_OPTION_AUTOMATIC_INSERTION:
  3597. $insertion_settings = $obj->get_automatic_insertion_text (false, false);
  3598. break;
  3599. case AI_OPTION_ALIGNMENT_TYPE:
  3600. $alignment_settings = $obj->get_alignment_type_text (false);
  3601. break;
  3602. }
  3603. }
  3604. if ($default_settings && $settings == '') continue;
  3605. $settings = ' [' . $insertion_settings . '][' . $alignment_settings . ']' . $settings;
  3606. echo sprintf ("%2d %-21s ", $block, $ai_wp_data [AI_MBSTRING_LOADED] ? mb_substr ($obj->get_ad_name(), 0, 21) : substr ($obj->get_ad_name(), 0, 21));
  3607. echo $obj->get_display_settings_post() ? "o" : ".", " ";
  3608. echo $obj->get_display_settings_page() ? "o" : ".", " ";
  3609. echo $obj->get_display_settings_home() ? "o" : ".", " ";
  3610. echo $obj->get_display_settings_category() ? "o" : ".", " ";
  3611. echo $obj->get_display_settings_archive() ? "o" : ".", " ";
  3612. echo $obj->get_display_settings_search() ? "o" : ".", " ";
  3613. echo $obj->get_enable_amp() ? "o" : ".", " ";
  3614. echo $obj->get_enable_ajax() ? "o" : ".", " ";
  3615. echo $obj->get_enable_feed() ? "o" : ".", " ";
  3616. echo $obj->get_enable_404() ? "o" : ".", " ";
  3617. echo $obj->get_enable_widget() ? "x" : ".", " ";
  3618. echo $obj->get_enable_manual() ? "x" : ".", " ";
  3619. echo $obj->get_enable_php_call() ? "x" : ".", " ";
  3620. echo $settings, "\n";
  3621. }
  3622. echo "\n";
  3623. $args = array (
  3624. 'public' => true,
  3625. '_builtin' => false
  3626. );
  3627. $custom_post_types = get_post_types ($args, 'names', 'and');
  3628. $screens = array_values (array_merge (array ('post', 'page'), $custom_post_types));
  3629. $args = array (
  3630. 'posts_per_page' => AI_LIST_EXCEPTIONS_LIMIT,
  3631. 'offset' => 0,
  3632. 'category' => '',
  3633. 'category_name' => '',
  3634. 'orderby' => 'type',
  3635. 'order' => 'ASC',
  3636. 'include' => '',
  3637. 'exclude' => '',
  3638. 'meta_query' => array (
  3639. array (
  3640. 'key' => '_adinserter_block_exceptions',
  3641. 'value' => '',
  3642. 'compare' => '!='
  3643. )
  3644. ),
  3645. 'post_type' => $screens,
  3646. 'post_mime_type' => '',
  3647. 'post_parent' => '',
  3648. 'author' => '',
  3649. 'author_name' => '',
  3650. 'post_status' => '',
  3651. 'suppress_filters' => true
  3652. );
  3653. $posts_pages = get_posts ($args);
  3654. if (count ($posts_pages) != 0) {
  3655. echo "EXCEPTIONS FOR BLOCKS ID TYPE TITLE URL\n";
  3656. foreach ($posts_pages as $page) {
  3657. $post_meta = get_post_meta ($page->ID, '_adinserter_block_exceptions', true);
  3658. if ($post_meta == '') continue;
  3659. $post_type_object = get_post_type_object ($page->post_type);
  3660. echo sprintf ("%-24s %-6s %-24s %-64s %s", $post_meta, $page->ID, $post_type_object->labels->singular_name, mb_substr ($page->post_title, 0, 64), get_permalink ($page->ID)), "\n";
  3661. }
  3662. echo "\n";
  3663. }
  3664. echo "TOTAL BLOCKS\n";
  3665. if (count ($ai_db_options_extract [ABOVE_HEADER_HOOK_BLOCKS][AI_PT_ANY]))
  3666. echo "ABOVE HEADER: ", implode (", ", $ai_db_options_extract [ABOVE_HEADER_HOOK_BLOCKS][AI_PT_ANY]), "\n";
  3667. if (count ($ai_db_options_extract [CONTENT_HOOK_BLOCKS][AI_PT_ANY]))
  3668. echo "CONTENT HOOK: ", implode (", ", $ai_db_options_extract [CONTENT_HOOK_BLOCKS][AI_PT_ANY]), "\n";
  3669. if (count ($ai_db_options_extract [EXCERPT_HOOK_BLOCKS][AI_PT_ANY]))
  3670. echo "EXCERPT HOOK: ", implode (", ", $ai_db_options_extract [EXCERPT_HOOK_BLOCKS][AI_PT_ANY]), "\n";
  3671. if (count ($ai_db_options_extract [LOOP_START_HOOK_BLOCKS][AI_PT_ANY]))
  3672. echo "LOOP START HOOK: ", implode (", ", $ai_db_options_extract [LOOP_START_HOOK_BLOCKS][AI_PT_ANY]), "\n";
  3673. if (count ($ai_db_options_extract [LOOP_END_HOOK_BLOCKS][AI_PT_ANY]))
  3674. echo "LOOP END HOOK: ", implode (", ", $ai_db_options_extract [LOOP_END_HOOK_BLOCKS][AI_PT_ANY]), "\n";
  3675. if (count ($ai_db_options_extract [POST_HOOK_BLOCKS][AI_PT_ANY]))
  3676. echo "POST HOOK: ", implode (", ", $ai_db_options_extract [POST_HOOK_BLOCKS][AI_PT_ANY]), "\n";
  3677. if (count ($ai_db_options_extract [BEFORE_COMMENTS_HOOK_BLOCKS][AI_PT_ANY]))
  3678. echo "BEFORE COMMENTS HOOK: ", implode (", ", $ai_db_options_extract [BEFORE_COMMENTS_HOOK_BLOCKS][AI_PT_ANY]), "\n";
  3679. if (count ($ai_db_options_extract [BETWEEN_COMMENTS_HOOK_BLOCKS][AI_PT_ANY]))
  3680. echo "BETWEEN COMMENTS HOOK ", implode (", ", $ai_db_options_extract [BETWEEN_COMMENTS_HOOK_BLOCKS][AI_PT_ANY]), "\n";
  3681. if (count ($ai_db_options_extract [AFTER_COMMENTS_HOOK_BLOCKS][AI_PT_ANY]))
  3682. echo "AFTER COMMENTS HOOK: ", implode (", ", $ai_db_options_extract [AFTER_COMMENTS_HOOK_BLOCKS][AI_PT_ANY]), "\n";
  3683. if (count ($ai_db_options_extract [FOOTER_HOOK_BLOCKS][AI_PT_ANY]))
  3684. echo "FOOTER HOOK: ", implode (", ", $ai_db_options_extract [FOOTER_HOOK_BLOCKS][AI_PT_ANY]), "\n";
  3685. foreach ($ai_custom_hooks as $hook_index => $custom_hook) {
  3686. switch ($custom_hook ['action']) {
  3687. case 'wp_footer':
  3688. // case 'wp_head':
  3689. case 'the_content':
  3690. case 'the_excerpt':
  3691. case 'loop_start':
  3692. case 'loop_end':
  3693. // case 'the_post':
  3694. continue 2;
  3695. }
  3696. if (count ($ai_db_options_extract [$custom_hook ['action'] . CUSTOM_HOOK_BLOCKS][AI_PT_ANY]))
  3697. echo substr (strtoupper (str_replace (array ('&lt;', '&gt;'), array ('<', '>'), get_hook_name ($custom_hook ['index']))) . " HOOK: ", 0, 25), implode (", ", $ai_db_options_extract [$custom_hook ['action'] . CUSTOM_HOOK_BLOCKS][AI_PT_ANY]), "\n";
  3698. }
  3699. if (count ($ai_db_options_extract [HTML_ELEMENT_HOOK_BLOCKS][AI_PT_ANY]))
  3700. echo "HTML ELEMENT: ", implode (", ", $ai_db_options_extract [HTML_ELEMENT_HOOK_BLOCKS][AI_PT_ANY]), "\n";
  3701. echo "\nBLOCKS FOR THIS PAGE TYPE\n";
  3702. if (isset ($ai_db_options_extract [ABOVE_HEADER_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [ABOVE_HEADER_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]))
  3703. echo "ABOVE HEADER: ", implode (", ", $ai_db_options_extract [ABOVE_HEADER_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]), "\n";
  3704. if (isset ($ai_db_options_extract [CONTENT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [CONTENT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]))
  3705. echo "CONTENT HOOK: ", implode (", ", $ai_db_options_extract [CONTENT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]), "\n";
  3706. if (isset ($ai_db_options_extract [EXCERPT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [EXCERPT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]))
  3707. echo "EXCERPT HOOK: ", implode (", ", $ai_db_options_extract [EXCERPT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]), "\n";
  3708. if (isset ($ai_db_options_extract [LOOP_START_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [LOOP_START_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]))
  3709. echo "LOOP START HOOK: ", implode (", ", $ai_db_options_extract [LOOP_START_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]), "\n";
  3710. if (isset ($ai_db_options_extract [LOOP_END_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [LOOP_END_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]))
  3711. echo "LOOP END HOOK: ", implode (", ", $ai_db_options_extract [LOOP_END_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]), "\n";
  3712. if (isset ($ai_db_options_extract [POST_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [POST_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]))
  3713. echo "POST HOOK: ", implode (", ", $ai_db_options_extract [POST_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]), "\n";
  3714. if (isset ($ai_db_options_extract [BEFORE_COMMENTS_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [BEFORE_COMMENTS_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]))
  3715. echo "AFTER COMMENTS HOOK: ", implode (", ", $ai_db_options_extract [BEFORE_COMMENTS_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]), "\n";
  3716. if (isset ($ai_db_options_extract [BETWEEN_COMMENTS_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [BETWEEN_COMMENTS_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]))
  3717. echo "BETWEEN COMMENTS HOOK: ", implode (", ", $ai_db_options_extract [BETWEEN_COMMENTS_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]), "\n";
  3718. if (isset ($ai_db_options_extract [AFTER_COMMENTS_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [AFTER_COMMENTS_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]))
  3719. echo "AFTER COMMENTS HOOK: ", implode (", ", $ai_db_options_extract [AFTER_COMMENTS_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]), "\n";
  3720. if (isset ($ai_db_options_extract [FOOTER_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [FOOTER_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]))
  3721. echo "FOOTER HOOK ", implode (", ", $ai_db_options_extract [FOOTER_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]), "\n";
  3722. foreach ($ai_custom_hooks as $hook_index => $custom_hook) {
  3723. switch ($custom_hook ['action']) {
  3724. case 'wp_footer':
  3725. // case 'wp_head':
  3726. case 'the_content':
  3727. case 'the_excerpt':
  3728. case 'loop_start':
  3729. case 'loop_end':
  3730. // case 'the_post':
  3731. continue 2;
  3732. }
  3733. if (isset ($ai_db_options_extract [$custom_hook ['action'] . CUSTOM_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [$custom_hook ['action'] . CUSTOM_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]))
  3734. echo substr (strtoupper (str_replace (array ('&lt;', '&gt;'), array ('<', '>'), get_hook_name ($custom_hook ['index']))) . " HOOK: ", 0, 25), implode (", ", $ai_db_options_extract [$custom_hook ['action'] . CUSTOM_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]), "\n";
  3735. }
  3736. if (isset ($ai_db_options_extract [HTML_ELEMENT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [HTML_ELEMENT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]))
  3737. echo "HTML ELEMENT: ", implode (", ", $ai_db_options_extract [HTML_ELEMENT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]), "\n";
  3738. echo "\nDISABLED BLOCKS: ", isset ($ai_wp_data [AI_DISABLED_BLOCKS]) ? implode (', ', $ai_wp_data [AI_DISABLED_BLOCKS]) : '', "\n";
  3739. if ($write_processing_log) {
  3740. echo "\nTIME EVENT\n";
  3741. echo "======================================\n";
  3742. foreach ($ai_processing_log as $log_line) {
  3743. echo $log_line, "\n";
  3744. }
  3745. sort ($block_insertion_log);
  3746. echo "\nINSERTION SUMMARY\n";
  3747. echo "======================================\n";
  3748. foreach ($block_insertion_log as $log_line) {
  3749. echo substr ($log_line, 3), "\n";
  3750. }
  3751. echo "\n\n";
  3752. echo "SERVER_ADDR: ", isset ($_SERVER ['SERVER_ADDR']) ? $_SERVER ['SERVER_ADDR'] : '', "\n";
  3753. echo "HTTP_CF_CONNECTING_IP: ", isset ($_SERVER ['HTTP_CF_CONNECTING_IP']) ? $_SERVER ['HTTP_CF_CONNECTING_IP'] : '', "\n";
  3754. echo "HTTP_CLIENT_IP: ", isset ($_SERVER ['HTTP_CLIENT_IP']) ? $_SERVER ['HTTP_CLIENT_IP'] : '', "\n";
  3755. echo "HTTP_X_FORWARDED_FOR: ", isset ($_SERVER ['HTTP_X_FORWARDED_FOR']) ? $_SERVER ['HTTP_X_FORWARDED_FOR'] : '', "\n";
  3756. echo "HTTP_X_FORWARDED: ", isset ($_SERVER ['HTTP_X_FORWARDED']) ? $_SERVER ['HTTP_X_FORWARDED'] : '', "\n";
  3757. echo "HTTP_X_CLUSTER_CLIENT_IP:", isset ($_SERVER ['HTTP_X_CLUSTER_CLIENT_IP']) ? $_SERVER ['HTTP_X_CLUSTER_CLIENT_IP'] : '', "\n";
  3758. echo "HTTP_FORWARDED_FOR: ", isset ($_SERVER ['HTTP_FORWARDED_FOR']) ? $_SERVER ['HTTP_FORWARDED_FOR'] : '', "\n";
  3759. echo "HTTP_FORWARDED: ", isset ($_SERVER ['HTTP_FORWARDED']) ? $_SERVER ['HTTP_FORWARDED'] : '', "\n";
  3760. echo "REMOTE_ADDR: ", isset ($_SERVER ['REMOTE_ADDR']) ? $_SERVER ['REMOTE_ADDR'] : '', "\n";
  3761. echo "\n";
  3762. echo "MULTISITE: ", is_multisite() ? "YES" : "NO", "\n";
  3763. if (is_multisite()) {
  3764. echo "MAIN SITE: ", is_main_site () ? "YES" : "NO", "\n";
  3765. echo "SITE COUNT: ", get_blog_count(), "\n";
  3766. }
  3767. echo "site_url: ", site_url (), "\n";
  3768. echo "home_url: ", home_url (), "\n";
  3769. if (is_multisite()) {
  3770. echo "network_home_url: ", network_home_url (), "\n";
  3771. }
  3772. echo "ABSPATH: ", ABSPATH, "\n";
  3773. echo "WP_CONTENT_DIR: ", WP_CONTENT_DIR, "\n";
  3774. echo "\n";
  3775. echo "PHP: ", phpversion(), "\n";
  3776. echo "mbstring: ", $ai_wp_data [AI_MBSTRING_LOADED] ? 'LOADED' : 'NO', "\n";
  3777. echo "Default charset: ", ini_get ("default_charset"), "\n";
  3778. echo "Memory Limit: ", ini_get ('memory_limit'), "\n";
  3779. echo "Upload Max Filesize: ", ini_get ('upload_max_filesize'), "\n";
  3780. echo "Post Max Size: ", ini_get ('post_max_size'), "\n";
  3781. echo "Max Execution Time: ", ini_get ('max_execution_time'), "\n";
  3782. echo "Max Input Vars: ", ini_get ('max_input_vars'), "\n";
  3783. echo "Display Errors: ", ini_get ('display_errors'), "\n";
  3784. echo "cURL: ", function_exists ('curl_version') ? 'ENABLED' : 'DISABLED', "\n";
  3785. echo "fsockopen: ", function_exists ('fsockopen') ? 'ENABLED' : 'DISABLED', "\n";
  3786. echo "DOMDocument: ", class_exists ('DOMDocument') ? 'YES' : 'NO', "\n";
  3787. echo "\n\n";
  3788. global $wp_version;
  3789. echo "Wordpress: ", $wp_version, "\n";
  3790. $current_theme = wp_get_theme();
  3791. echo "Current Theme: ", $current_theme->get ('Name') . " " . $current_theme->get ('Version'), "\n";
  3792. echo "\n";
  3793. echo "A INSTALLED PLUGINS\n";
  3794. echo "======================================\n";
  3795. if ( ! function_exists( 'get_plugins' ) ) {
  3796. require_once ABSPATH . 'wp-admin/includes/plugin.php';
  3797. }
  3798. $all_plugins = get_plugins();
  3799. $active_plugins = get_option ('active_plugins');
  3800. $active_sitewide_plugins = is_multisite () ? get_site_option ('active_sitewide_plugins') : false;
  3801. foreach ($all_plugins as $plugin_path => $plugin) {
  3802. $multisite_status = ' ';
  3803. if ($active_sitewide_plugins !== false) {
  3804. $multisite_status = array_key_exists ($plugin_path, $active_sitewide_plugins) ? '# ' : ' ';
  3805. }
  3806. echo in_array ($plugin_path, $active_plugins) ? '* ' : $multisite_status, html_entity_decode ($plugin ["Name"]), ' ', $plugin ["Version"], "\n";
  3807. }
  3808. }
  3809. $log = ob_get_clean ();
  3810. $log = str_replace (array ('<', '>'), array ('&lt;', '&gt;'), $log);
  3811. echo $log;
  3812. }
  3813. function ai_shutdown_hook () {
  3814. global $ai_wp_data, $ad_inserter_globals;
  3815. $global_name = implode ('_', array (
  3816. 'AI',
  3817. 'STATUS')
  3818. );
  3819. if (function_exists ('ai_system_output')) ai_system_output ();
  3820. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0 && (get_remote_debugging () || (isset ($ad_inserter_globals [$global_name]) && $ad_inserter_globals [$global_name] == 1) || ($ai_wp_data [AI_WP_USER] & AI_USER_LOGGED_IN) != 0)) {
  3821. if ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_HOMEPAGE ||
  3822. $ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_STATIC ||
  3823. $ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_POST ||
  3824. $ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_CATEGORY ||
  3825. $ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_SEARCH ||
  3826. $ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_ARCHIVE ||
  3827. $ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_404 ||
  3828. $ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_NONE ||
  3829. $ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_ANY) {
  3830. echo "\n<!--\n\n";
  3831. ai_write_debug_info (true);
  3832. echo "\n-->\n";
  3833. }
  3834. }
  3835. }
  3836. function ai_activation_hook () {
  3837. ai_add_rewrite_rules ();
  3838. flush_rewrite_rules();
  3839. }
  3840. function ai_deactivation_hook () {
  3841. flush_rewrite_rules();
  3842. }
  3843. function ai_check_multisite_options (&$multisite_options) {
  3844. if (!isset ($multisite_options ['MULTISITE_SETTINGS_PAGE'])) $multisite_options ['MULTISITE_SETTINGS_PAGE'] = DEFAULT_MULTISITE_SETTINGS_PAGE;
  3845. if (!isset ($multisite_options ['MULTISITE_WIDGETS'])) $multisite_options ['MULTISITE_WIDGETS'] = DEFAULT_MULTISITE_WIDGETS;
  3846. if (!isset ($multisite_options ['MULTISITE_PHP_PROCESSING'])) $multisite_options ['MULTISITE_PHP_PROCESSING'] = DEFAULT_MULTISITE_PHP_PROCESSING;
  3847. if (!isset ($multisite_options ['MULTISITE_EXCEPTIONS'])) $multisite_options ['MULTISITE_EXCEPTIONS'] = DEFAULT_MULTISITE_EXCEPTIONS;
  3848. if (!isset ($multisite_options ['MULTISITE_MAIN_FOR_ALL_BLOGS'])) $multisite_options ['MULTISITE_MAIN_FOR_ALL_BLOGS'] = DEFAULT_MULTISITE_MAIN_FOR_ALL_BLOGS;
  3849. if (!isset ($multisite_options ['MULTISITE_SITE_ADMIN_PAGE'])) $multisite_options ['MULTISITE_SITE_ADMIN_PAGE'] = DEFAULT_MULTISITE_SITE_ADMIN_PAGE;
  3850. if (function_exists ('ai_check_multisite_options_2')) ai_check_multisite_options_2 ($multisite_options);
  3851. }
  3852. function ai_check_limits ($value, $min, $max, $default) {
  3853. if (!is_numeric ($value)) {
  3854. $value = $default;
  3855. }
  3856. $value = intval ($value);
  3857. if ($value < $min) {
  3858. $value = $min;
  3859. }
  3860. if ($value > $max) {
  3861. $value = $max;
  3862. }
  3863. return $value;
  3864. }
  3865. function ai_check_plugin_options ($plugin_options = array ()) {
  3866. global $version_string;
  3867. $plugin_options ['VERSION'] = $version_string;
  3868. if (!isset ($plugin_options ['SYNTAX_HIGHLIGHTER_THEME'])) $plugin_options ['SYNTAX_HIGHLIGHTER_THEME'] = DEFAULT_SYNTAX_HIGHLIGHTER_THEME;
  3869. if (!isset ($plugin_options ['BLOCK_CLASS_NAME'])) $plugin_options ['BLOCK_CLASS_NAME'] = DEFAULT_BLOCK_CLASS_NAME;
  3870. if (!isset ($plugin_options ['BLOCK_CLASS'])) $plugin_options ['BLOCK_CLASS'] = DEFAULT_BLOCK_CLASS;
  3871. if (!isset ($plugin_options ['BLOCK_NUMBER_CLASS'])) $plugin_options ['BLOCK_NUMBER_CLASS'] = DEFAULT_BLOCK_NUMBER_CLASS;
  3872. if (!isset ($plugin_options ['BLOCK_NAME_CLASS'])) $plugin_options ['BLOCK_NAME_CLASS'] = DEFAULT_BLOCK_NAME_CLASS;
  3873. if (!isset ($plugin_options ['INLINE_STYLES'])) $plugin_options ['INLINE_STYLES'] = DEFAULT_INLINE_STYLES;
  3874. if (!isset ($plugin_options ['MINIMUM_USER_ROLE'])) $plugin_options ['MINIMUM_USER_ROLE'] = DEFAULT_MINIMUM_USER_ROLE;
  3875. if (!isset ($plugin_options ['STICKY_WIDGET_MODE'])) $plugin_options ['STICKY_WIDGET_MODE'] = DEFAULT_STICKY_WIDGET_MODE;
  3876. if (!isset ($plugin_options ['STICKY_WIDGET_MARGIN'])) $plugin_options ['STICKY_WIDGET_MARGIN'] = DEFAULT_STICKY_WIDGET_MARGIN;
  3877. $plugin_options ['STICKY_WIDGET_MARGIN'] = ai_check_limits ($plugin_options ['STICKY_WIDGET_MARGIN'], 0, 999, DEFAULT_STICKY_WIDGET_MARGIN);
  3878. if (!isset ($plugin_options ['LAZY_LOADING_OFFSET'])) $plugin_options ['LAZY_LOADING_OFFSET'] = DEFAULT_LAZY_LOADING_OFFSET;
  3879. $plugin_options ['LAZY_LOADING_OFFSET'] = ai_check_limits ($plugin_options ['LAZY_LOADING_OFFSET'], 0, 9999, DEFAULT_LAZY_LOADING_OFFSET);
  3880. if (!isset ($plugin_options ['MAX_PAGE_BLOCKS'])) $plugin_options ['MAX_PAGE_BLOCKS'] = DEFAULT_MAX_PAGE_BLOCKS;
  3881. $plugin_options ['MAX_PAGE_BLOCKS'] = ai_check_limits ($plugin_options ['MAX_PAGE_BLOCKS'], 0, 9999, DEFAULT_MAX_PAGE_BLOCKS);
  3882. if (!isset ($plugin_options ['PLUGIN_PRIORITY'])) $plugin_options ['PLUGIN_PRIORITY'] = DEFAULT_PLUGIN_PRIORITY;
  3883. $plugin_options ['PLUGIN_PRIORITY'] = ai_check_limits ($plugin_options ['PLUGIN_PRIORITY'], 0, 999999, DEFAULT_PLUGIN_PRIORITY);
  3884. if (!isset ($plugin_options ['TAB_SETUP_DELAY'])) $plugin_options ['TAB_SETUP_DELAY'] = DEFAULT_TAB_SETUP_DELAY;
  3885. $plugin_options ['TAB_SETUP_DELAY'] = ai_check_limits ($plugin_options ['TAB_SETUP_DELAY'], 0, 9999, DEFAULT_TAB_SETUP_DELAY);
  3886. if (!isset ($plugin_options ['CLICK_FRAUD_PROTECTION'])) $plugin_options ['CLICK_FRAUD_PROTECTION'] = DEFAULT_CLICK_FRAUD_PROTECTION;
  3887. if (!isset ($plugin_options ['CLICK_FRAUD_PROTECTION_TIME'])) $plugin_options ['CLICK_FRAUD_PROTECTION_TIME'] = DEFAULT_CLICK_FRAUD_PROTECTION_TIME;
  3888. if (!isset ($plugin_options ['DYNAMIC_BLOCKS'])) $plugin_options ['DYNAMIC_BLOCKS'] = DEFAULT_DYNAMIC_BLOCKS;
  3889. if (!isset ($plugin_options ['PARAGRAPH_COUNTING_FUNCTIONS'])) $plugin_options ['PARAGRAPH_COUNTING_FUNCTIONS'] = DEFAULT_PARAGRAPH_COUNTING_FUNCTIONS;
  3890. if (!isset ($plugin_options ['OUTPUT_BUFFERING'])) $plugin_options ['OUTPUT_BUFFERING'] = DEFAULT_OUTPUT_BUFFERING;
  3891. if (!isset ($plugin_options ['DISABLE_CACHING'])) $plugin_options ['DISABLE_CACHING'] = DEFAULT_DISABLE_CACHING;
  3892. if (!isset ($plugin_options ['WAIT_FOR_JQUERY'])) $plugin_options ['WAIT_FOR_JQUERY'] = DEFAULT_WAIT_FOR_JQUERY;
  3893. if (!isset ($plugin_options ['NO_PARAGRAPH_COUNTING_INSIDE'])) $plugin_options ['NO_PARAGRAPH_COUNTING_INSIDE'] = DEFAULT_NO_PARAGRAPH_COUNTING_INSIDE;
  3894. if (!isset ($plugin_options ['AD_LABEL'])) $plugin_options ['AD_LABEL'] = DEFAULT_AD_TITLE;
  3895. if (!isset ($plugin_options ['MAIN_CONTENT_ELEMENT'])) $plugin_options ['MAIN_CONTENT_ELEMENT'] = DEFAULT_MAIN_CONTENT_ELEMENT;
  3896. if (!isset ($plugin_options ['ADB_ACTION'])) $plugin_options ['ADB_ACTION'] = AI_DEFAULT_ADB_ACTION;
  3897. if (!isset ($plugin_options ['ADB_NO_ACTION'])) $plugin_options ['ADB_NO_ACTION'] = AI_DEFAULT_ADB_NO_ACTION;
  3898. if (!isset ($plugin_options ['ADB_DELAY_ACTION'])) $plugin_options ['ADB_DELAY_ACTION'] = '';
  3899. if (!isset ($plugin_options ['ADB_NO_ACTION_PERIOD'])) $plugin_options ['ADB_NO_ACTION_PERIOD'] = AI_DEFAULT_ADB_NO_ACTION_PERIOD;
  3900. if (!isset ($plugin_options ['ADB_SELECTORS'])) $plugin_options ['ADB_SELECTORS'] = '';
  3901. if (!isset ($plugin_options ['ADB_REDIRECTION_PAGE'])) $plugin_options ['ADB_REDIRECTION_PAGE'] = AI_DEFAULT_ADB_REDIRECTION_PAGE;
  3902. if (!isset ($plugin_options ['ADB_CUSTOM_REDIRECTION_URL'])) $plugin_options ['ADB_CUSTOM_REDIRECTION_URL'] = '';
  3903. if (!isset ($plugin_options ['ADB_OVERLAY_CSS'])) $plugin_options ['ADB_OVERLAY_CSS'] = AI_DEFAULT_ADB_OVERLAY_CSS;
  3904. if (!isset ($plugin_options ['ADB_MESSAGE_CSS'])) $plugin_options ['ADB_MESSAGE_CSS'] = AI_DEFAULT_ADB_MESSAGE_CSS;
  3905. if (!isset ($plugin_options ['ADB_UNDISMISSIBLE_MESSAGE'])) $plugin_options ['ADB_UNDISMISSIBLE_MESSAGE'] = AI_DEFAULT_ADB_UNDISMISSIBLE_MESSAGE;
  3906. if (!isset ($plugin_options ['ADB_NO_UNDISMISSIBLE_MESSAGE'])) $plugin_options ['ADB_NO_UNDISMISSIBLE_MESSAGE'] = AI_DEFAULT_ADB_NO_UNDISMISSIBLE_MESSAGE;
  3907. if (!isset ($plugin_options ['ADMIN_TOOLBAR_DEBUGGING'])) $plugin_options ['ADMIN_TOOLBAR_DEBUGGING'] = DEFAULT_ADMIN_TOOLBAR_DEBUGGING;
  3908. if (!isset ($plugin_options ['ADMIN_TOOLBAR_MOBILE'])) $plugin_options ['ADMIN_TOOLBAR_MOBILE'] = DEFAULT_ADMIN_TOOLBAR_MOBILE;
  3909. if (!isset ($plugin_options ['FORCE_ADMIN_TOOLBAR'])) $plugin_options ['FORCE_ADMIN_TOOLBAR'] = DEFAULT_FORCE_ADMIN_TOOLBAR;
  3910. if (!isset ($plugin_options ['REMOTE_DEBUGGING'])) $plugin_options ['REMOTE_DEBUGGING'] = DEFAULT_REMOTE_DEBUGGING;
  3911. if (!isset ($plugin_options ['DISABLE_TRANSLATION'])) $plugin_options ['DISABLE_TRANSLATION'] = DEFAULT_DISABLE_TRANSLATION;
  3912. if (!isset ($plugin_options ['BACKEND_JS_DEBUGGING'])) $plugin_options ['BACKEND_JS_DEBUGGING'] = DEFAULT_BACKEND_JS_DEBUGGING;
  3913. if (!isset ($plugin_options ['FRONTEND_JS_DEBUGGING'])) $plugin_options ['FRONTEND_JS_DEBUGGING'] = DEFAULT_FRONTEND_JS_DEBUGGING;
  3914. if (!isset ($plugin_options ['DISABLE_BLOCK_INSERTIONS'])) $plugin_options ['DISABLE_BLOCK_INSERTIONS'] = DEFAULT_DISABLE_BLOCK_INSERTIONS;
  3915. if (!isset ($plugin_options ['DISABLE_PHP_PROCESSING'])) $plugin_options ['DISABLE_PHP_PROCESSING'] = DEFAULT_DISABLE_PHP_PROCESSING;
  3916. if (!isset ($plugin_options ['DISABLE_HTML_CODE'])) $plugin_options ['DISABLE_HTML_CODE'] = DEFAULT_DISABLE_HTML_CODE;
  3917. if (!isset ($plugin_options ['DISABLE_CSS_CODE'])) $plugin_options ['DISABLE_CSS_CODE'] = DEFAULT_DISABLE_CSS_CODE;
  3918. if (!isset ($plugin_options ['DISABLE_JS_CODE'])) $plugin_options ['DISABLE_JS_CODE'] = DEFAULT_DISABLE_JS_CODE;
  3919. if (!isset ($plugin_options ['DISABLE_HEADER_CODE'])) $plugin_options ['DISABLE_HEADER_CODE'] = DEFAULT_DISABLE_HEADER_CODE;
  3920. if (!isset ($plugin_options ['DISABLE_FOOTER_CODE'])) $plugin_options ['DISABLE_FOOTER_CODE'] = DEFAULT_DISABLE_FOOTER_CODE;
  3921. $min_width_0_defined = false;
  3922. for ($viewport = 1; $viewport <= 6; $viewport ++) {
  3923. $viewport_name_option_name = 'VIEWPORT_NAME_' . $viewport;
  3924. $viewport_width_option_name = 'VIEWPORT_WIDTH_' . $viewport;
  3925. if (!isset ($plugin_options [$viewport_name_option_name])) $plugin_options [$viewport_name_option_name] =
  3926. defined ("DEFAULT_VIEWPORT_NAME_" . $viewport) ? constant ("DEFAULT_VIEWPORT_NAME_" . $viewport) : "";
  3927. if ($viewport == 1 && $plugin_options [$viewport_name_option_name] == '')
  3928. $plugin_options [$viewport_name_option_name] = constant ("DEFAULT_VIEWPORT_NAME_1");
  3929. if ($plugin_options [$viewport_name_option_name] != '') {
  3930. $last_viewport_width_option_name = $viewport_width_option_name;
  3931. if (!isset ($plugin_options [$viewport_width_option_name])) $plugin_options [$viewport_width_option_name] =
  3932. defined ("DEFAULT_VIEWPORT_WIDTH_" . $viewport) ? constant ("DEFAULT_VIEWPORT_WIDTH_" . $viewport) : 0;
  3933. $viewport_width = $plugin_options [$viewport_width_option_name];
  3934. if ($viewport > 1) {
  3935. $previous_viewport_option_width = $plugin_options ['VIEWPORT_WIDTH_' . ($viewport - 1)];
  3936. }
  3937. if (!is_numeric ($viewport_width)) {
  3938. if ($viewport == 1)
  3939. $viewport_width = constant ("DEFAULT_VIEWPORT_WIDTH_1"); else
  3940. $viewport_width = $previous_viewport_option_width - 1;
  3941. }
  3942. if ($viewport_width > 9999) {
  3943. $viewport_width = 9999;
  3944. }
  3945. // if ($viewport > 1) {
  3946. // if ($viewport_width >= $previous_viewport_option_width)
  3947. // $viewport_width = $previous_viewport_option_width - 1;
  3948. // }
  3949. $viewport_width = intval ($viewport_width);
  3950. if ($viewport_width < 0) {
  3951. $viewport_width = 0;
  3952. }
  3953. if ($viewport_width == 0) {
  3954. $min_width_0_defined = true;
  3955. }
  3956. $plugin_options [$viewport_width_option_name] = $viewport_width;
  3957. } else $plugin_options [$viewport_width_option_name] = '';
  3958. }
  3959. if (!$min_width_0_defined) {
  3960. $plugin_options [$last_viewport_width_option_name] = 0;
  3961. }
  3962. for ($hook = 1; $hook <= 20; $hook ++) {
  3963. $hook_enabled_settins_name = 'HOOK_ENABLED_' . $hook;
  3964. $hook_name_settins_name = 'HOOK_NAME_' . $hook;
  3965. $hook_action_settins_name = 'HOOK_ACTION_' . $hook;
  3966. $hook_priority_settins_name = 'HOOK_PRIORITY_' . $hook;
  3967. if (!isset ($plugin_options [$hook_enabled_settins_name])) $plugin_options [$hook_enabled_settins_name] = AI_DISABLED;
  3968. if (!isset ($plugin_options [$hook_name_settins_name])) $plugin_options [$hook_name_settins_name] = '';
  3969. if (!isset ($plugin_options [$hook_action_settins_name])) $plugin_options [$hook_action_settins_name] = '';
  3970. if (!isset ($plugin_options [$hook_priority_settins_name]) || !is_numeric ($plugin_options [$hook_priority_settins_name])) $plugin_options [$hook_priority_settins_name] = DEFAULT_CUSTOM_HOOK_PRIORITY;
  3971. }
  3972. if (function_exists ('ai_check_options')) ai_check_options ($plugin_options);
  3973. return ($plugin_options);
  3974. }
  3975. function option_stripslashes (&$options) {
  3976. $options = wp_unslash ($options);
  3977. // if (is_array ($options)) {
  3978. // foreach ($options as $key => $option) {
  3979. // option_stripslashes ($options [$key]);
  3980. // }
  3981. // } else if (is_string ($options)) $options = stripslashes ($options);
  3982. }
  3983. // Deprecated
  3984. function ai_get_old_option ($option_name) {
  3985. $options = get_option ($option_name);
  3986. option_stripslashes ($options);
  3987. return ($options);
  3988. }
  3989. function ai_get_option ($option_name) {
  3990. $ai_db_options = get_option ($option_name);
  3991. if ($ai_db_options === false) {
  3992. return $ai_db_options;
  3993. }
  3994. if (is_string ($ai_db_options) && substr ($ai_db_options, 0, 4) === ':AI:') {
  3995. $ai_db_options = unserialize (base64_decode (substr ($ai_db_options, 4), true));
  3996. }
  3997. return $ai_db_options;
  3998. }
  3999. function ai_update_option ($option_name, $value) {
  4000. update_option ($option_name, ':AI:'. base64_encode (serialize ($value)));
  4001. }
  4002. function ai_load_options () {
  4003. global $ai_db_options, $ai_db_options_multisite, $ai_wp_data;
  4004. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) ai_log ("LOAD OPTIONS START");
  4005. if (is_multisite()) {
  4006. $ai_db_options_multisite = get_site_option (AI_OPTION_NAME);
  4007. option_stripslashes ($ai_db_options_multisite);
  4008. }
  4009. if (is_multisite() && multisite_main_for_all_blogs () && defined ('BLOG_ID_CURRENT_SITE')) {
  4010. $ai_db_options = get_blog_option (BLOG_ID_CURRENT_SITE, AI_OPTION_NAME);
  4011. if (is_string ($ai_db_options) && substr ($ai_db_options, 0, 4) === ':AI:') {
  4012. $ai_db_options = unserialize (base64_decode (substr ($ai_db_options, 4), true));
  4013. }
  4014. option_stripslashes ($ai_db_options);
  4015. } else {
  4016. $ai_db_options = ai_get_option (AI_OPTION_NAME);
  4017. option_stripslashes ($ai_db_options);
  4018. }
  4019. if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) ai_log ("LOAD OPTIONS END");
  4020. }
  4021. function get_viewport_css () {
  4022. global $ai_db_options;
  4023. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['VIEWPORT_CSS'])) $ai_db_options [AI_OPTION_GLOBAL]['VIEWPORT_CSS'] = generate_viewport_css ();
  4024. return ($ai_db_options [AI_OPTION_GLOBAL]['VIEWPORT_CSS']);
  4025. }
  4026. function get_alignment_css () {
  4027. global $ai_db_options;
  4028. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['ALIGNMENT_CSS']) ||
  4029. isset ($ai_db_options [AI_OPTION_GLOBAL]['VERSION']) && $ai_db_options [AI_OPTION_GLOBAL]['VERSION'] < '020211'
  4030. ) $ai_db_options [AI_OPTION_GLOBAL]['ALIGNMENT_CSS'] = generate_alignment_css ();
  4031. return (str_replace ('&#039;', "'", $ai_db_options [AI_OPTION_GLOBAL]['ALIGNMENT_CSS']));
  4032. }
  4033. function get_syntax_highlighter_theme () {
  4034. global $ai_db_options;
  4035. // return 'ad-inserter';
  4036. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['SYNTAX_HIGHLIGHTER_THEME'])) $ai_db_options [AI_OPTION_GLOBAL]['SYNTAX_HIGHLIGHTER_THEME'] = DEFAULT_SYNTAX_HIGHLIGHTER_THEME;
  4037. return ($ai_db_options [AI_OPTION_GLOBAL]['SYNTAX_HIGHLIGHTER_THEME']);
  4038. }
  4039. function get_block_class_name ($default_if_empty = false) {
  4040. global $ai_db_options;
  4041. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['BLOCK_CLASS_NAME'])) $ai_db_options [AI_OPTION_GLOBAL]['BLOCK_CLASS_NAME'] = DEFAULT_BLOCK_CLASS_NAME;
  4042. if ($default_if_empty && $ai_db_options [AI_OPTION_GLOBAL]['BLOCK_CLASS_NAME'] == '') return (DEFAULT_BLOCK_CLASS_NAME);
  4043. return ($ai_db_options [AI_OPTION_GLOBAL]['BLOCK_CLASS_NAME']);
  4044. }
  4045. function get_block_class () {
  4046. global $ai_db_options;
  4047. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['BLOCK_CLASS'])) $ai_db_options [AI_OPTION_GLOBAL]['BLOCK_CLASS'] = DEFAULT_BLOCK_CLASS;
  4048. return ($ai_db_options [AI_OPTION_GLOBAL]['BLOCK_CLASS']);
  4049. }
  4050. function get_block_number_class () {
  4051. global $ai_db_options;
  4052. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['BLOCK_NUMBER_CLASS'])) $ai_db_options [AI_OPTION_GLOBAL]['BLOCK_NUMBER_CLASS'] = DEFAULT_BLOCK_NUMBER_CLASS;
  4053. return ($ai_db_options [AI_OPTION_GLOBAL]['BLOCK_NUMBER_CLASS']);
  4054. }
  4055. function get_block_name_class () {
  4056. global $ai_db_options;
  4057. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['BLOCK_NAME_CLASS'])) $ai_db_options [AI_OPTION_GLOBAL]['BLOCK_NAME_CLASS'] = DEFAULT_BLOCK_NAME_CLASS;
  4058. return ($ai_db_options [AI_OPTION_GLOBAL]['BLOCK_NAME_CLASS']);
  4059. }
  4060. function get_inline_styles () {
  4061. global $ai_db_options;
  4062. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['INLINE_STYLES'])) $ai_db_options [AI_OPTION_GLOBAL]['INLINE_STYLES'] = DEFAULT_INLINE_STYLES;
  4063. return ($ai_db_options [AI_OPTION_GLOBAL]['INLINE_STYLES']);
  4064. }
  4065. function get_minimum_user_role () {
  4066. global $ai_db_options;
  4067. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['MINIMUM_USER_ROLE'])) $ai_db_options [AI_OPTION_GLOBAL]['MINIMUM_USER_ROLE'] = DEFAULT_MINIMUM_USER_ROLE;
  4068. return ($ai_db_options [AI_OPTION_GLOBAL]['MINIMUM_USER_ROLE']);
  4069. }
  4070. function get_sticky_widget_mode () {
  4071. global $ai_db_options;
  4072. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['STICKY_WIDGET_MODE'])) $ai_db_options [AI_OPTION_GLOBAL]['STICKY_WIDGET_MODE'] = DEFAULT_STICKY_WIDGET_MODE;
  4073. return ($ai_db_options [AI_OPTION_GLOBAL]['STICKY_WIDGET_MODE']);
  4074. }
  4075. function get_sticky_widget_margin () {
  4076. global $ai_db_options;
  4077. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['STICKY_WIDGET_MARGIN'])) $ai_db_options [AI_OPTION_GLOBAL]['STICKY_WIDGET_MARGIN'] = DEFAULT_STICKY_WIDGET_MARGIN;
  4078. return ($ai_db_options [AI_OPTION_GLOBAL]['STICKY_WIDGET_MARGIN']);
  4079. }
  4080. function get_lazy_loading_offset () {
  4081. global $ai_db_options;
  4082. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['LAZY_LOADING_OFFSET'])) $ai_db_options [AI_OPTION_GLOBAL]['LAZY_LOADING_OFFSET'] = DEFAULT_LAZY_LOADING_OFFSET;
  4083. return ($ai_db_options [AI_OPTION_GLOBAL]['LAZY_LOADING_OFFSET']);
  4084. }
  4085. function get_click_fraud_protection () {
  4086. global $ai_db_options;
  4087. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['CLICK_FRAUD_PROTECTION'])) $ai_db_options [AI_OPTION_GLOBAL]['CLICK_FRAUD_PROTECTION'] = DEFAULT_CLICK_FRAUD_PROTECTION;
  4088. return ($ai_db_options [AI_OPTION_GLOBAL]['CLICK_FRAUD_PROTECTION']);
  4089. }
  4090. function get_click_fraud_protection_time () {
  4091. global $ai_db_options;
  4092. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['CLICK_FRAUD_PROTECTION_TIME'])) $ai_db_options [AI_OPTION_GLOBAL]['CLICK_FRAUD_PROTECTION_TIME'] = DEFAULT_CLICK_FRAUD_PROTECTION_TIME;
  4093. return ($ai_db_options [AI_OPTION_GLOBAL]['CLICK_FRAUD_PROTECTION_TIME']);
  4094. }
  4095. function get_max_page_blocks () {
  4096. global $ai_db_options;
  4097. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['MAX_PAGE_BLOCKS'])) $ai_db_options [AI_OPTION_GLOBAL]['MAX_PAGE_BLOCKS'] = DEFAULT_MAX_PAGE_BLOCKS;
  4098. return ($ai_db_options [AI_OPTION_GLOBAL]['MAX_PAGE_BLOCKS']);
  4099. }
  4100. function get_plugin_priority () {
  4101. global $ai_db_options;
  4102. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['PLUGIN_PRIORITY'])) $ai_db_options [AI_OPTION_GLOBAL]['PLUGIN_PRIORITY'] = DEFAULT_PLUGIN_PRIORITY;
  4103. return ($ai_db_options [AI_OPTION_GLOBAL]['PLUGIN_PRIORITY']);
  4104. }
  4105. function get_tab_setup_delay () {
  4106. global $ai_db_options;
  4107. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['TAB_SETUP_DELAY'])) $ai_db_options [AI_OPTION_GLOBAL]['TAB_SETUP_DELAY'] = DEFAULT_TAB_SETUP_DELAY;
  4108. return ($ai_db_options [AI_OPTION_GLOBAL]['TAB_SETUP_DELAY']);
  4109. }
  4110. function get_dynamic_blocks(){
  4111. global $ai_db_options, $ai_wp_data;
  4112. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['DYNAMIC_BLOCKS'])) $ai_db_options [AI_OPTION_GLOBAL]['DYNAMIC_BLOCKS'] = DEFAULT_DYNAMIC_BLOCKS;
  4113. return ($ai_db_options [AI_OPTION_GLOBAL]['DYNAMIC_BLOCKS']);
  4114. }
  4115. function get_paragraph_counting_functions(){
  4116. global $ai_db_options;
  4117. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['PARAGRAPH_COUNTING_FUNCTIONS'])) $ai_db_options [AI_OPTION_GLOBAL]['PARAGRAPH_COUNTING_FUNCTIONS'] = DEFAULT_PARAGRAPH_COUNTING_FUNCTIONS;
  4118. return ($ai_db_options [AI_OPTION_GLOBAL]['PARAGRAPH_COUNTING_FUNCTIONS']);
  4119. }
  4120. function get_output_buffering(){
  4121. global $ai_db_options;
  4122. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['OUTPUT_BUFFERING'])) $ai_db_options [AI_OPTION_GLOBAL]['OUTPUT_BUFFERING'] = DEFAULT_OUTPUT_BUFFERING;
  4123. return ($ai_db_options [AI_OPTION_GLOBAL]['OUTPUT_BUFFERING']);
  4124. }
  4125. function get_disable_caching (){
  4126. global $ai_db_options;
  4127. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['DISABLE_CACHING'])) $ai_db_options [AI_OPTION_GLOBAL]['DISABLE_CACHING'] = DEFAULT_DISABLE_CACHING;
  4128. return ($ai_db_options [AI_OPTION_GLOBAL]['DISABLE_CACHING']);
  4129. }
  4130. function get_wait_for_jquery (){
  4131. global $ai_db_options;
  4132. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['WAIT_FOR_JQUERY'])) $ai_db_options [AI_OPTION_GLOBAL]['WAIT_FOR_JQUERY'] = DEFAULT_WAIT_FOR_JQUERY;
  4133. return ($ai_db_options [AI_OPTION_GLOBAL]['WAIT_FOR_JQUERY']);
  4134. }
  4135. function get_no_paragraph_counting_inside () {
  4136. global $ai_db_options;
  4137. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['NO_PARAGRAPH_COUNTING_INSIDE'])) $ai_db_options [AI_OPTION_GLOBAL]['NO_PARAGRAPH_COUNTING_INSIDE'] = DEFAULT_NO_PARAGRAPH_COUNTING_INSIDE;
  4138. return (str_replace (array ('<', '>'), '', $ai_db_options [AI_OPTION_GLOBAL]['NO_PARAGRAPH_COUNTING_INSIDE']));
  4139. }
  4140. function get_ad_label ($decode = false) {
  4141. global $ai_db_options;
  4142. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['AD_LABEL'])) $ai_db_options [AI_OPTION_GLOBAL]['AD_LABEL'] = DEFAULT_AD_TITLE;
  4143. if ($decode) return (html_entity_decode ($ai_db_options [AI_OPTION_GLOBAL]['AD_LABEL']));
  4144. return ($ai_db_options [AI_OPTION_GLOBAL]['AD_LABEL']);
  4145. }
  4146. function get_main_content_element () {
  4147. global $ai_db_options;
  4148. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['MAIN_CONTENT_ELEMENT'])) $ai_db_options [AI_OPTION_GLOBAL]['MAIN_CONTENT_ELEMENT'] = DEFAULT_MAIN_CONTENT_ELEMENT;
  4149. return ($ai_db_options [AI_OPTION_GLOBAL]['MAIN_CONTENT_ELEMENT']);
  4150. }
  4151. function get_force_admin_toolbar () {
  4152. global $ai_db_options;
  4153. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['FORCE_ADMIN_TOOLBAR'])) $ai_db_options [AI_OPTION_GLOBAL]['FORCE_ADMIN_TOOLBAR'] = DEFAULT_FORCE_ADMIN_TOOLBAR;
  4154. return ($ai_db_options [AI_OPTION_GLOBAL]['FORCE_ADMIN_TOOLBAR']);
  4155. }
  4156. function get_admin_toolbar_debugging () {
  4157. global $ai_db_options;
  4158. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['ADMIN_TOOLBAR_DEBUGGING'])) $ai_db_options [AI_OPTION_GLOBAL]['ADMIN_TOOLBAR_DEBUGGING'] = DEFAULT_ADMIN_TOOLBAR_DEBUGGING;
  4159. return ($ai_db_options [AI_OPTION_GLOBAL]['ADMIN_TOOLBAR_DEBUGGING']);
  4160. }
  4161. function get_admin_toolbar_mobile () {
  4162. global $ai_db_options;
  4163. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['ADMIN_TOOLBAR_MOBILE'])) $ai_db_options [AI_OPTION_GLOBAL]['ADMIN_TOOLBAR_MOBILE'] = DEFAULT_ADMIN_TOOLBAR_MOBILE;
  4164. return ($ai_db_options [AI_OPTION_GLOBAL]['ADMIN_TOOLBAR_MOBILE']);
  4165. }
  4166. function get_remote_debugging () {
  4167. global $ai_db_options;
  4168. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['REMOTE_DEBUGGING'])) $ai_db_options [AI_OPTION_GLOBAL]['REMOTE_DEBUGGING'] = DEFAULT_REMOTE_DEBUGGING;
  4169. return ($ai_db_options [AI_OPTION_GLOBAL]['REMOTE_DEBUGGING']);
  4170. }
  4171. function get_disable_translation () {
  4172. global $ai_db_options;
  4173. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['DISABLE_TRANSLATION'])) $ai_db_options [AI_OPTION_GLOBAL]['DISABLE_TRANSLATION'] = DEFAULT_DISABLE_TRANSLATION;
  4174. return ($ai_db_options [AI_OPTION_GLOBAL]['DISABLE_TRANSLATION']);
  4175. }
  4176. function get_backend_javascript_debugging () {
  4177. global $ai_db_options;
  4178. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['BACKEND_JS_DEBUGGING'])) $ai_db_options [AI_OPTION_GLOBAL]['BACKEND_JS_DEBUGGING'] = DEFAULT_BACKEND_JS_DEBUGGING;
  4179. return ($ai_db_options [AI_OPTION_GLOBAL]['BACKEND_JS_DEBUGGING']);
  4180. }
  4181. function get_frontend_javascript_debugging () {
  4182. global $ai_db_options;
  4183. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['FRONTEND_JS_DEBUGGING'])) $ai_db_options [AI_OPTION_GLOBAL]['FRONTEND_JS_DEBUGGING'] = DEFAULT_FRONTEND_JS_DEBUGGING;
  4184. return ($ai_db_options [AI_OPTION_GLOBAL]['FRONTEND_JS_DEBUGGING']);
  4185. }
  4186. function get_disable_block_insertions () {
  4187. global $ai_db_options;
  4188. if (isset ($_GET [AI_URL_DEBUG_DISABLE_BLOCK_INSERTIONS]) && $_GET [AI_URL_DEBUG_DISABLE_BLOCK_INSERTIONS] == 'all' && get_remote_debugging ()) return true;
  4189. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['DISABLE_BLOCK_INSERTIONS'])) $ai_db_options [AI_OPTION_GLOBAL]['DISABLE_BLOCK_INSERTIONS'] = DEFAULT_DISABLE_BLOCK_INSERTIONS;
  4190. return ($ai_db_options [AI_OPTION_GLOBAL]['DISABLE_BLOCK_INSERTIONS']);
  4191. }
  4192. function get_disable_php_processing () {
  4193. global $ai_db_options;
  4194. if (isset ($_GET [AI_URL_DEBUG_DISABLE_PHP_PROCESSING]) && $_GET [AI_URL_DEBUG_DISABLE_PHP_PROCESSING] && get_remote_debugging ()) return true;
  4195. if (isset ($_GET [AI_URL_DEBUG_DISABLE_BLOCK_INSERTIONS]) && get_remote_debugging ()) {
  4196. if ($_GET [AI_URL_DEBUG_DISABLE_BLOCK_INSERTIONS] == 'php') return true;
  4197. if (strpos ($_GET [AI_URL_DEBUG_DISABLE_BLOCK_INSERTIONS], '-') !== false) {
  4198. $blocks = explode ('-', $_GET [AI_URL_DEBUG_DISABLE_BLOCK_INSERTIONS]);
  4199. if (in_array ('php', $blocks)) return true;
  4200. }
  4201. }
  4202. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['DISABLE_PHP_PROCESSING'])) $ai_db_options [AI_OPTION_GLOBAL]['DISABLE_PHP_PROCESSING'] = DEFAULT_DISABLE_PHP_PROCESSING;
  4203. return ($ai_db_options [AI_OPTION_GLOBAL]['DISABLE_PHP_PROCESSING']);
  4204. }
  4205. function get_disable_html_code () {
  4206. global $ai_db_options;
  4207. if (isset ($_GET [AI_URL_DEBUG_DISABLE_HTML_CODE]) && $_GET [AI_URL_DEBUG_DISABLE_HTML_CODE] && get_remote_debugging ()) return true;
  4208. if (isset ($_GET [AI_URL_DEBUG_DISABLE_BLOCK_INSERTIONS]) && get_remote_debugging ()) {
  4209. if ($_GET [AI_URL_DEBUG_DISABLE_BLOCK_INSERTIONS] == 'html') return true;
  4210. if (strpos ($_GET [AI_URL_DEBUG_DISABLE_BLOCK_INSERTIONS], '-') !== false) {
  4211. $blocks = explode ('-', $_GET [AI_URL_DEBUG_DISABLE_BLOCK_INSERTIONS]);
  4212. if (in_array ('html', $blocks)) return true;
  4213. }
  4214. }
  4215. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['DISABLE_HTML_CODE'])) $ai_db_options [AI_OPTION_GLOBAL]['DISABLE_HTML_CODE'] = DEFAULT_DISABLE_CSS_CODE;
  4216. return ($ai_db_options [AI_OPTION_GLOBAL]['DISABLE_HTML_CODE']);
  4217. }
  4218. function get_disable_css_code () {
  4219. global $ai_db_options;
  4220. if (isset ($_GET [AI_URL_DEBUG_DISABLE_CSS_CODE]) && $_GET [AI_URL_DEBUG_DISABLE_CSS_CODE] && get_remote_debugging ()) return true;
  4221. if (isset ($_GET [AI_URL_DEBUG_DISABLE_BLOCK_INSERTIONS]) && get_remote_debugging ()) {
  4222. if ($_GET [AI_URL_DEBUG_DISABLE_BLOCK_INSERTIONS] == 'css') return true;
  4223. if (strpos ($_GET [AI_URL_DEBUG_DISABLE_BLOCK_INSERTIONS], '-') !== false) {
  4224. $blocks = explode ('-', $_GET [AI_URL_DEBUG_DISABLE_BLOCK_INSERTIONS]);
  4225. if (in_array ('css', $blocks)) return true;
  4226. }
  4227. }
  4228. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['DISABLE_CSS_CODE'])) $ai_db_options [AI_OPTION_GLOBAL]['DISABLE_CSS_CODE'] = DEFAULT_DISABLE_CSS_CODE;
  4229. return ($ai_db_options [AI_OPTION_GLOBAL]['DISABLE_CSS_CODE']);
  4230. }
  4231. function get_disable_js_code () {
  4232. global $ai_db_options;
  4233. if (isset ($_GET [AI_URL_DEBUG_DISABLE_JS_CODE]) && $_GET [AI_URL_DEBUG_DISABLE_JS_CODE] && get_remote_debugging ()) return true;
  4234. if (isset ($_GET [AI_URL_DEBUG_DISABLE_BLOCK_INSERTIONS]) && get_remote_debugging ()) {
  4235. if ($_GET [AI_URL_DEBUG_DISABLE_BLOCK_INSERTIONS] == 'js') return true;
  4236. if (strpos ($_GET [AI_URL_DEBUG_DISABLE_BLOCK_INSERTIONS], '-') !== false) {
  4237. $blocks = explode ('-', $_GET [AI_URL_DEBUG_DISABLE_BLOCK_INSERTIONS]);
  4238. if (in_array ('js', $blocks)) return true;
  4239. }
  4240. }
  4241. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['DISABLE_JS_CODE'])) $ai_db_options [AI_OPTION_GLOBAL]['DISABLE_JS_CODE'] = DEFAULT_DISABLE_JS_CODE;
  4242. return ($ai_db_options [AI_OPTION_GLOBAL]['DISABLE_JS_CODE']);
  4243. }
  4244. function get_disable_header_code () {
  4245. global $ai_db_options;
  4246. if (isset ($_GET [AI_URL_DEBUG_DISABLE_HEADER_CODE]) && $_GET [AI_URL_DEBUG_DISABLE_HEADER_CODE] && get_remote_debugging ()) return true;
  4247. if (isset ($_GET [AI_URL_DEBUG_DISABLE_BLOCK_INSERTIONS]) && get_remote_debugging ()) {
  4248. if ($_GET [AI_URL_DEBUG_DISABLE_BLOCK_INSERTIONS] == 'h') return true;
  4249. if (strpos ($_GET [AI_URL_DEBUG_DISABLE_BLOCK_INSERTIONS], '-') !== false) {
  4250. $blocks = explode ('-', $_GET [AI_URL_DEBUG_DISABLE_BLOCK_INSERTIONS]);
  4251. if (in_array ('h', $blocks)) return true;
  4252. }
  4253. }
  4254. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['DISABLE_HEADER_CODE'])) $ai_db_options [AI_OPTION_GLOBAL]['DISABLE_HEADER_CODE'] = DEFAULT_DISABLE_HEADER_CODE;
  4255. return ($ai_db_options [AI_OPTION_GLOBAL]['DISABLE_HEADER_CODE']);
  4256. }
  4257. function get_disable_footer_code () {
  4258. global $ai_db_options;
  4259. if (isset ($_GET [AI_URL_DEBUG_DISABLE_FOOTER_CODE]) && $_GET [AI_URL_DEBUG_DISABLE_FOOTER_CODE] && get_remote_debugging ()) return true;
  4260. if (isset ($_GET [AI_URL_DEBUG_DISABLE_BLOCK_INSERTIONS]) && get_remote_debugging ()) {
  4261. if ($_GET [AI_URL_DEBUG_DISABLE_BLOCK_INSERTIONS] == 'f') return true;
  4262. if (strpos ($_GET [AI_URL_DEBUG_DISABLE_BLOCK_INSERTIONS], '-') !== false) {
  4263. $blocks = explode ('-', $_GET [AI_URL_DEBUG_DISABLE_BLOCK_INSERTIONS]);
  4264. if (in_array ('f', $blocks)) return true;
  4265. }
  4266. }
  4267. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['DISABLE_FOOTER_CODE'])) $ai_db_options [AI_OPTION_GLOBAL]['DISABLE_FOOTER_CODE'] = DEFAULT_DISABLE_FOOTER_CODE;
  4268. return ($ai_db_options [AI_OPTION_GLOBAL]['DISABLE_FOOTER_CODE']);
  4269. }
  4270. function get_blocks_sticky () {
  4271. if (!function_exists ('ai_block_list_buttons')) return false;
  4272. $current_flags = get_option (AI_FLAGS_NAME, 0);
  4273. return (($current_flags & AD_FLAGS_BLOCKS_STICKY) != 0);
  4274. }
  4275. function get_viewport_name ($viewport_number) {
  4276. global $ai_db_options;
  4277. $viewport_settins_name = 'VIEWPORT_NAME_' . $viewport_number;
  4278. if (!isset ($ai_db_options [AI_OPTION_GLOBAL][$viewport_settins_name]))
  4279. $ai_db_options [AI_OPTION_GLOBAL][$viewport_settins_name] = defined ("DEFAULT_VIEWPORT_NAME_" . $viewport_number) ? constant ("DEFAULT_VIEWPORT_NAME_" . $viewport_number) : "";
  4280. return ($ai_db_options [AI_OPTION_GLOBAL][$viewport_settins_name]);
  4281. }
  4282. function get_viewport_width ($viewport_number) {
  4283. global $ai_db_options;
  4284. $viewport_settins_name = 'VIEWPORT_WIDTH_' . $viewport_number;
  4285. if (!isset ($ai_db_options [AI_OPTION_GLOBAL][$viewport_settins_name]))
  4286. $ai_db_options [AI_OPTION_GLOBAL][$viewport_settins_name] = defined ("DEFAULT_VIEWPORT_WIDTH_" . $viewport_number) ? constant ("DEFAULT_VIEWPORT_WIDTH_" . $viewport_number) : "";
  4287. return ($ai_db_options [AI_OPTION_GLOBAL][$viewport_settins_name]);
  4288. }
  4289. function get_hook_enabled ($hook_number) {
  4290. global $ai_db_options;
  4291. $hook_settins_name = 'HOOK_ENABLED_' . $hook_number;
  4292. if (!isset ($ai_db_options [AI_OPTION_GLOBAL][$hook_settins_name])) $ai_db_options [AI_OPTION_GLOBAL][$hook_settins_name] = AI_DISABLED;
  4293. return ($ai_db_options [AI_OPTION_GLOBAL][$hook_settins_name]);
  4294. }
  4295. function get_hook_name ($hook_number) {
  4296. global $ai_db_options;
  4297. $hook_settins_name = 'HOOK_NAME_' . $hook_number;
  4298. if (!isset ($ai_db_options [AI_OPTION_GLOBAL][$hook_settins_name])) $ai_db_options [AI_OPTION_GLOBAL][$hook_settins_name] = "";
  4299. return ($ai_db_options [AI_OPTION_GLOBAL][$hook_settins_name]);
  4300. }
  4301. function get_hook_action ($hook_number) {
  4302. global $ai_db_options;
  4303. $hook_settins_name = 'HOOK_ACTION_' . $hook_number;
  4304. if (!isset ($ai_db_options [AI_OPTION_GLOBAL][$hook_settins_name])) $ai_db_options [AI_OPTION_GLOBAL][$hook_settins_name] = "";
  4305. return ($ai_db_options [AI_OPTION_GLOBAL][$hook_settins_name]);
  4306. }
  4307. function get_hook_priority ($hook_number) {
  4308. global $ai_db_options;
  4309. $hook_settins_name = 'HOOK_PRIORITY_' . $hook_number;
  4310. if (!isset ($ai_db_options [AI_OPTION_GLOBAL][$hook_settins_name])) $ai_db_options [AI_OPTION_GLOBAL][$hook_settins_name] = DEFAULT_CUSTOM_HOOK_PRIORITY;
  4311. return ($ai_db_options [AI_OPTION_GLOBAL][$hook_settins_name]);
  4312. }
  4313. function get_country_group_name ($group_number) {
  4314. global $ai_db_options;
  4315. $country_group_settins_name = 'COUNTRY_GROUP_NAME_' . $group_number;
  4316. if (!isset ($ai_db_options [AI_OPTION_GLOBAL][$country_group_settins_name])) $ai_db_options [AI_OPTION_GLOBAL][$country_group_settins_name] = DEFAULT_COUNTRY_GROUP_NAME . ' ' . $group_number;
  4317. return ($ai_db_options [AI_OPTION_GLOBAL][$country_group_settins_name]);
  4318. }
  4319. function get_group_country_list ($group_number) {
  4320. global $ai_db_options;
  4321. $group_countries_settins_name = 'GROUP_COUNTRIES_' . $group_number;
  4322. if (!isset ($ai_db_options [AI_OPTION_GLOBAL][$group_countries_settins_name])) $ai_db_options [AI_OPTION_GLOBAL][$group_countries_settins_name] = '';
  4323. return ($ai_db_options [AI_OPTION_GLOBAL][$group_countries_settins_name]);
  4324. }
  4325. function multisite_settings_page_enabled () {
  4326. global $ai_db_options_multisite;
  4327. if (is_multisite()) {
  4328. if (!isset ($ai_db_options_multisite ['MULTISITE_SETTINGS_PAGE'])) $ai_db_options_multisite ['MULTISITE_SETTINGS_PAGE'] = DEFAULT_MULTISITE_SETTINGS_PAGE;
  4329. if ($ai_db_options_multisite ['MULTISITE_SETTINGS_PAGE'] == '') $ai_db_options_multisite ['MULTISITE_SETTINGS_PAGE'] = DEFAULT_MULTISITE_SETTINGS_PAGE;
  4330. if (multisite_main_for_all_blogs ()) $ai_db_options_multisite ['MULTISITE_SETTINGS_PAGE'] = AI_DISABLED;
  4331. elseif (current_user_can ('manage_network_plugins')) $ai_db_options_multisite ['MULTISITE_SETTINGS_PAGE'] = AI_ENABLED;
  4332. return ($ai_db_options_multisite ['MULTISITE_SETTINGS_PAGE']);
  4333. }
  4334. return DEFAULT_MULTISITE_SETTINGS_PAGE;
  4335. }
  4336. function multisite_widgets_enabled () {
  4337. global $ai_db_options_multisite;
  4338. if (is_multisite()) {
  4339. if (!isset ($ai_db_options_multisite ['MULTISITE_WIDGETS'])) $ai_db_options_multisite ['MULTISITE_WIDGETS'] = DEFAULT_MULTISITE_WIDGETS;
  4340. if ($ai_db_options_multisite ['MULTISITE_WIDGETS'] == '') $ai_db_options_multisite ['MULTISITE_WIDGETS'] = DEFAULT_MULTISITE_WIDGETS;
  4341. return ($ai_db_options_multisite ['MULTISITE_WIDGETS']);
  4342. }
  4343. return DEFAULT_MULTISITE_WIDGETS;
  4344. }
  4345. function multisite_php_processing () {
  4346. global $ai_db_options_multisite;
  4347. if (is_multisite()) {
  4348. if (function_exists ('ai_filter_multisite_settings')) {
  4349. if (!isset ($ai_db_options_multisite ['MULTISITE_PHP_PROCESSING'])) $ai_db_options_multisite ['MULTISITE_PHP_PROCESSING'] = DEFAULT_MULTISITE_PHP_PROCESSING;
  4350. if ($ai_db_options_multisite ['MULTISITE_PHP_PROCESSING'] == '') $ai_db_options_multisite ['MULTISITE_PHP_PROCESSING'] = DEFAULT_MULTISITE_PHP_PROCESSING;
  4351. return ($ai_db_options_multisite ['MULTISITE_PHP_PROCESSING']);
  4352. }
  4353. return AI_ENABLED;
  4354. }
  4355. return DEFAULT_MULTISITE_PHP_PROCESSING;
  4356. }
  4357. function multisite_exceptions_enabled () {
  4358. global $ai_db_options_multisite;
  4359. if (is_multisite()) {
  4360. if (!isset ($ai_db_options_multisite ['MULTISITE_EXCEPTIONS'])) $ai_db_options_multisite ['MULTISITE_EXCEPTIONS'] = DEFAULT_MULTISITE_EXCEPTIONS;
  4361. if ($ai_db_options_multisite ['MULTISITE_EXCEPTIONS'] == '') $ai_db_options_multisite ['MULTISITE_EXCEPTIONS'] = DEFAULT_MULTISITE_EXCEPTIONS;
  4362. return ($ai_db_options_multisite ['MULTISITE_EXCEPTIONS']);
  4363. }
  4364. return DEFAULT_MULTISITE_EXCEPTIONS;
  4365. }
  4366. function multisite_main_for_all_blogs () {
  4367. global $ai_db_options_multisite;
  4368. if (is_multisite()) {
  4369. if (!isset ($ai_db_options_multisite ['MULTISITE_MAIN_FOR_ALL_BLOGS'])) $ai_db_options_multisite ['MULTISITE_MAIN_FOR_ALL_BLOGS'] = DEFAULT_MULTISITE_MAIN_FOR_ALL_BLOGS;
  4370. if ($ai_db_options_multisite ['MULTISITE_MAIN_FOR_ALL_BLOGS'] == '') $ai_db_options_multisite ['MULTISITE_MAIN_FOR_ALL_BLOGS'] = DEFAULT_MULTISITE_MAIN_FOR_ALL_BLOGS;
  4371. return ($ai_db_options_multisite ['MULTISITE_MAIN_FOR_ALL_BLOGS']);
  4372. }
  4373. return DEFAULT_MULTISITE_MAIN_FOR_ALL_BLOGS;
  4374. }
  4375. function multisite_site_admin_page () {
  4376. global $ai_db_options_multisite;
  4377. if (is_multisite()) {
  4378. if (!isset ($ai_db_options_multisite ['MULTISITE_SITE_ADMIN_PAGE'])) $ai_db_options_multisite ['MULTISITE_SITE_ADMIN_PAGE'] = DEFAULT_MULTISITE_SITE_ADMIN_PAGE;
  4379. if (multisite_main_for_all_blogs ()) $ai_db_options_multisite ['MULTISITE_SITE_ADMIN_PAGE'] = AI_DISABLED;
  4380. return ($ai_db_options_multisite ['MULTISITE_SITE_ADMIN_PAGE']);
  4381. }
  4382. return DEFAULT_MULTISITE_SITE_ADMIN_PAGE;
  4383. }
  4384. function get_adb_action ($saved_value = false) {
  4385. global $ai_db_options, $ai_wp_data;
  4386. if (!$saved_value) {
  4387. if ($ai_wp_data [AI_CODE_FOR_IFRAME]) return AI_ADB_ACTION_NONE;
  4388. switch (get_adb_no_action ()) {
  4389. case AI_ADB_NO_ACTION_LOGGED_IN:
  4390. if (($ai_wp_data [AI_WP_USER] & AI_USER_LOGGED_IN) != 0) return AI_ADB_ACTION_NONE;
  4391. break;
  4392. case AI_ADB_NO_ACTION_ADMINISTRATORS:
  4393. if (($ai_wp_data [AI_WP_USER] & AI_USER_ADMINISTRATOR) != 0) return AI_ADB_ACTION_NONE;
  4394. break;
  4395. }
  4396. if (isset ($ai_wp_data [AI_ADB_SHORTCODE_ACTION])) return ($ai_wp_data [AI_ADB_SHORTCODE_ACTION]);
  4397. }
  4398. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['ADB_ACTION'])) $ai_db_options [AI_OPTION_GLOBAL]['ADB_ACTION'] = AI_DEFAULT_ADB_ACTION;
  4399. return ($ai_db_options [AI_OPTION_GLOBAL]['ADB_ACTION']);
  4400. }
  4401. function get_adb_no_action ($saved_value = false) {
  4402. global $ai_db_options, $ai_wp_data;
  4403. if (!$saved_value) {
  4404. if ($ai_wp_data [AI_CODE_FOR_IFRAME]) return AI_ADB_NO_ACTION_NONE;
  4405. }
  4406. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['ADB_NO_ACTION'])) $ai_db_options [AI_OPTION_GLOBAL]['ADB_NO_ACTION'] = AI_DEFAULT_ADB_NO_ACTION;
  4407. return ($ai_db_options [AI_OPTION_GLOBAL]['ADB_NO_ACTION']);
  4408. }
  4409. function get_delay_action ($return_number = false) {
  4410. global $ai_db_options;
  4411. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['ADB_DELAY_ACTION'])) $ai_db_options [AI_OPTION_GLOBAL]['ADB_DELAY_ACTION'] = '';
  4412. if ($return_number) {
  4413. $value = trim ($ai_db_options [AI_OPTION_GLOBAL]['ADB_DELAY_ACTION']);
  4414. if ($value == '') $value = 0;
  4415. // if (is_numeric ($value)) return $value; else return 0;
  4416. }
  4417. return ($ai_db_options [AI_OPTION_GLOBAL]['ADB_DELAY_ACTION']);
  4418. }
  4419. function get_no_action_period ($return_number = false) {
  4420. global $ai_db_options;
  4421. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['ADB_NO_ACTION_PERIOD'])) $ai_db_options [AI_OPTION_GLOBAL]['ADB_NO_ACTION_PERIOD'] = AI_DEFAULT_ADB_NO_ACTION_PERIOD;
  4422. if ($return_number) {
  4423. $value = trim ($ai_db_options [AI_OPTION_GLOBAL]['ADB_NO_ACTION_PERIOD']);
  4424. if ($value == '') $value = 0;
  4425. if (is_numeric ($value)) return $value; else return AI_DEFAULT_ADB_NO_ACTION_PERIOD;
  4426. }
  4427. return ($ai_db_options [AI_OPTION_GLOBAL]['ADB_NO_ACTION_PERIOD']);
  4428. }
  4429. function get_adb_selectors ($decode = false) {
  4430. global $ai_db_options;
  4431. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['ADB_SELECTORS'])) $ai_db_options [AI_OPTION_GLOBAL]['ADB_SELECTORS'] = '';
  4432. if ($decode)
  4433. return (html_entity_decode ($ai_db_options [AI_OPTION_GLOBAL]['ADB_SELECTORS'])); else
  4434. return ($ai_db_options [AI_OPTION_GLOBAL]['ADB_SELECTORS']);
  4435. }
  4436. function get_redirection_page ($return_number = false) {
  4437. global $ai_db_options;
  4438. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['ADB_REDIRECTION_PAGE'])) $ai_db_options [AI_OPTION_GLOBAL]['ADB_REDIRECTION_PAGE'] = AI_DEFAULT_ADB_REDIRECTION_PAGE;
  4439. if ($return_number) {
  4440. $value = trim ($ai_db_options [AI_OPTION_GLOBAL]['ADB_REDIRECTION_PAGE']);
  4441. if ($value == '') $value = 0;
  4442. if (is_numeric ($value)) return $value; else return AI_DEFAULT_ADB_REDIRECTION_PAGE;
  4443. }
  4444. return ($ai_db_options [AI_OPTION_GLOBAL]['ADB_REDIRECTION_PAGE']);
  4445. }
  4446. function get_custom_redirection_url () {
  4447. global $ai_db_options;
  4448. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['ADB_CUSTOM_REDIRECTION_URL'])) $ai_db_options [AI_OPTION_GLOBAL]['ADB_CUSTOM_REDIRECTION_URL'] = '';
  4449. return ($ai_db_options [AI_OPTION_GLOBAL]['ADB_CUSTOM_REDIRECTION_URL']);
  4450. }
  4451. function get_message_css () {
  4452. global $ai_db_options;
  4453. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['ADB_MESSAGE_CSS'])) $ai_db_options [AI_OPTION_GLOBAL]['ADB_MESSAGE_CSS'] = AI_DEFAULT_ADB_MESSAGE_CSS;
  4454. return ($ai_db_options [AI_OPTION_GLOBAL]['ADB_MESSAGE_CSS']);
  4455. }
  4456. function get_overlay_css () {
  4457. global $ai_db_options;
  4458. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['ADB_OVERLAY_CSS'])) $ai_db_options [AI_OPTION_GLOBAL]['ADB_OVERLAY_CSS'] = AI_DEFAULT_ADB_OVERLAY_CSS;
  4459. return ($ai_db_options [AI_OPTION_GLOBAL]['ADB_OVERLAY_CSS']);
  4460. }
  4461. function get_undismissible_message ($saved_value = false) {
  4462. global $ai_db_options, $ai_wp_data;
  4463. if (!$saved_value) {
  4464. switch (get_no_undismissible_message ()) {
  4465. case AI_ADB_NO_ACTION_LOGGED_IN:
  4466. if (($ai_wp_data [AI_WP_USER] & AI_USER_LOGGED_IN) != 0) return AI_DISABLED;
  4467. break;
  4468. case AI_ADB_NO_ACTION_ADMINISTRATORS:
  4469. if (($ai_wp_data [AI_WP_USER] & AI_USER_ADMINISTRATOR) != 0) return AI_DISABLED;
  4470. break;
  4471. }
  4472. }
  4473. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['ADB_UNDISMISSIBLE_MESSAGE'])) $ai_db_options [AI_OPTION_GLOBAL]['ADB_UNDISMISSIBLE_MESSAGE'] = AI_DEFAULT_ADB_UNDISMISSIBLE_MESSAGE;
  4474. return ($ai_db_options [AI_OPTION_GLOBAL]['ADB_UNDISMISSIBLE_MESSAGE']);
  4475. }
  4476. function get_no_undismissible_message () {
  4477. global $ai_db_options;
  4478. if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['ADB_NO_UNDISMISSIBLE_MESSAGE'])) $ai_db_options [AI_OPTION_GLOBAL]['ADB_NO_UNDISMISSIBLE_MESSAGE'] = AI_DEFAULT_ADB_NO_UNDISMISSIBLE_MESSAGE;
  4479. return ($ai_db_options [AI_OPTION_GLOBAL]['ADB_NO_UNDISMISSIBLE_MESSAGE']);
  4480. }
  4481. function filter_html_class ($str){
  4482. $str = str_replace (array ("\\\""), array ("\""), $str);
  4483. $str = sanitize_html_class ($str);
  4484. return $str;
  4485. }
  4486. function filter_string ($str){
  4487. $str = str_replace (array ("\\\""), array ("\""), $str);
  4488. $str = str_replace (array ("\"", "<", ">"), "", $str);
  4489. $str = trim (esc_html ($str));
  4490. return $str;
  4491. }
  4492. function filter_string_tags ($str){
  4493. $str = str_replace (array ("\\\""), array ("\""), $str);
  4494. $str = str_replace (array ("\""), "", $str);
  4495. $str = str_replace (array ("<", ">"), array ("&lt;", "&gt;"), $str);
  4496. $str = trim (esc_html ($str));
  4497. return $str;
  4498. }
  4499. function filter_option ($option, $value, $delete_escaped_backslashes = true){
  4500. if ($delete_escaped_backslashes)
  4501. $value = str_replace (array ("\\\""), array ("\""), $value);
  4502. if ($option == 'ADB_SELECTORS' ||
  4503. $option == AI_OPTION_HTML_SELECTOR ||
  4504. $option == AI_OPTION_ANIMATION_TRIGGER_VALUE ||
  4505. $option == 'MAIN_CONTENT_ELEMENT') {
  4506. $value = str_replace (array ("\\", "/", "?", "\"", "'", "'", '"'), "", $value);
  4507. $value = esc_html ($value);
  4508. }
  4509. elseif ($option == AI_OPTION_DOMAIN_LIST ||
  4510. $option == 'NO_PARAGRAPH_COUNTING_INSIDE' ||
  4511. $option == AI_OPTION_BACKGROUND_COLOR ||
  4512. $option == AI_OPTION_PARAGRAPH_TAGS ||
  4513. $option == AI_OPTION_COUNT_INSIDE_ELEMENTS ||
  4514. $option == AI_OPTION_IP_ADDRESS_LIST ||
  4515. $option == AI_OPTION_COUNTRY_LIST) {
  4516. $value = str_replace (array ("\\", "/", "?", "\"", "'", "<", ">", "[", "]", "'", '"'), "", $value);
  4517. $value = esc_html ($value);
  4518. }
  4519. elseif (
  4520. $option == AI_OPTION_PARAGRAPH_TEXT ||
  4521. $option == AI_OPTION_COUNT_INSIDE_ELEMENTS_TEXT ||
  4522. $option == AI_OPTION_AVOID_TEXT_ABOVE ||
  4523. $option == AI_OPTION_AVOID_TEXT_BELOW ||
  4524. $option == AI_OPTION_CLIENT_LIST
  4525. ) {
  4526. $value = esc_html ($value);
  4527. }
  4528. elseif ($option == AI_OPTION_BLOCK_NAME ||
  4529. $option == AI_OPTION_GENERAL_TAG ||
  4530. $option == AI_OPTION_DOMAIN_LIST ||
  4531. $option == AI_OPTION_CATEGORY_LIST ||
  4532. $option == AI_OPTION_TAG_LIST ||
  4533. $option == AI_OPTION_TAXONOMY_LIST ||
  4534. $option == AI_OPTION_ID_LIST ||
  4535. $option == AI_OPTION_URL_LIST ||
  4536. $option == AI_OPTION_PARAGRAPH_NUMBER ||
  4537. $option == AI_OPTION_MIN_PARAGRAPHS ||
  4538. $option == AI_OPTION_MAX_PARAGRAPHS ||
  4539. $option == AI_OPTION_SKIP_FIRST_PARAGRAPHS ||
  4540. $option == AI_OPTION_SKIP_LAST_PARAGRAPHS ||
  4541. $option == AI_OPTION_MIN_WORDS_ABOVE ||
  4542. $option == AI_OPTION_AVOID_PARAGRAPHS_ABOVE ||
  4543. $option == AI_OPTION_AVOID_PARAGRAPHS_BELOW ||
  4544. $option == AI_OPTION_AVOID_TRY_LIMIT ||
  4545. $option == AI_OPTION_MIN_WORDS ||
  4546. $option == AI_OPTION_MAX_WORDS ||
  4547. $option == AI_OPTION_MIN_PARAGRAPH_WORDS ||
  4548. $option == AI_OPTION_MAX_PARAGRAPH_WORDS ||
  4549. $option == AI_OPTION_MAXIMUM_INSERTIONS ||
  4550. $option == AI_OPTION_AFTER_DAYS ||
  4551. $option == AI_OPTION_START_DATE ||
  4552. $option == AI_OPTION_END_DATE ||
  4553. $option == AI_OPTION_FALLBACK ||
  4554. $option == AI_OPTION_EXCERPT_NUMBER ||
  4555. $option == AI_OPTION_WAIT_FOR_DELAY ||
  4556. $option == AI_OPTION_HORIZONTAL_MARGIN ||
  4557. $option == AI_OPTION_VERTICAL_MARGIN ||
  4558. $option == AI_OPTION_ANIMATION_TRIGGER_OFFSET ||
  4559. $option == AI_OPTION_ANIMATION_TRIGGER_DELAY ||
  4560. $option == AI_OPTION_IFRAME_WIDTH ||
  4561. $option == AI_OPTION_IFRAME_HEIGHT ||
  4562. $option == AI_OPTION_AUTO_CLOSE_TIME ||
  4563. $option == AI_OPTION_STAY_CLOSED_TIME ||
  4564. $option == AI_OPTION_DELAY_SHOWING ||
  4565. $option == AI_OPTION_SHOW_EVERY ||
  4566. $option == AI_OPTION_VISITOR_MAX_IMPRESSIONS ||
  4567. $option == AI_OPTION_VISITOR_LIMIT_IMPRESSIONS_PER_TIME_PERIOD ||
  4568. $option == AI_OPTION_VISITOR_LIMIT_IMPRESSIONS_TIME_PERIOD ||
  4569. $option == AI_OPTION_MAX_IMPRESSIONS ||
  4570. $option == AI_OPTION_LIMIT_IMPRESSIONS_PER_TIME_PERIOD ||
  4571. $option == AI_OPTION_LIMIT_IMPRESSIONS_TIME_PERIOD ||
  4572. $option == AI_OPTION_VISITOR_MAX_CLICKS ||
  4573. $option == AI_OPTION_VISITOR_LIMIT_CLICKS_PER_TIME_PERIOD ||
  4574. $option == AI_OPTION_VISITOR_LIMIT_CLICKS_TIME_PERIOD ||
  4575. $option == AI_OPTION_MAX_CLICKS ||
  4576. $option == AI_OPTION_LIMIT_CLICKS_PER_TIME_PERIOD ||
  4577. $option == AI_OPTION_LIMIT_CLICKS_TIME_PERIOD ||
  4578. $option == AI_OPTION_BACKGROUND_IMAGE ||
  4579. $option == 'CLICK_FRAUD_PROTECTION_TIME' ||
  4580. $option == 'ADB_DELAY_ACTION' ||
  4581. $option == 'ADB_NO_ACTION_PERIOD' ||
  4582. $option == 'ADB_REDIRECTION_PAGE' ||
  4583. $option == 'ADB_CUSTOM_REDIRECTION_URL' ||
  4584. $option == AI_OPTION_CUSTOM_CSS ||
  4585. $option == 'HOOK_PRIORITY' ||
  4586. $option == 'ADB_OVERLAY_CSS' ||
  4587. $option == 'ADB_MESSAGE_CSS') {
  4588. $value = str_replace (array ("\"", "<", ">", "[", "]"), "", $value);
  4589. $value = esc_html ($value);
  4590. }
  4591. elseif ($option == AI_OPTION_URL_PARAMETER_LIST) {
  4592. $value = str_replace (array ("\"", "<", ">"), "", $value);
  4593. $value = esc_html ($value);
  4594. }
  4595. elseif ($option == 'AD_LABEL' ||
  4596. $option == 'REPORT_HEADER_TITLE' ||
  4597. $option == 'REPORT_HEADER_DESCRIPTION' ||
  4598. $option == 'EXTERNAL_TRACKING_CATEGORY' ||
  4599. $option == 'EXTERNAL_TRACKING_ACTION' ||
  4600. $option == 'EXTERNAL_TRACKING_LABEL' ||
  4601. $option == 'REPORT_FOOTER') {
  4602. $value = str_replace (array ("\\", "?"), "", $value);
  4603. $value = esc_html ($value);
  4604. }
  4605. elseif (
  4606. $option == 'REPORT_HEADER_IMAGE') {
  4607. $value = str_replace (home_url () . '/', '', $value);
  4608. $value = str_replace (array ("http://", "https://", ":". "\"", "<", ">", "[", "]"), "", $value);
  4609. $value = esc_html ($value);
  4610. }
  4611. elseif (
  4612. $option == 'MAXMIND_LICENSE_KEY' ||
  4613. $option == 'GEO_DB'
  4614. ) {
  4615. $value = str_replace (array (":". "\"", "<", ">", "[", "]"), "", $value);
  4616. }
  4617. return $value;
  4618. }
  4619. function filter_option_hf ($option, $value){
  4620. $value = str_replace (array ("\\\""), array ("\""), $value);
  4621. // if ($option == AI_OPTION_CODE ) {
  4622. // } elseif ($option == AI_OPTION_ENABLE_MANUAL) {
  4623. // } elseif ($option == AI_OPTION_PROCESS_PHP) {
  4624. // } elseif ($option == AI_OPTION_ENABLE_404) {
  4625. // } elseif ($option == AI_OPTION_DETECT_SERVER_SIDE) {
  4626. // } elseif ($option == AI_OPTION_DISPLAY_FOR_DEVICES) {
  4627. // }
  4628. return $value;
  4629. }
  4630. function ai_ajax () {
  4631. global $ai_wp_data;
  4632. // check_ajax_referer ("adinserter_data", "ai_check");
  4633. // check_admin_referer ("adinserter_data", "ai_check");
  4634. if (isset ($_POST ["adsense-ad-units"])) {
  4635. if (defined ('AI_ADSENSE_API')) {
  4636. adsense_ad_name ($_POST ["adsense-ad-units"]);
  4637. }
  4638. }
  4639. elseif (isset ($_GET ["block"])) {
  4640. $block = sanitize_text_field ($_GET ["block"]);
  4641. if (is_numeric ($block) && $block >= 1 && $block <= 96) {
  4642. global $block_object;
  4643. $block = $block_object [$block];
  4644. if (isset ($_GET ["cookie_check"]) && $_GET ["cookie_check"] == 1) {
  4645. $block->client_side_cookie_check = true;
  4646. }
  4647. if (isset ($_GET ["hide-debug-labels"]) && $_GET ["hide-debug-labels"] == 1) {
  4648. $block->hide_debug_labels = true;
  4649. }
  4650. if ($block->get_iframe ())
  4651. echo $block->get_iframe_page ();
  4652. }
  4653. }
  4654. elseif (isset ($_GET ["ads-txt"])) {
  4655. $ads_txt = get_option (AI_ADS_TXT_NAME);
  4656. if ($ads_txt === false) {
  4657. wp_die ('Page not found', 404);
  4658. }
  4659. header ('Content-Type: text/plain');
  4660. echo esc_html ($ads_txt);
  4661. wp_die ();
  4662. }
  4663. elseif (function_exists ('ai_ajax_processing_2')) {
  4664. ai_ajax_processing_2 ();
  4665. }
  4666. wp_die ();
  4667. }
  4668. function ai_ajax_backend () {
  4669. global $preview_name, $preview_alignment, $preview_css;
  4670. // check_ajax_referer ("adinserter_data", "ai_check");
  4671. check_admin_referer ("adinserter_data", "ai_check");
  4672. if (is_multisite() && !is_main_site () && !multisite_settings_page_enabled ()) {
  4673. wp_die ();
  4674. }
  4675. if (!current_user_can ('manage_options')) {
  4676. wp_die ();
  4677. }
  4678. if (isset ($_POST ["preview"])) {
  4679. $block = urldecode ($_POST ["preview"]);
  4680. if (is_numeric ($block) && $block >= 1 && $block <= 96) {
  4681. require_once AD_INSERTER_PLUGIN_DIR.'includes/preview.php';
  4682. $preview_parameters = array ();
  4683. if (isset ($_POST ['name'])) $preview_parameters ['name'] = base64_decode ($_POST ['name']);
  4684. if (isset ($_POST ['code'])) $preview_parameters ['code'] = base64_decode ($_POST ['code']);
  4685. if (isset ($_POST ['alignment'])) $preview_parameters ['alignment'] = base64_decode ($_POST ['alignment']);
  4686. if (isset ($_POST ['horizontal'])) $preview_parameters ['horizontal'] = base64_decode ($_POST ['horizontal']);
  4687. if (isset ($_POST ['vertical'])) $preview_parameters ['vertical'] = base64_decode ($_POST ['vertical']);
  4688. if (isset ($_POST ['horizontal_margin'])) $preview_parameters ['horizontal_margin'] = base64_decode ($_POST ['horizontal_margin']);
  4689. if (isset ($_POST ['vertical_margin'])) $preview_parameters ['vertical_margin'] = base64_decode ($_POST ['vertical_margin']);
  4690. if (isset ($_POST ['animation'])) $preview_parameters ['animation'] = base64_decode ($_POST ['animation']);
  4691. if (isset ($_POST ['alignment_css'])) $preview_parameters ['alignment_css'] = base64_decode ($_POST ['alignment_css']);
  4692. if (isset ($_POST ['custom_css'])) $preview_parameters ['custom_css'] = base64_decode ($_POST ['custom_css']);
  4693. if (isset ($_POST ['php'])) $preview_parameters ['php'] = $_POST ['php'];
  4694. if (isset ($_POST ['close'])) $preview_parameters ['close'] = $_POST ['close'];
  4695. if (isset ($_POST ['background'])) $preview_parameters ['background'] = $_POST ['background'];
  4696. if (isset ($_POST ['body_background'])) $preview_parameters ['body_background'] = $_POST ['body_background'];
  4697. if (isset ($_POST ['background_image'])) $preview_parameters ['background_image'] = base64_decode ($_POST ['background_image']);
  4698. if (isset ($_POST ['background_color'])) $preview_parameters ['background_color'] = base64_decode ($_POST ['background_color']);
  4699. if (isset ($_POST ['background_size'])) $preview_parameters ['background_size'] = base64_decode ($_POST ['background_size']);
  4700. if (isset ($_POST ['background_repeat'])) $preview_parameters ['background_repeat'] = base64_decode ($_POST ['background_repeat']);
  4701. if (isset ($_POST ['label'])) $preview_parameters ['label'] = $_POST ['label'];
  4702. if (isset ($_POST ['read_only'])) $preview_parameters ['read_only'] = $_POST ['read_only'];
  4703. if (isset ($_POST ['iframe'])) $preview_parameters ['iframe'] = $_POST ['iframe'];
  4704. if (isset ($_POST ['check'])) $preview_parameters ['check'] = $_POST ['check'];
  4705. if (isset ($_POST ['count'])) $preview_parameters ['count'] = $_POST ['count'];
  4706. if (isset ($_POST ['rotate'])) $preview_parameters ['rotate'] = $_POST ['rotate'];
  4707. if (isset ($_POST ['viewport'])) $preview_parameters ['viewport'] = $_POST ['viewport'];
  4708. generate_code_preview (
  4709. $block,
  4710. $preview_parameters
  4711. );
  4712. }
  4713. elseif ($block == 'adb') {
  4714. require_once AD_INSERTER_PLUGIN_DIR.'includes/preview-adb.php';
  4715. $process_php = isset ($_POST ["php"]) && $_POST ["php"] == 1;
  4716. generate_code_preview_adb (base64_decode ($_POST ["code"]), $process_php);
  4717. }
  4718. elseif ($block == 'adsense') {
  4719. if (defined ('AI_ADSENSE_API')) {
  4720. require_once AD_INSERTER_PLUGIN_DIR.'includes/preview.php';
  4721. require_once AD_INSERTER_PLUGIN_DIR.'includes/adsense-api.php';
  4722. if (defined ('AI_ADSENSE_AUTHORIZATION_CODE')) {
  4723. $adsense = new adsense_api();
  4724. $adsense_code = $adsense->getAdCode (base64_decode ($_POST ["slot_id"]));
  4725. $adsense_error = $adsense->getError ();
  4726. $preview_parameters = array (
  4727. "name" => isset ($_POST ["name"]) ? base64_decode ($_POST ["name"]) : 'ADSENSE CODE',
  4728. "alignment" => '',
  4729. "horizontal" => '',
  4730. "vertical" => '',
  4731. "alignment_css" => '',
  4732. "custom_css" => '',
  4733. "code" => $adsense_error == '' ? $adsense_code : '<div style="color: red;">'.$adsense_error.'</div>',
  4734. "php" => false,
  4735. "label" => false,
  4736. "close" => AI_CLOSE_NONE,
  4737. "read_only" => true,
  4738. );
  4739. generate_code_preview (
  4740. 0, // Default settings
  4741. $preview_parameters
  4742. );
  4743. }
  4744. }
  4745. }
  4746. }
  4747. elseif (isset ($_POST ["edit"])) {
  4748. if (is_numeric ($_POST ["edit"]) && $_POST ["edit"] >= 1 && $_POST ["edit"] <= 96) {
  4749. require_once AD_INSERTER_PLUGIN_DIR.'includes/editor.php';
  4750. $process_php = isset ($_POST ["php"]) && $_POST ["php"] == 1;
  4751. generate_code_editor ($_POST ["edit"], base64_decode ($_POST ["code"]), $process_php);
  4752. }
  4753. }
  4754. if (isset ($_POST ["placeholder"])) {
  4755. $block = urldecode ($_POST ["block"]);
  4756. if (is_numeric ($block) && $block >= 1 && $block <= 96) {
  4757. require_once AD_INSERTER_PLUGIN_DIR.'includes/placeholders.php';
  4758. generate_placeholder_editor (str_replace (array ('"', "\\'"), array ('&quot', '&#039'), urldecode ($_POST ["placeholder"])), $block);
  4759. }
  4760. }
  4761. elseif (isset ($_POST ["generate-code"])) {
  4762. $code_generator = new ai_code_generator ();
  4763. echo json_encode ($code_generator->generate ($_POST));
  4764. }
  4765. elseif (isset ($_POST ["import-code"])) {
  4766. $code_generator = new ai_code_generator ();
  4767. echo json_encode ($code_generator->import (base64_decode ($_POST ["import-code"])));
  4768. }
  4769. elseif (isset ($_POST ["import-rotation-code"])) {
  4770. $code_generator = new ai_code_generator ();
  4771. echo json_encode ($code_generator->import_rotation (base64_decode ($_POST ["import-rotation-code"])));
  4772. }
  4773. elseif (isset ($_POST ["generate-rotation-code"])) {
  4774. $code_generator = new ai_code_generator ();
  4775. echo json_encode ($code_generator->generate_rotation (json_decode (base64_decode ($_POST ['generate-rotation-code']), true)));
  4776. }
  4777. elseif (isset ($_GET ["image"])) {
  4778. $filename = sanitize_file_name ($_GET ["image"]);
  4779. header ("Content-Type: image/png");
  4780. header ("Content-Length: " . filesize (AD_INSERTER_PLUGIN_DIR.'images/'.$filename));
  4781. readfile (AD_INSERTER_PLUGIN_DIR.'images/'.$filename);
  4782. }
  4783. elseif (isset ($_GET ["css"])) {
  4784. $filename = sanitize_file_name ($_GET ["css"]);
  4785. header ("Content-Type: text/css");
  4786. header ("Content-Length: " . filesize (AD_INSERTER_PLUGIN_DIR.'css/'.$filename));
  4787. readfile (AD_INSERTER_PLUGIN_DIR.'css/'.$filename);
  4788. }
  4789. elseif (isset ($_GET ["js"])) {
  4790. $filename = sanitize_file_name ($_GET ["js"]);
  4791. header ("Content-Type: application/javascript");
  4792. header ("Content-Length: " . filesize (AD_INSERTER_PLUGIN_DIR.'js/'.$filename));
  4793. readfile (AD_INSERTER_PLUGIN_DIR.'js/'.$filename);
  4794. }
  4795. elseif (isset ($_GET ["rating"])) {
  4796. $cache_time = $_GET ["rating"] == 'update' ? 0 * 60 : AI_TRANSIENT_RATING_EXPIRATION;
  4797. if (!get_transient (AI_TRANSIENT_RATING) || !($transient_timeout = get_option ('_transient_timeout_' . AI_TRANSIENT_RATING)) || AI_TRANSIENT_RATING_EXPIRATION - ($transient_timeout - time ()) > $cache_time) {
  4798. $args = (object) array ('slug' => 'ad-inserter');
  4799. $request = array ('action' => 'plugin_information', 'timeout' => 5, 'request' => serialize ($args));
  4800. $url = 'http://api.wordpress.org/plugins/info/1.0/';
  4801. $response = wp_remote_post ($url, array ('body' => $request));
  4802. $plugin_info = @unserialize ($response ['body']);
  4803. if (isset ($plugin_info->ratings)) {
  4804. $total_rating = 0;
  4805. $total_count = 0;
  4806. foreach ($plugin_info->ratings as $rating => $count) {
  4807. $total_rating += $rating * $count;
  4808. $total_count += $count;
  4809. }
  4810. $rating = number_format ($total_rating / $total_count, 4);
  4811. set_transient (AI_TRANSIENT_RATING, $rating, AI_TRANSIENT_RATING_EXPIRATION);
  4812. }
  4813. }
  4814. if ($rating = get_transient (AI_TRANSIENT_RATING)) {
  4815. if ($rating > 1 && $rating <= 5) echo $rating;
  4816. }
  4817. }
  4818. elseif (isset ($_POST ["notice"])) {
  4819. update_option ('ai-notice-' . $_POST ["notice"], $_POST ["click"]);
  4820. }
  4821. elseif (isset ($_POST ["notice-check"])) {
  4822. echo $_POST ["notice-check"];
  4823. }
  4824. elseif (isset ($_GET ["list"])) {
  4825. $search_text = trim ($_GET ["list"]);
  4826. $show_all_blocks = isset ($_GET ["all"]) && $_GET ["all"];
  4827. $start = trim ($_GET ["start"]);
  4828. $end = trim ($_GET ["end"]);
  4829. $active = trim ($_GET ["active"]);
  4830. code_block_list ($start, $end, $search_text, $show_all_blocks, $active);
  4831. }
  4832. elseif (isset ($_GET ["adsense-list"])) {
  4833. if (defined ('AI_ADSENSE_API')) {
  4834. adsense_list ();
  4835. }
  4836. }
  4837. elseif (isset ($_GET ["adsense-code