get_all_models(); $campaigns = $models['models']; $activites = array(); foreach($campaigns as $key=>$model){ $id = $model->id; $title = $model->settings['robot_campaign_name']; $query = " SELECT * FROM " . $wpdb->prefix . "ai_robot_logs WHERE level = 'success' AND created > '" . $stamp . "' AND camp_id = " . $id; $wpdb->get_results($query); $count = $wpdb->num_rows; $activites[$key]['id'] = $id; $activites[$key]['title'] = $title; $activites[$key]['count'] = $count; } $posts_count = 0; foreach ( $activites as $key => $activity) { $posts_count += $activity['count']; } $site_name = ( is_multisite() ) ? get_site_option( 'site_name' ) : get_option( 'blogname' ); $ret .= '

' . $site_name . '

Last '.$update_frequency.' '.$update_frequency_unit.' Report

'; $all_campaigns = '' . count($campaigns) . 'Total Campaigns'; $total_posts = '' . $posts_count . 'Total Posts'; $ret .= '
' . $all_campaigns . '
'; $ret .= '
' . $total_posts . '
'; // Activities breakdown $rows = array(); $rows[] = '

' . __( 'Campaigns details', 'ai-robot' ) . '

'; if ( $activites ) { foreach ( $activites as $key => $activity) { $rows[] = '' . $activity['title'] . '' . $activity['count'] . ' posts'; } } $ret .= '' . implode( '', $rows ) . '
'; $ret = '
' . $ret . '
'; return $ret; } /** * * Send notification letter * * @param string $type Notification type * @param string|array $msg Additional message * * @return bool */ function ai_robot_send_email( $type = '', $msg = '' ) { if ( ! $type ) { return false; } $html_mode = true; $subj = '[' . get_option( 'blogname' ) . '] ' . __( 'Ai Robot notify', 'ai-robot' ) . ': '; $body = ''; if ( is_array( $msg ) ) { $msg = implode( "\n\n", $msg ); } switch ( $type ) { case 'report': $html_mode = true; $subj = '[' . get_option( 'blogname' ) . '] WP Ai Robot: ' . __( 'Stats Report', 'ai-robot' ); $body = ai_robot_generate_report(); $link = admin_url( 'admin.php?page=ai-robot-settings' ); $body .= '
' . __( 'To change reporting settings visit', 'ai-robot' ) . ' ' . $link . ''; $body .= $msg; break; case 'new_version': $subj = __( 'A new version of Ai Robot is available to install', 'ai-robot' ); $body = __( 'Hi!', 'ai-robot' ) . "\n\n"; $body .= __( 'A new version of Ai Robot is available to install', 'ai-robot' ) . "\n\n"; $body .= $msg . "\n\n"; $body .= __( 'Website', 'ai-robot' ) . ': ' . get_option( 'blogname' ); break; } $to_list = ai_robot_get_email( $type, true ); $to = implode( ', ', $to_list ); $footer = ''; $footer .= "\n\n\n" . __( 'This message was sent by', 'ai-robot' ) . ' Ai Robot ' . AI_ROBOT_VERSION . "\n"; $footer .= 'https://wpairobot.com'; if ( $html_mode ) { add_filter( 'wp_mail_content_type', 'ai_robot_enable_html' ); $footer = str_replace( "\n", '
', $footer ); } // Everything is prepared, let's send it out $result = null; if ( $to && $subj && $body ) { if ( function_exists( 'wp_mail' ) ) { $body = $body . $footer; if ( $html_mode ) { $body = '' . $body . ''; } $result = wp_mail( $to, $subj, $body ); } } remove_filter('wp_mail_content_type', 'ai_robot_enable_html'); return $result; } /** * @param string $type Type of notification email * @param bool $array Return as an array * * @return array|string Email address(es) for notifications */ function ai_robot_get_email( $type = '', $array = false ) { $email = ''; if ( empty( $email ) ) { $email = get_site_option( 'admin_email' ); if ( $array ) { $email = array( $email ); } } return $email; } function ai_robot_enable_html() { return 'text/html'; }