setField(array("attr" => "audio",
"type" => "file",
"label" => __("MP3 File", "audio"),
"note" => "(Max. file size: ".ini_get('upload_max_filesize').")"));
if (isset($_GET['action']) and $_GET['action'] == "bookmarklet")
$this->setField(array("attr" => "from_url",
"type" => "text",
"label" => __("From URL?", "audio"),
"optional" => true,
"no_value" => true));
$this->setField(array("attr" => "description",
"type" => "text_block",
"label" => __("Description", "audio"),
"optional" => true,
"preview" => true,
"bookmarklet" => "selection"));
$this->setFilter("description", array("markup_text", "markup_post_text"));
$this->respondTo("delete_post", "delete_file");
$this->respondTo("javascript", "player_js");
$this->respondTo("feed_item", "enclose_mp3");
$this->respondTo("filter_post", "filter_post");
$this->respondTo("admin_write_post", "swfupload");
$this->respondTo("admin_edit_post", "swfupload");
$this->respondTo("post_options", "add_option");
}
public function swfupload($admin, $post = null) {
if (isset($post) and $post->feather != "audio" or
isset($_GET['feather']) and $_GET['feather'] != "audio")
return;
Trigger::current()->call("prepare_swfupload", "audio", "*.mp3");
}
public function submit() {
if (!isset($_POST['filename'])) {
if (isset($_FILES['audio']) and $_FILES['audio']['error'] == 0)
$filename = upload($_FILES['audio'], "mp3");
elseif (!empty($_POST['from_url']))
$filename = upload_from_url($_POST['from_url'], "mp3");
else
error(__("Error"), __("Couldn't upload audio file."));
} else
$filename = $_POST['filename'];
return Post::add(array("filename" => $filename,
"description" => $_POST['description']),
$_POST['slug'],
Post::check_url($_POST['slug']));
}
public function update($post) {
if (!isset($_POST['filename']))
if (isset($_FILES['audio']) and $_FILES['audio']['error'] == 0) {
$this->delete_file($post);
$filename = upload($_FILES['audio'], "mp3");
} elseif (!empty($_POST['from_url'])) {
$this->delete_file($post);
$filename = upload_from_url($_POST['from_url'], "mp3");
} else
$filename = $post->filename;
else {
$this->delete_file($post);
$filename = $_POST['filename'];
}
$post->update(array("filename" => $filename,
"description" => $_POST['description']));
}
public function title($post) {
return oneof($post->title, $post->title_from_excerpt());
}
public function excerpt($post) {
return $post->description;
}
public function feed_content($post) {
return $post->description;
}
public function delete_file($post) {
if ($post->feather != "audio") return;
unlink(MAIN_DIR.Config::current()->uploads_path.$post->filename);
}
public function filter_post($post) {
if ($post->feather != "audio") return;
$post->audio_player = $this->flash_player_for($post->filename, array(), $post);
}
public function player_js() {
?>//'."\n";
$player.= ''."\n";
return $player;
}
public function add_option($options, $post = null) {
if (isset($post) and $post->feather != "audio") return;
if (!isset($_GET['feather']) and Config::current()->enabled_feathers[0] != "audio" or
isset($_GET['feather']) and $_GET['feather'] != "audio") return;
$options[] = array("attr" => "from_url",
"label" => __("From URL?", "audio"),
"type" => "text");
return $options;
}
}