setField(array("attr" => "title", "type" => "text", "label" => __("Title", "chat"), "optional" => true)); $this->setField(array("attr" => "dialogue", "type" => "text_block", "label" => __("Dialogue", "chat"), "preview" => true, "help" => "chat_dialogue", "bookmarklet" => "selection")); $this->customFilter("dialogue", "format_dialogue"); $this->setFilter("title", array("markup_title", "markup_post_title")); $this->setFilter("dialogue", array("markup_text", "markup_post_text")); $this->respondTo("preview_chat", "format_dialogue"); $this->respondTo("help_chat_dialogue", "help"); } public function submit() { if (empty($_POST['dialogue'])) error(__("Error"), __("Dialogue can't be blank.")); fallback($_POST['slug'], sanitize($_POST['title'])); return Post::add(array("title" => $_POST['title'], "dialogue" => $_POST['dialogue']), $_POST['slug'], Post::check_url($_POST['slug'])); } public function update($post) { if (empty($_POST['dialogue'])) error(__("Error"), __("Dialogue can't be blank.")); $post->update(array("title" => $_POST['title'], "dialogue" => $_POST['dialogue'])); } public function title($post) { $dialogue = oneof($post->dialogue_unformatted, $post->dialogue); $dialogue = explode("\n", $dialogue); $line = preg_replace("/^\s*[\[\(]?[0-9]{1,2}:[0-9]{2}(:[0-9]{2})?\s*(pm|am)?[\]|\)]?\s*/i", "", $dialogue[0]); $first_line = preg_replace("/([<]?)([^:|>]+)( \(me\)?)(:|>) (.+)/i", "\\1\\2\\4 \\5", $dialogue[0]); return oneof($post->title, $first_line); } public function excerpt($post) { return $post->dialogue; } public function feed_content($post) { return $post->dialogue; } public function format_dialogue($text, $post = null) { if (isset($post)) $post->dialogue_unformatted = $text; $split = explode("\n", $text); $return = '"; # If they're previewing. if (!isset($post)) $return = preg_replace("/(
  • )(.+)(<\/span> (.+)\n<\/li>)/", "\\1\\3\\4", $return); return $return; } public function help() { $title = __("Dialogue Formatting", "chat"); $body = "

    ".__("To give yourself a special CSS class, append \" (me)\" to your username, like so:", "chat")."

    \n"; $body.= "\n"; $body.= "

    ".__("This only has to be done to the first occurrence of the username.", "chat")."

    "; $body.= "

    ".__("To attribute a name to a URL, append the URL in parentheses, preceded by a space, to the username:", "chat")."

    \n"; $body.= "\n"; $body.= "

    ".__("This also only has to be done to the first occurrence of the username. It cannot be combined with attributing someone as yourself (because they're already at your site anyway).", "chat")."

    "; return array($title, $body); } }