/** * Show 'edit message' page. * * @param integer $id id of message to edit, NULL/0 to create new message */ public function edit($id = NULL) { if ($id) { // load message $message = new Bbpp_ThankMeLater_Message($id); } else { // create default message $blog_name = get_bloginfo("name"); $message = new Bbpp_ThankMeLater_Message(); $message_subject = sprintf(_x("%s - %s", "post title - blog name", "bbpp-thankmelater"), "[post_title]", $blog_name); $message_message = "[t_simple]\n\n"; $message_message .= "[t_part name=\"main\"]\n\n"; $message_message .= sprintf(__("Hi %s,", "bbpp-thankmelater"), "[name]"); /* translators: the string "[post_title]" will be replaced with the blog post's title. Please do not remove this string. */ $t_message_thanks = __("Thank you for your comment on [post_title]. Please check back soon for a response.", "bbpp-thankmelater"); $message_message .= "\n\n" . sprintf($t_message_thanks, $blog_name); $message_message .= "\n\n"; $message_message .= "[htmlonly]\n<a href=\"[comment_url attr=1]\">"; $message_message .= __("Return to your comment.", "bbpp-thankmelater"); $message_message .= "</a>\n[/htmlonly]"; $message_message .= "\n\n[textonly]\n"; /* translators: the string "[comment_url]" will be replaced with the URL to the user's comment. Please do not remove this string. */ $t_message_link = __("Return to your comment: [comment_url]", "bbpp-thankmelater"); $message_message .= $t_message_link; $message_message .= "\n[/textonly]"; $message_message .= "\n\n" . sprintf(__("You posted this comment on %s: %s", "bbpp-thankmelater"), "[date format=\"d M\"]", "[comment maxlength=200]"); $message_message .= "\n\n" . __("Thank you!", "bbpp-thankmelater") . "\n\n"; $message_message .= "[/t_part]\n\n"; $message_message .= "[/t_simple]"; $message->addMessage(array("from_name" => $blog_name, "from_email" => get_bloginfo("admin_email"), "subject" => $message_subject, "message" => $message_message, "min_delay" => 30, "min_delay_unit" => "minutes", "target_tags" => array(), "target_categories" => array(), "target_posts" => array(), "max_sends_per_email" => 0, "track_opens" => 1)); } $error = array(); if ($_POST) { // save the changes to the database check_admin_referer("bbpp_thankmelater_edit_message_" . intval($id)); $data = stripslashes_deep($_POST); if (!isset($data["target_tags"])) { $data["target_tags"] = array(); } if (!isset($data["target_categories"])) { $data["target_categories"] = array(); } if (!isset($data["target_posts"])) { $data["target_posts"] = array(); } if (!isset($data["track_opens"])) { $data["track_opens"] = "0"; } $message->setMessage($data); $error = $message->save(); if (!$error) { // message updated! show the list of messages: $id = $message->getId(); return $this->index(false, array($id)); } } //$ab_sort = function ($a, $b) { // return ($a->name < $b->name) ? -1 : 1; //}; // get the tag targeting options $tag_options = get_tags(array("number" => 200, "orderby" => "count", "order" => "desc", "hide_empty" => false)); usort($tag_options, array($this, "_cmp_name")); // get the category targeting options $category_options = get_categories(array("number" => 200, "orderby" => "count", "order" => "desc", "hide_empty" => false)); usort($category_options, array($this, "_cmp_name")); // get the posts which may be targeted $post_options = get_posts(array("numberposts" => 200, "orderby" => "post_date", "order" => "desc", "post_status" => "publish,pending,draft,future,private")); usort($post_options, array($this, "_cmp_post_title")); // show the edit form require_once BBPP_THANKMELATER_PLUGIN_PATH . "admin/messages/edit.php"; }