'.__('Connect Your ReadyGraph Account').'
'.__('Almost done - connect your account to start getting users.').'
'; } } add_action('admin_notices', 'add_al2fb_readygraph_plugin_warning'); if(get_option('readygraph_application_id') && strlen(get_option('readygraph_application_id')) > 0){ if ((get_option('readygraph_access_token') && strlen(get_option('readygraph_access_token')) > 0) || (get_option('readygraph_enable_monetize') && get_option('readygraph_enable_monetize') == "true")){ add_action('wp_footer', 'al2fb_readygraph_client_script_head', 9); } } add_action('admin_init', 'on_plugin_activated_readygraph_al2fb_redirect'); add_option('readygraph_connect_notice','true'); function rg_al2fb_popup_options_enqueue_scripts() { if ( get_option('readygraph_popup_template') == 'default-template' ) { wp_enqueue_style( 'default-template', plugin_dir_url( __FILE__ ) .'extension/readygraph/assets/css/default-popup.css' ); } if ( get_option('readygraph_popup_template') == 'red-template' ) { wp_enqueue_style( 'red-template', plugin_dir_url( __FILE__ ) .'extension/readygraph/assets/css/red-popup.css' ); } if ( get_option('readygraph_popup_template') == 'blue-template' ) { wp_enqueue_style( 'blue-template', plugin_dir_url( __FILE__ ) .'extension/readygraph/assets/css/blue-popup.css' ); } if ( get_option('readygraph_popup_template') == 'black-template' ) { wp_enqueue_style( 'black-template', plugin_dir_url( __FILE__ ) .'extension/readygraph/assets/css/black-popup.css' ); } if ( get_option('readygraph_popup_template') == 'gray-template' ) { wp_enqueue_style( 'gray-template', plugin_dir_url( __FILE__ ) .'extension/readygraph/assets/css/gray-popup.css' ); } if ( get_option('readygraph_popup_template') == 'green-template' ) { wp_enqueue_style( 'green-template', plugin_dir_url( __FILE__ ) .'extension/readygraph/assets/css/green-popup.css' ); } if ( get_option('readygraph_popup_template') == 'yellow-template' ) { wp_enqueue_style( 'yellow-template', plugin_dir_url( __FILE__ ) .'extension/readygraph/assets/css/yellow-popup.css' ); } if ( get_option('readygraph_popup_template') == 'custom-template' ) { wp_enqueue_style( 'custom-template', plugin_dir_url( __FILE__ ) .'extension/readygraph/assets/css/custom-popup.css' ); } } add_action( 'admin_enqueue_scripts', 'rg_al2fb_popup_options_enqueue_scripts' ); add_action( 'wp_enqueue_scripts', 'rg_al2fb_popup_options_enqueue_scripts' ); function al2fb_post_updated_send_email( $post_id ) { // If this is just a revision, don't send the email. $post_type = get_post_type( $post_id ); if ('page' != $post_type && 'post' != $post_type) return; if ( wp_is_post_revision( $post_id ) ) return; if(get_option('readygraph_application_id') && strlen(get_option('readygraph_application_id')) > 0 && get_option('readygraph_send_blog_updates') == "true"){ $post_title = get_the_title( $post_id ); $post_url = get_permalink( $post_id ); $post_content = get_post($post_id); $post_excerpt = (isset($post_content->post_excerpt) && (!empty($post_content->post_excerpt))) ? $post_content->post_excerpt : wp_trim_words(strip_tags(strip_shortcodes($post_content->post_content)),500); $attachments = get_children(array('post_parent' => $post_id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID')); $images_list = array(); foreach($attachments as $att_id => $attachment) { $full_img_url = wp_get_attachment_url($attachment->ID); $images_list[] = $full_img_url; // Your Code here } $post_image = ""; if ($images_list) $post_image = reset($images_list); $url = 'http://readygraph.com/api/v1/post.json/'; $response = wp_remote_post($url, array( 'body' => array('is_wordpress'=>1, 'message' => $post_title, 'message_link' => $post_url, 'message_image_link' => $post_image, 'message_excerpt' => $post_excerpt,'client_key' => get_option('readygraph_application_id'), 'email' => get_option('readygraph_email')))); if ( is_wp_error( $response ) ) { $error_message = $response->get_error_message(); } else { } $app_id = get_option('readygraph_application_id'); wp_remote_get( "http://readygraph.com/api/v1/tracking?event=post_created&app_id=$app_id" ); } else { } } add_action('future_to_publish','al2fb_post_updated_send_email'); add_action('new_to_publish','al2fb_post_updated_send_email'); add_action('draft_to_publish','al2fb_post_updated_send_email'); if(get_option('al2fb_wordpress_sync_users')) return; else { add_action('plugins_loaded', 'al2fb_wordpress_sync_users'); } function al2fb_wordpress_sync_users() { if(get_option('al2fb_wordpress_sync_users') && get_option('al2fb_wordpress_sync_users') == "true") return; else { if(get_option('readygraph_application_id') && strlen(get_option('readygraph_application_id')) > 0){ global $wpdb; $app_id = get_option('readygraph_application_id'); $query = "SELECT email as email, date as user_date FROM {$wpdb->prefix}users "; $subscribe2_users = $wpdb->get_results($query); $emails = ""; $dates = ""; $count = 0; $count = mysql_num_rows($subscribe2_users); wp_remote_get( "http://readygraph.com/api/v1/tracking?event=wp_user_synced&app_id=$app_id&count=$count" ); foreach($subscribe2_users as $user) { $emails .= $user->email . ","; $dates .= $user->user_date . ","; } $url = 'https://readygraph.com/api/v1/wordpress-sync-enduser/'; $response = wp_remote_post($url, array( 'body' => array('app_id' => $app_id, 'email' => rtrim($emails, ", "), 'user_registered' => rtrim($dates, ", ")))); update_option('al2fb_wordpress_sync_users',"true"); remove_action('plugins_loaded', 'al2fb_wordpress_sync_users'); } } } function al2fb_rg_connect(){ if(get_option('readygraph_connect_anonymous') != "true"){ $url = 'https://readygraph.com/api/v1/wordpress-rg-connect-anonymous/'; $randon_string = al2fb_get_random_string(); $response = wp_remote_post($url, array( 'body' => array('app_secret' => $randon_string, 'website' => home_url()))); if ( is_wp_error( $response ) ) { $error_message = $response->get_error_message(); } else { $result = json_decode($response['body'],true); $app_id = $result['data']['app_id']; update_option('readygraph_connect_anonymous', 'true'); update_option('readygraph_application_id', $app_id); update_option('readygraph_connect_anonymous_app_secret', $randon_string); } } } function al2fb_get_random_string() { $valid_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; $length = 10; $random_string = ""; $num_valid_chars = strlen($valid_chars); for ($i = 0; $i < $length; $i++) { $random_pick = mt_rand(1, $num_valid_chars); $random_char = $valid_chars[$random_pick-1]; $random_string .= $random_char; } return $random_string; } ?>