Skip to content
Snippets Groups Projects
Commit 8c3fd880 authored by ale's avatar ale
Browse files

Update the SQL schema and template

The template had problems with string quoting (PHP
only allows interpolation in double-quoted strings!).

The SQL schema changes the primary key,
so we're switching to a different table to avoid
having to dedupe existing data.
parent 2656ff6f
No related branches found
No related tags found
No related merge requests found
Pipeline #21872 passed
......@@ -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>';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment