wpdb = $wpdb; $this->table_name = $afbt_table_name = $this->wpdb->prefix . 'affiliate_boost'; $this->table_name2 = $afbt_table_name2 = $this->wpdb->prefix . 'affiliate_boost_website'; $this->posts = $afbt_table_name3 = $this->wpdb->prefix . 'posts'; } public function afbt_AddAdminPage() { $abOptionsPage = add_submenu_page('options-general.php', 'Affiliate Booster', 'Affiliate Booster', 'manage_options', 'affiliate-boost-options', array(&$this, 'afbtGetOptionsScreen')); $abStylePage = add_submenu_page('affiliate-boost-options', 'Style Editor', 'Style', 'manage_options', 'affiliate-boost-style', array(&$this, 'afbtGetOptionsScreen')); } public function afbtGetOptionsScreen() { // Settings navigation tabs if (isset($_GET['tab']) || !isset($_GET['tab'])) { $active_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'affiliate_retrieval_section'; } $afbtRetrieveLink = admin_url() . 'admin.php?page=affiliate-boost-options&tab=affiliate_retrieval_section'; $afbtTestsLink = admin_url() . 'admin.php?page=affiliate-boost-options&tab=affiliate_style'; echo ''; // Settings form if (!isset($_GET['tab']) || $_GET['tab'] == 'affiliate_retrieval_section') { ?>

Link Setting Options

'; wp_nonce_field("update-options"); ?>

'; } } function array_intersect_fixed($array1, $array2) { $result = array(); foreach ($array1 as $val) { if (!in_array($val['keywords'], $array2)) { $results[] = $val; } } return $results; } /* * check the keywords in contents */ function afbt_replace_for_keywords($content) { global $wp; $current_page = home_url($wp->request); $page_title = get_the_title(); $font_size = get_option('affiliate_boost_setting')['font-size']; $font_color = get_option('affiliate_boost_setting')['font-color']; if ($font_color) { $style_color = "color:" . $font_color . ";"; } if (strpos($font_size, 'px') !== false) { $style_color .= "font-size:" . $font_size . ";"; } else { if ($font_size) { $style_color .= "font-size:" . $font_size . "px;"; } } $this->style = $style = "style='" . $style_color . "'"; $qtot = $this->wpdb->get_results("SELECT keywords,affiliate_link FROM " . $this->table_name2 . " INNER JOIN " . $this->table_name . " ON parent_id = w_id WHERE website = '" . $page_title . "'"); $this->linkarray = $arrqtotay = json_decode(json_encode($qtot), true); if ($arrqtotay) { foreach ($arrqtotay as $getRecords) { if (strpos($getRecords['keywords'], ',') !== false) { $explode_keywords = explode(",", $getRecords['keywords']); foreach ($explode_keywords as $keywords) { if (strpos($content, $keywords) !== false) { $content = preg_replace("/\b" . $keywords . "\b/", '' . esc_html($keywords) . '', $content); } } } else { if (strpos($content, $getRecords['keywords']) !== false) { $content = preg_replace("/\b" . $getRecords['keywords'] . "\b/", '' . esc_html($getRecords['keywords']) . '', $content); } } } libxml_use_internal_errors(true); $dom = new DOMDocument; if (empty(trim($content))) { return $content; } $dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8')); $array_link = array(); foreach ($dom->getElementsByTagName('a') as $node) { if ($node->getAttribute('class') == 'afbt_link') { $array_link[] = trim($node->nodeValue); } } $unique_arr = array_map("unserialize", array_unique(array_map("serialize", $array_link))); $array_end = $this->array_intersect_fixed($arrqtotay, $unique_arr); $this->json_arr = json_encode($array_end); return $content; } else { return $content; } } function afbt_frontscript() { ?>