setField(array("attr" => "video",
"type" => "text_block",
"rows" => 4,
"label" => __("Video", "video"),
"preview" => true,
"bookmarklet" => $this->isVideo() ?
"url" :
""));
$this->setField(array("attr" => "caption",
"type" => "text_block",
"rows" => 4,
"label" => __("Caption", "video"),
"optional" => true,
"preview" => true,
"bookmarklet" => "selection"));
if ($this->isVideo())
$this->bookmarkletSelected();
$this->setFilter("caption", array("markup_text", "markup_post_text"));
$this->respondTo("preview_video", "embed_tag");
}
public function submit() {
if (empty($_POST['video']))
error(__("Error"), __("Video can't be blank."));
return Post::add(array("embed" => $this->embed_tag($_POST['video']),
"video" => $_POST['video'],
"caption" => $_POST['caption']),
$_POST['slug'],
Post::check_url($_POST['slug']));
}
public function update($post) {
if (empty($_POST['video']))
error(__("Error"), __("Video can't be blank."));
$post->update(array("embed" => $this->embed_tag($_POST['video']),
"video" => $_POST['video'],
"caption" => $_POST['caption']));
}
public function title($post) {
return $post->title_from_excerpt();
}
public function excerpt($post) {
return $post->caption;
}
public function feed_content($post) {
return $post->embed."
".$post->caption;
}
public function embed_tag($video, $field = null) { # We use this for previewing too
if (isset($field) and $field != "embed")
return $video; # If they're previewing and the field argument isn't the embed, return the original.
if (preg_match("/http:\/\/(www\.|[a-z]{2}\.)?youtube\.com\/watch\?v=([^&]+)/", $video, $matches)) {
return '';
} else if (preg_match("/^http:\/\/(www\.)?vimeo.com\/([0-9]+)/", $video, $matches)) {
$site = get_remote("http://vimeo.com/".$matches[2]);
preg_match('/