admin_url( 'admin-ajax.php' ))); wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'affinitomics_ajax_script' ); } function custom_restore_function($post_ID) { $the_key = get_option('af_key'); $af_cloud_url = get_option('af_cloud_url', ''); $url = get_permalink($post_ID); $request = curl_request($af_cloud_url . "/api/restore_resource?user_key=" . $the_key . '&uid=' . $post_ID . '&url=' . $url); } add_action('untrash_post', 'custom_restore_function'); /* Page Types to Apply Affinitomics */ $screens = array(); // if (get_option('af_post_type_affinitomics','true') == 'true') $screens[] = 'archetype'; if (get_option('af_post_type_posts','false') == 'true') $screens[] = 'post'; if (get_option('af_post_type_pages','false') == 'true') $screens[] = 'page'; if (get_option('af_post_type_products','false') == 'true') $screens[] = 'product'; if (get_option('af_post_type_projects','false') == 'true') $screens[] = 'project'; if (get_option('af_post_type_listings','false') == 'true') $screens[] = 'listing'; add_action('admin_menu', 'remove_extra_submenu_items'); function remove_extra_submenu_items() { global $submenu; unset($submenu["edit.php?post_type=archetype"][10]); unset($submenu["edit.php?post_type=archetype"][5]); } function af_verify_key(){ $the_key = get_option('af_key'); $af_cloud_url = get_option('af_cloud_url', ''); if (!isset($the_key) || $the_key == ""){ $request = curl_request($af_cloud_url . "/api/anon_key"); $response = json_decode($request, true); update_option( 'af_key' , $response['data']['anon_key'] ); } } function af_check_for_errors(){ $the_key = get_option('af_key'); $af_cloud_url = get_option('af_cloud_url', ''); $request = curl_request($af_cloud_url . "/check_for_errors?user_key=" . $the_key); $response = json_decode($request, true); update_option( 'af_errors' , $response['data']['af_errors'] ); update_option( 'af_error_code' , $response['data']['af_error_code'] ); } function af_verify_provider(){ update_option( 'af_cloud_url' , 'www.affinitomics.com' ); } /* Save Custom DATA */ function afpost_save_postdata() { af_verify_key(); af_verify_provider(); $post_ID = get_the_id(); $post_status = get_post_status($post_ID); // Collect descriptor terms from the post $these_descriptors = wp_get_post_terms( $post_ID, "descriptor" ); $descriptor_terms = array(); foreach ($these_descriptors as $descriptor) { array_push($descriptor_terms, $descriptor->name); } // Collect draw terms from the post $these_draws = wp_get_post_terms( $post_ID, "draw" ); $draw_terms = array(); foreach ($these_draws as $draw) { array_push($draw_terms, $draw->name); } // Collect distance terms from the post $these_distances = wp_get_post_terms( $post_ID, "distance" ); $distance_terms = array(); foreach ($these_distances as $distance) { array_push($distance_terms, $distance->name); } // implode the data $afpost_descriptors = implode(",", $descriptor_terms); $afpost_draw = implode(",", $draw_terms); $afpost_distance = implode(",", $distance_terms); // Save Meta DATA add_post_meta($post_ID, '_afpost_descriptors', $afpost_descriptors, true) or update_post_meta($post_ID, '_afpost_descriptors', $afpost_descriptors); add_post_meta($post_ID, '_afpost_draw', $afpost_draw, true) or update_post_meta($post_ID, '_afpost_draw', $afpost_draw); add_post_meta($post_ID, '_afpost_distance', $afpost_distance, true) or update_post_meta($post_ID, '_afpost_distance', $afpost_distance); // Affinitomic ID $afid = get_post_meta($post_ID, 'afid', true); // Categories String $cat_string = ''; // Save Data To Prefrent Cloud global $af_flag; if ($af_flag == 0) { $cat_string = ''; $categories = get_the_category($id); if ($categories) { $cats = array(); foreach($categories as $cat) { $cats[] = $cat->term_id; } $cat_string = implode(",", $cats); } $affinitomics = array( 'url' => get_permalink($post_ID), 'title' => get_the_title($post_ID), 'descriptors' => $afpost_descriptors, 'draws' => $afpost_draw, 'distances' => $afpost_distance, 'key' => get_option('af_key'), 'uid' => $post_ID, 'category' => $cat_string, 'status' => $post_status ); if ($afid) $affinitomics['afid'] = $afid; $af_cloudify_url = get_option('af_cloud_url') . '/api/affinitomics/cloudify/' . get_option('af_key') . '/'; $request = curl_request($af_cloudify_url, $affinitomics); $af = json_decode($request, true); if (isset($af['data']['objectId'])) { update_post_meta($post_ID, 'afid', $af['data']['objectId']); } } $af_flag = 1; } /* ---------------------------------------------------------------------- CUSTOM TAXONOMY ---------------------------------------------------------------------- */ // Register Custom Taxonomy Descriptor function descriptor_taxonomy() { $labels = array( 'name' => _x( 'Descriptors', 'Taxonomy General Name', 'text_domain' ), 'singular_name' => _x( 'Descriptor', 'Taxonomy Singular Name', 'text_domain' ), 'menu_name' => __( 'Descriptor', 'text_domain' ), 'all_items' => __( 'All Descriptors', 'text_domain' ), 'parent_item' => __( 'Parent Descriptor', 'text_domain' ), 'parent_item_colon' => __( 'Parent Descriptor:', 'text_domain' ), 'new_item_name' => __( 'New Descriptor', 'text_domain' ), 'add_new_item' => __( 'Add New Descriptor', 'text_domain' ), 'edit_item' => __( 'Edit Descriptor', 'text_domain' ), 'update_item' => __( 'Update Descriptor', 'text_domain' ), 'separate_items_with_commas' => __( 'Descriptors are similar to Categories in Wordpress. Separate each Descriptor with commas. e.g. Summer Activities, Hobbies', 'text_domain' ), 'search_items' => __( 'Search descriptors', 'affinitomics' ), 'add_or_remove_items' => __( 'Add or remove descriptors', 'text_domain' ), 'choose_from_most_used' => __( 'Choose from the most used Descriptors', 'text_domain' ), ); $args = array( 'labels' => $labels, 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_admin_column' => true, 'show_in_nav_menus' => true, 'show_tagcloud' => true, ); global $screens; register_taxonomy( 'descriptor', $screens, $args ); } // Hook into the 'init' action add_action( 'init', 'descriptor_taxonomy', 0 ); // Register Custom Taxonomy Draw function draw_taxonomy() { $labels = array( 'name' => _x( 'Positive Relationships (Draws)', 'Taxonomy General Name', 'text_domain' ), 'singular_name' => _x( 'Draw', 'Taxonomy Singular Name', 'text_domain' ), 'menu_name' => __( 'Draw', 'text_domain' ), 'all_items' => __( 'All Draws', 'text_domain' ), 'parent_item' => __( 'Parent Draw', 'text_domain' ), 'parent_item_colon' => __( 'Parent Draw:', 'text_domain' ), 'new_item_name' => __( 'New Draw', 'text_domain' ), 'add_new_item' => __( 'Add New Draw', 'text_domain' ), 'edit_item' => __( 'Edit Draw', 'text_domain' ), 'update_item' => __( 'Update Draw', 'text_domain' ), 'separate_items_with_commas' => __( 'Syntax: Draws can have a magnitude from 1 to 5 written as a suffix, with each draw separated by a comma. If a magnitude is not present, a magnitude of one will be assumed. e.g. Cats5, Laser Pointer2', 'text_domain' ), 'search_items' => __( 'Search draws', 'affinitomics' ), 'add_or_remove_items' => __( 'Add or remove draws', 'text_domain' ), 'choose_from_most_used' => __( 'Choose from the most used Draws', 'text_domain' ), ); $args = array( 'labels' => $labels, 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_admin_column' => true, 'show_in_nav_menus' => true, 'show_tagcloud' => true, ); global $screens; register_taxonomy( 'draw', $screens, $args ); } // Hook into the 'init' action add_action( 'init', 'draw_taxonomy', 0 ); // Register Custom Taxonomy Distance function distance_taxonomy() { $labels = array( 'name' => _x( 'Negative Relationships (Distances)', 'Taxonomy General Name', 'text_domain' ), 'singular_name' => _x( 'Distance', 'Taxonomy Singular Name', 'text_domain' ), 'menu_name' => __( 'Distance', 'text_domain' ), 'all_items' => __( 'All Distances', 'text_domain' ), 'parent_item' => __( 'Parent Distance', 'text_domain' ), 'parent_item_colon' => __( 'Parent Distance:', 'text_domain' ), 'new_item_name' => __( 'New Distance', 'text_domain' ), 'add_new_item' => __( 'Add New Distance', 'text_domain' ), 'edit_item' => __( 'Edit Distance', 'text_domain' ), 'update_item' => __( 'Update Distance', 'text_domain' ), 'separate_items_with_commas' => __( 'Syntax: Distances can have a magnitude of 1 to 5, written as a suffix, with each distance separated by a comma. If a magnitude is not present, a magnitude of one will be assumed. e.g. Nickelback5, Canada2', 'text_domain' ), 'search_items' => __( 'Search distances', 'affinitomics' ), 'add_or_remove_items' => __( 'Add or remove Distance', 'text_domain' ), 'choose_from_most_used' => __( 'Choose from the most used Distances', 'text_domain' ), ); $args = array( 'labels' => $labels, 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_admin_column' => true, 'show_in_nav_menus' => true, 'show_tagcloud' => true, ); global $screens; register_taxonomy( 'distance', $screens, $args ); } // Hook into the 'init' action add_action( 'init', 'distance_taxonomy', 0 ); /* ---------------------------------------------------------------------- Register "Archetype" post type ---------------------------------------------------------------------- */ // Register Custom Post Type function arche_type() { $labels = array( 'name' => __( 'Archetypes', 'Post Type General Name', 'text_domain' ), 'singular_name' => __( 'Archetype', 'Post Type Singular Name', 'text_domain' ), 'menu_name' => __( 'Affinitomics™', 'text_domain' ), 'parent_item_colon' => __( 'Parent Archetype:', 'text_domain' ), 'all_items' => __( 'All Archetypes', 'text_domain' ), 'view_item' => __( 'View Archetype', 'text_domain' ), 'add_new_item' => __( 'Add New Archetype', 'text_domain' ), 'add_new' => __( 'New Archetype', 'text_domain' ), 'edit_item' => __( 'Edit Archetype', 'text_domain' ), 'update_item' => __( 'Update Archetype', 'text_domain' ), 'search_items' => __( 'Search Archetypes', 'text_domain' ), 'not_found' => __( 'No archetypes found', 'text_domain' ), 'not_found_in_trash' => __( 'No archetypes found in Trash', 'text_domain' ), ); $args = array( 'label' => __( 'archetype', 'text_domain' ), 'description' => __( 'Archetype information pages', 'text_domain' ), 'labels' => $labels, 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', 'post-formats', ), 'taxonomies' => array( 'descriptor', 'draw', 'distance' ), 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => true, 'show_in_admin_bar' => true, 'menu_position' => 5, 'menu_icon' => plugins_url( 'affinitomics-favicon.png', __FILE__ ), 'can_export' => true, 'has_archive' => true, 'exclude_from_search' => false, 'publicly_queryable' => true, 'capability_type' => 'post', ); register_post_type( 'archetype', $args ); } // // Hook into the 'init' action add_action( 'init', 'arche_type', 0 ); /* ---------------------------------------------------------------------- RELATED POSTS SHORTCODE Examples: [afview], [afview limit="4"], [afview category_filter="50"] [afview limit=1 display_title="false"] ---------------------------------------------------------------------- */ //register shortcode add_shortcode("afview", "afview_handler"); //handle shortcode function afview_handler( $atts, $content = null ) { $afview_output = afview_function($atts); return $afview_output; } //process shortcode function afview_function($atts) { af_verify_key(); af_verify_provider(); global $screens; extract( shortcode_atts( array( 'affinitomics' => null, 'display_title' => 'true', 'limit' => 10, 'category_filter' => '' ), $atts ) ); // Start output // $afview_output = '
'; $afview_output = ''; $post_id = get_the_ID(); $afid = get_post_meta($post_id, 'afid', true); $af_domain = get_option('af_domain'); $af_key = get_option('af_key'); // Find Related Elements if ($afid) { $af_cloud = get_option('af_cloud_url') . '/api/affinitomics/related/' . $af_key . '?afid=' . $afid . '&limit=' . $limit . '&category_filter=' . $category_filter; if ($affinitomics) { $af_cloud = $af_cloud . '&af=' . rawurlencode($affinitomics); } global $afview_count; $afview_count ++; if ($display_title == 'true') { $afview_output .= '

Related Items: '; // These are the custom affinitomics if ($affinitomics) { $afview_output .= $affinitomics; } $afview_output .= ' (sorted by Affinitomic concordance)

'; } $afview_output .= ''; } // HTML Output /*

Related Items: +foo, -bar (sorted by Affinitomic concordance)

*/ return $afview_output; } /* End Affinitomics Commercial Code */ /* ---------------------------------------------------------------------- Administration and Settings Menu ---------------------------------------------------------------------- */ add_action( 'admin_menu', 'af_plugin_menu' ); function af_plugin_menu() { // Add Custom Sub Menus add_submenu_page( 'edit.php?post_type=archetype', 'Settings', 'Settings', 'manage_options', 'affinitomics', 'af_plugin_options'); add_action( 'admin_init', 'af_register_settings' ); add_submenu_page( 'edit.php?post_type=archetype', 'Cloud Export', 'Cloud Export', 'manage_options', 'afcloudify', 'af_plugin_export'); } /* Affinitomics Commercial Code */ function af_plugin_export() { if ( !current_user_can( 'manage_options' ) ) { wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); } af_verify_key(); af_verify_provider(); // Export to Cloud if (isset($_POST['af_cloudify']) && $_POST['af_cloudify'] == 'true') { echo ''; } echo '

Export

'; global $screens; $args = array( 'post_type' => $screens, 'category' => $category_id, 'posts_per_page' => -1 ); $posts_array = get_posts($args); echo ''; echo '
    '; foreach($posts_array as $post) { place_jquery_tag($post); } echo '
'; // Default View echo '
'; echo '

Affinitomics Cloud Export

'; echo '
'; settings_fields( 'af-cloud-settings-group' ); do_settings_sections( 'af-cloud-settings-group' ); $af_cloudify = get_option( 'af_cloudify', '' ); if ($af_cloudify == 'true') $cloud_checked = 'checked="checked"'; echo '

Migrate Affinitomics to the Cloud?

'; echo ' Make it So!'; submit_button('Export'); echo '
'; echo '
'; if (is_plugin_active('affinitomics-taxonomy-converter/affinitomics-taxonomy-converter.php')) { echo 'Convert Taxonomy'; } else { echo 'Hey, did you know we have a handy importing tool? Check out the '; echo 'Affinitomics Taxonomy Converter'; } } function place_jquery_tag($post){ $id = $post->ID; $afid = get_post_meta($id, 'afid', true); $cat_string = ''; $categories = get_the_terms( $id, 'category' ); if ($categories) { $cats = array(); foreach($categories as $cat) { $cats[] = $cat->term_id; } $cat_string = implode(",", $cats); } // Collect draw terms from the post $these_draws = wp_get_post_terms( $id, "draw" ); $draw_terms = array(); foreach ($these_draws as $draw) { array_push($draw_terms, $draw->name); } // Collect distance terms from the post $these_distances = wp_get_post_terms( $id, "distance" ); $distance_terms = array(); foreach ($these_distances as $distance) { array_push($distance_terms, $distance->name); } // Collect descriptor terms from the post $these_descriptors = wp_get_post_terms( $id, "descriptor" ); $descriptor_terms = array(); foreach ($these_descriptors as $descriptor) { array_push($descriptor_terms, $descriptor->name); } $post_status = get_post_status($id); $affinitomics = array( 'url' => get_permalink($id), 'title' => get_the_title($id), 'descriptors' => implode(',', $descriptor_terms), 'draws' => implode(',', $draw_terms), 'distances' => implode(',', $distance_terms), 'uid' => $id, 'category' => $cat_string, 'status' => $post_status ); if ($affinitomics['descriptors'] || $affinitomics['draws'] || $affinitomics['distances']) { $af_cloud_url = get_option('af_cloud_url') . '/api/affinitomics/cloudify/' . get_option('af_key') . '/?'; $af_cloud_url .= '&url=' . get_permalink($id); $af_cloud_url .= '&title=' . get_the_title($id); $af_cloud_url .= '&descriptors=' . implode(',', $descriptor_terms); $af_cloud_url .= '&draws=' . implode(',', $draw_terms); $af_cloud_url .= '&distances=' . implode(',', $distance_terms); $af_cloud_url .= '&uid=' . $id; $af_cloud_url .= '&category=' . $cat_string; $af_cloud_url .= '&status=' . $post_status; echo ''; } } function af_plugin_options() { if ( !current_user_can( 'manage_options' ) ) { wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); } if ( isset( $_GET['dismissNotice'] ) ) { update_option( 'af_banner_notice_dismissed' , 'true' ); } af_verify_key(); echo '
'; echo '

Affinitomics Plugin Settings

'; echo '
'; settings_fields( 'af-settings-group' ); do_settings_sections( 'af-settings-group' ); af_verify_provider(); af_check_for_errors(); $af_errors = get_option('af_errors', ''); $af_error_code = get_option('af_error_code', ''); if(strlen($af_errors) > 0) { echo '

----- Warning -----

'; echo '

Error Message: ' . $af_errors . '

'; echo '

Error Code: ' . $af_error_code . '

'; echo '

----- Warning -----

'; } /* Affinitomics Commercial Code */ $af_key = get_option('af_key', ''); $af_cloud_url = get_option('af_cloud_url', ''); echo '
'; echo 'This is the last supported version of Affinitomics for Wordpress™.
Please upgrade to aimojo™ here for continued support and development. It\'s free too!'; echo '
'; echo '

Affinitomics™ API Key

'; echo ''; echo '

'; if(strlen($af_key) == 60){ echo 'Anonymous Account - Register for free and see in-depth reporting!
'; echo 'Register for Free'; } elseif (strlen($af_key) == 64) { echo 'Legacy User Account - Create your user account for free and see in-depth reporting!
'; echo 'Register for Free'; } elseif (strlen($af_key) > 64) { echo 'Registered User
'; echo 'View usage statistics'; } else { echo 'API Key Unrecognized...'; } echo '

'; $af_post_type_affinitomics = get_option('af_post_type_affinitomics'); $af_post_type_posts = get_option('af_post_type_posts'); $af_post_type_pages = get_option('af_post_type_pages'); $af_post_type_products = get_option('af_post_type_products'); $af_post_type_projects = get_option('af_post_type_projects'); $af_post_type_listings = get_option('af_post_type_listings'); $af_post_type_affinitomics_checked = ''; $af_post_type_posts_checked = ''; $af_post_type_pages_checked = ''; $af_post_type_products_checked = ''; $af_post_type_projects_checked = ''; $af_post_type_listings_checked = ''; if ($af_post_type_affinitomics == 'true') $af_post_type_affinitomics_checked = 'checked="checked"'; if ($af_post_type_pages == 'true') $af_post_type_pages_checked = 'checked="checked"'; if ($af_post_type_posts == 'true') $af_post_type_posts_checked = 'checked="checked"'; if ($af_post_type_products == 'true') $af_post_type_products_checked = 'checked="checked"'; if ($af_post_type_projects == 'true') $af_post_type_projects_checked = 'checked="checked"'; if ($af_post_type_listings == 'true') $af_post_type_listings_checked = 'checked="checked"'; echo '

To which Post-types would you like to apply your Affinitomics™?

'; echo ' Posts
'; echo ' Pages
'; echo ' Products
'; echo ' Projects
'; echo ' Listings
'; $af_tag_descriptors = get_option( 'af_tag_descriptors', 'true' ); $true_checked = ''; $false_checked = ''; if ($af_tag_descriptors == 'true') $true_checked = 'checked="checked"'; if ($af_tag_descriptors == 'false') $false_checked = 'checked="checked"'; $af_jumpsearch = get_option( 'af_jumpsearch', 'false' ); $true_checked = ''; $false_checked = ''; if ($af_jumpsearch == 'true') $true_checked = 'checked="checked"'; if ($af_jumpsearch == 'false') $false_checked = 'checked="checked"'; echo '

JumpSearch ( search using Affinitomics™ as context )

'; echo ' Yes
'; echo ' No
'; $af_google_cse_key = get_option('af_google_cse_key', ''); echo '

Google™ API Key

'; echo ' (not sure what this is?)'; $af_google_cse_id = get_option('af_google_cse_id', ''); echo '

Google™ Custom Search Engine ID

'; echo ' (not sure what this is?)'; $af_jumpsearch_post_type_affinitomics = get_option('af_jumpsearch_post_type_affinitomics'); $af_jumpsearch_post_type_posts = get_option('af_jumpsearch_post_type_posts'); $af_jumpsearch_post_type_pages = get_option('af_jumpsearch_post_type_pages'); $af_jumpsearch_post_type_products = get_option('af_jumpsearch_post_type_products'); $af_jumpsearch_post_type_projects = get_option('af_jumpsearch_post_type_projects'); $af_jumpsearch_post_type_listings = get_option('af_jumpsearch_post_type_listings'); $af_jumpsearch_post_type_affinitomics_checked = ''; $af_jumpsearch_post_type_posts_checked = ''; $af_jumpsearch_post_type_pages_checked = ''; $af_jumpsearch_post_type_products_checked = ''; $af_jumpsearch_post_type_projects_checked = ''; $af_jumpsearch_post_type_listings_checked = ''; if ($af_jumpsearch_post_type_affinitomics == 'true') $af_jumpsearch_post_type_affinitomics_checked = 'checked="checked"'; if ($af_jumpsearch_post_type_posts == 'true') $af_jumpsearch_post_type_posts_checked = 'checked="checked"'; if ($af_jumpsearch_post_type_pages == 'true') $af_jumpsearch_post_type_pages_checked = 'checked="checked"'; if ($af_jumpsearch_post_type_products == 'true') $af_jumpsearch_post_type_products_checked = 'checked="checked"'; if ($af_jumpsearch_post_type_projects == 'true') $af_jumpsearch_post_type_projects_checked = 'checked="checked"'; if ($af_jumpsearch_post_type_listings == 'true') $af_jumpsearch_post_type_listings_checked = 'checked="checked"'; echo '

Which Pages or Post-types should have a JumpSearch field?

'; echo ' Posts
'; echo ' Pages
'; echo ' Products
'; echo ' Projects
'; echo ' Listings
'; $af_jumpsearch_location = get_option( 'af_jumpsearch_location', 'bottom' ); $top_checked = ''; $bottom_checked = ''; if ($af_jumpsearch_location == 'top') $top_checked = 'checked="checked"'; if ($af_jumpsearch_location == 'bottom') $bottom_checked = 'checked="checked"'; echo '

Where on Pages or Post-types should the JumpSearch field appear?

'; echo ' Top of the Page or Post
'; echo ' Bottom of the Page or Post
'; submit_button(); echo ''; echo '
'; echo '
'; echo ''; } function af_register_settings() { register_setting('af-settings-group', 'af_cloud_url'); register_setting('af-settings-group', 'af_domain'); register_setting('af-settings-group', 'af_key'); register_setting('af-settings-group', 'af_post_type_affinitomics'); register_setting('af-settings-group', 'af_post_type_posts'); register_setting('af-settings-group', 'af_post_type_pages'); register_setting('af-settings-group', 'af_post_type_products'); register_setting('af-settings-group', 'af_post_type_projects'); register_setting('af-settings-group', 'af_post_type_listings'); register_setting('af-settings-group', 'af_tag_descriptors'); register_setting('af-settings-group', 'af_jumpsearch'); register_setting('af-settings-group', 'af_google_cse_key'); register_setting('af-settings-group', 'af_google_cse_id'); register_setting('af-settings-group', 'af_jumpsearch_post_type_affinitomics'); register_setting('af-settings-group', 'af_jumpsearch_post_type_posts'); register_setting('af-settings-group', 'af_jumpsearch_post_type_pages'); register_setting('af-settings-group', 'af_jumpsearch_location'); register_setting('af-settings-group', 'af_errors'); register_setting('af-settings-group', 'af_error_code'); register_setting('af-cloud-settings-group', 'af_cloudify'); } function extraView( $name, array $args = array() ) { $args = apply_filters( 'affinitomics_view_arguments', $args, $name ); foreach ( $args AS $key => $val ) { $$key = $val; } load_plugin_textdomain( 'affinitomics' ); $file = AFFINITOMICS__PLUGIN_DIR . 'views/'. $name . '.php'; include( $file ); } function display_notice() { // only show notice if we're either a super admin on a network or an admin on a single site $show_notice = current_user_can( 'manage_network_plugins' ) || ( ! is_multisite() && current_user_can( 'install_plugins' ) ); if ( !$show_notice ) return; $dismissed = get_option( 'af_banner_notice_dismissed', '' ); if ($dismissed != 'true') { $registerLink = 'http://aimojo.com'; $postOptionsUrl = 'edit.php?post_type=archetype&page=affinitomics&dismissNotice=1'; $bannerImage = 'upgrade-to-aimojo-mod.jpg'; extraView( 'notice', array( 'bannerLink' => $registerLink, 'postOptionsUrl' => $postOptionsUrl, 'bannerImage' => $bannerImage ) ); } } /* ---------------------------------------------------------------------- Google Search with Affinitomics ---------------------------------------------------------------------- ---------------------------------------------------------------------- Search HTML Produced by Google CSE: ---------------------------------------------------------------------- ---------------------------------------------------------------------- CSS Styling Examples: ---------------------------------------------------------------------- #af-search h2 {background-color:magenta;} #search-content {background-color:green;} */ if (get_option('af_jumpsearch') == 'true') { add_filter( 'the_content', 'af_search_content_filter', 20 ); } // Compare this post type with the user options function this_page_search_enabled(){ $this_page_type = get_post_type( get_the_ID() ); switch ($this_page_type) { case 'post': return get_option('af_jumpsearch_post_type_posts'); break; case 'page': return get_option('af_jumpsearch_post_type_pages'); break; case 'product': return get_option('af_jumpsearch_post_type_products'); break; case 'project': return get_option('af_jumpsearch_post_type_projects'); break; case 'listing': return get_option('af_jumpsearch_post_type_listings'); break; } } function af_search_content_filter( $content ) { if(this_page_search_enabled()){ if ( is_singular() ) { $cse = ''; $cse .= ''; $post_id = get_the_ID(); // Collect descriptor terms from the post $these_descriptors = wp_get_post_terms( $post_id, "descriptor" ); $descriptor_terms = array(); foreach ($these_descriptors as $descriptor) { array_push($descriptor_terms, $descriptor->name); } // Collect draws, find the highest draw $best_draw = ""; $best_draw_num = 0; $these_draws = wp_get_post_terms( $post_id, "draw" ); $draw_terms = array(); foreach ($these_draws as $draw) { $this_weight = substr($draw->name, -1); if (is_numeric($this_weight)){ if ($this_weight > 1) { if ( $this_weight > $best_draw_num ) { $best_draw = preg_replace("/[0-9]/", "", $draw->name); $best_draw_num = $this_weight; } } } else { $draw->name = preg_replace("/[0-9]/", "", $draw->name); array_push($draw_terms, $draw->name); } } // Find the best distance or use the first one $best_distance = ""; $best_distance_num = 0; $these_distances = wp_get_post_terms( $post_id, "distance" ); $distance_terms = array(); foreach ($these_distances as $distance) { $this_weight = substr($distance->name, -1); if (is_numeric($this_weight)){ if ( $this_weight > $best_distance_num ) { $best_distance = preg_replace("/[0-9]/", "", $distance->name); $best_distance_num = $this_weight; } } else { $distance->name = preg_replace("/[0-9]/", "", $distance->name); array_push($distance_terms, $distance->name); } } if (count($descriptor_terms) > 0){ $descriptors_meta = $descriptor_terms[0]; } else { $descriptors_meta = ""; } if($best_draw != ""){ $draw_meta = $best_draw; } else if (count($draw_terms) > 0){ $draw_meta = $draw_terms[0]; } else { $draw_meta = ""; } if($best_distance != ""){ $distance_meta = '-' . $best_distance; } else if (count($distance_terms) > 0){ $distance_meta = '-' . $distance_terms[0]; } else { $distance_meta = ""; } // Use Taxonomy Data to Build Affinitomic Search String $affinitomics = ''; if ($descriptors_meta != '') { $affinitomics = $descriptors_meta; } if ($draw_meta != '') { if ($affinitomics == '') { $affinitomics = $draw_meta; } else { $affinitomics .= ', ' . $draw_meta; } } if ($distance_meta != '') { if ($affinitomics == '') { $affinitomics = $distance_meta; } else { $affinitomics .= ', ' . $distance_meta; } } if ($affinitomics != '') { $cse .= '
 
'; $cse .= ''; $modified_content = ''; if (get_option('af_jumpsearch_location') == 'top') $modified_content .= $cse; $modified_content .= $content; if (get_option('af_jumpsearch_location') == 'bottom') $modified_content .= $cse; return $modified_content; } } return $content; } /* End Affinitomics Commercial Code */ // CURL Request Function function curl_request($url,$postdata=false) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLINFO_HEADER_OUT, false); curl_setopt($ch, CURLOPT_VERBOSE, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, $url); if ($postdata) { //urlify the data for the POST foreach($postdata as $key=>$value) { $fields_string .= rawurlencode($key).'='.rawurlencode($value).'&'; } rtrim($fields_string, '&'); curl_setopt($ch,CURLOPT_POST, count($postdata)); curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); } $response = curl_exec($ch); curl_close($ch); return $response; }