diff --git a/ai-global-activity.php b/ai-global-activity.php index 931f303849bfe735a4db6fb2d1475a3786e6d117..f195d6d4fcc4989e9aef69703ec2dfa4c7b25f57 100644 --- a/ai-global-activity.php +++ b/ai-global-activity.php @@ -13,7 +13,7 @@ global $ai_activity_db_version; $ai_activity_db_version = '1.0'; -define('AI_ACTIVITY_TABLE_NAME', 'ai_activity'); +define('AI_ACTIVITY_TABLE_NAME', 'ai_global_activity'); /* Database schema initialization */ function ai_activity_install() { @@ -24,7 +24,6 @@ function ai_activity_install() { $charset_collate = $wpdb->get_charset_collate(); $sql = "CREATE TABLE $table_name ( - id mediumint(9) NOT NULL AUTO_INCREMENT, blog_id integer(11) NOT NULL, post_id integer(11) NOT NULL, title text, @@ -32,7 +31,7 @@ function ai_activity_install() { content text, url text, published_at datetime DEFAULT current_timestamp(), - PRIMARY KEY (id), + PRIMARY KEY (blog_id, post_id), KEY published_at (published_at) ) $charset_collate;"; @@ -77,7 +76,10 @@ function ai_activity_publish_post($post_id) { $post_content = get_the_content('more...', true, $post); $post_author = apply_filters('the_author', $post->post_author); - $wpdb->insert( + // If another entry for the same blog_id/post_id exists, + // we want to overwrite it (likely someone editing an already + // published post). + $wpdb->replace( AI_ACTIVITY_TABLE_NAME, array( 'title' => $post_title, @@ -116,7 +118,7 @@ function ai_activity_get_latest_posts($offset, $limit) { $results = $wpdb->get_results($wpdb->prepare( " SELECT blog_id, post_id, title, author, content, url, published_at - FROM $table_name + FROM {$table_name} ORDER BY published_at DESC LIMIT %d OFFSET %d ", @@ -150,39 +152,39 @@ function ai_activity_display_recent_posts($tmp_number, $tmp_title_characters, $t if ($tmp_title_link == 'no') { $html .= $title_short; } else { - $html .= '<a href="{$post_url}" >${title_short}</a>'; + $html .= "<a href=\"{$post_url}\" >{$title_short}</a>"; } if ($show_blog) { $blog_details = get_blog_details($blog_id); $site_url = get_site_url($blog_id); $class = 'blog-info'; - $post_blog = '<span class="{$class}"> - <a href="{$site_url}">{$blog_details->blogname}</a> - </span>'; + $post_blog = "<span class=\"{$class}\"> + <a href=\"{$site_url}\">{$blog_details->blogname}</a> + </span>"; $post_blog = apply_filters('recent_network_posts_post_blog', $post_blog, $blog_id); - $html .= ' (<a href="{$site_url}">{$blog_details->blogname}</a>)'; + $html .= " (<a href=\"{$site_url}\">{$blog_details->blogname}</a>)"; } - $html .= '</div>'; + $html .= "</div>"; } - $html .= '<div class="post-content">{$post->content}</div>'; - $html .= '</div>'; + $html .= "<div class=\"post-content\">{$post->content}</div>"; + $html .= "</div>"; } } $html .= '<div class="global-activity-pagination">'; $prev_link = ai_activity_get_previous_page_link(); if ($prev_link) { - $html .= '<div class="nav-previous align-left"><a href="{$prev_link}">Newer</a></div>'; + $html .= "<div class=\"nav-previous align-left\"><a href=\"{$prev_link}\">Newer</a></div>"; } $next_link = ai_activity_get_next_page_link(); if ($next_link) { - $html .= '<div class="nav-next align-right"><a href="{$next_link}">Older</a></div>'; + $html .= "<div class=\"nav-next align-right\"><a href=\"{$next_link}\">Older</a></div>"; } $html .= '</div>';