/** * Format 'targeting' value */ public function column_targeting($data) { $target_tags = $data["target_tags"]; $target_categories = $data["target_categories"]; $target_posts = $data["target_posts"]; // create a virtual Thank Me Later message $message = new Bbpp_ThankMeLater_Message(); $message->addMessage(array("target_tags" => $target_tags, "target_categories" => $target_categories, "target_posts" => $target_posts)); $posts = $message->getTargets(); $count = count($posts); $sep = _x(", ", "separator in list of post names", "bbpp-thankmelater"); $max_show = 2; if ($count == 0) { $summary = __("Targets 0 posts", "bbpp-thankmelater"); } elseif ($count <= $max_show) { $names = ""; $post = get_post($posts[$count - 1]); $last_name = $post->post_title; for ($i = 0; $i < $count - 1; $i++) { if ($i > 0) { $names .= $sep; } $post = get_post($posts[$i]); $names .= $post->post_title; } $summary = sprintf(_n("Targets %2\$s", "Targets %s and %s", $count, "bbpp-thankmelater"), esc_html($names), esc_html($last_name)); } else { $names = ""; for ($i = 0; $i < $max_show; $i++) { if ($i > 0) { $names .= $sep; } $post = get_post($posts[$i]); $names .= $post->post_title; } $view_all_url = "?page=" . urlencode(stripslashes($_REQUEST["page"])) . "&action=targets" . "&id=" . $data["id"]; $summary = sprintf(_n("Targets %s and %s%d other post%s", "Targets %s and %s%d other posts%s.", $count - $max_show, "bbpp-thankmelater"), esc_html($names), "<a href=\"{$view_all_url}\">", $count - $max_show, "</a>"); } if (!$target_categories && !$target_tags && !$target_posts) { $summary = __("Targets all posts", "bbpp-thankmelater"); } return $summary; }
/** * Generate a summary of the targeted messages (call with AJAX) * * @param array $target_tags * @param array $target_categories * @param array $target_posts */ public function targeting($target_tags, $target_categories, $target_posts) { // create a virtual Thank Me Later message $message = new Bbpp_ThankMeLater_Message(); $message->addMessage(array("target_tags" => $target_tags, "target_categories" => $target_categories, "target_posts" => $target_posts)); $posts = $message->getTargets(); $count = count($posts); $sep = _x(", ", "separator in list of post names", "bbpp-thankmelater"); $max_show = 4; if ($count == 0) { // restrictions returns no posts. $summary = __("Targets 0 posts", "bbpp-thankmelater"); } elseif ($count <= $max_show) { // show all posts $names = ""; $post = get_post($posts[$count - 1]); $last_name = $post->post_title; for ($i = 0; $i < $count - 1; $i++) { if ($i > 0) { $names .= $sep; } $post = get_post($posts[$i]); $names .= $post->post_title; } /* translators: %2$s will be replaced with post name. In plural version, the first %s is a seperated list of post titles, the second %s is the title of the last post */ $t_summary = _n("Targets %2\$s", "Targets %s and %s", $count, "bbpp-thankmelater"); $summary = sprintf($t_summary, $names, $last_name); } else { // show first $max_show posts, followed by 'and [n] other posts' $names = ""; for ($i = 0; $i < $max_show; $i++) { if ($i > 0) { $names .= $sep; } $post = get_post($posts[$i]); $names .= $post->post_title; } $summary = sprintf(_n("Targets %s and %s%d other post%s", "Targets %s and %s%d other posts%s", $count - $max_show, "bbpp-thankmelater"), $names, "", $count - $max_show, ""); } if (!$target_categories && !$target_tags && !$target_posts) { $summary = __("Targets all posts", "bbpp-thankmelater"); } $response = array("summary" => $summary); echo json_encode($response); exit; }