CMS for the late garbage.fm
at main 139 lines 3.9 kB view raw
1<?php 2 3class AdminEpisodesController extends ApplicationController { 4 static $session = "on"; 5 static $before_filter = array( 6 "authenticate_user", 7 "require_logged_in_user", 8 ); 9 static $layout = "admin"; 10 11 static $verify = array( 12 array("method" => "post", 13 "only" => array("create", "update", "destroy"), 14 "redirect_to" => ADMIN_ROOT_URL, 15 ), 16 ); 17 18 static $filter_parameter_logging = array("preview_text"); 19 20 public function destroy() { 21 $this->episode = Episode::find_by_episode($this->params["id"]); 22 $this->episode->delete(); 23 24 $this->add_flash_success("Successfully deleted episode " 25 . h($this->episode->episode)); 26 return $this->redirect_to(ADMIN_ROOT_URL); 27 } 28 29 public function index() { 30 $this->episodes = Episode::find("all", 31 array("order" => "episode DESC")); 32 } 33 34 public function build() { 35 $this->episode = new Episode; 36 37 $this->episode->episode = Episode::next_episode(); 38 39 $this->episode->is_pending = true; 40 $this->episode->air_date = new DateTime(date("Y-m-d 20:00:00")); 41 42 $this->page_title = "Create New Episode"; 43 } 44 45 public function create() { 46 $this->episode = new Episode($this->params["episode"]); 47 48 if ($_FILES["episode"]["name"]["new_mp3"]) 49 $this->episode->take_new_mp3($_FILES["episode"]["tmp_name"]["new_mp3"]); 50 51 if ($this->episode->save()) { 52 $this->add_flash_success("Successfully created episode " . 53 $this->episode->episode); 54 return $this->redirect_to(ADMIN_ROOT_URL); 55 } 56 else { 57 return $this->render(array("action" => "build")); 58 } 59 } 60 61 public function edit() { 62 $this->episode = Episode::find_by_episode($this->params["id"]); 63 } 64 65 public function preview() { 66 $this->episode = Episode::find_by_episode($this->params["id"]); 67 if (!$this->episode) 68 throw new \ActiveRecord\RecordNotFound("can't find episode " 69 . $this->params["id"]); 70 71 $this->next_episode = Episode::find_by_episode_and_is_pending( 72 $this->episode->episode + 1, false); 73 if ($this->episode->episode > 0) 74 $this->prev_episode = Episode::find_by_episode( 75 $this->episode->episode - 1); 76 77 $this->page_title = $this->episode->episode . ": " 78 . $this->episode->title; 79 80 return $this->render(array("html" => 81 "<div class=\"episodes\">" 82 . $this->render_to_string(array("action" => HALFMOON_ROOT 83 . "/views/episodes/_episode"), array("episode" => $this->episode)) 84 . "</div><hr>", "layout" => "application")); 85 } 86 87 public function update() { 88 $this->episode = Episode::find_by_episode($this->params["id"]); 89 90 if ($_FILES["episode"]["name"]["new_mp3"]) 91 $this->episode->take_new_mp3($_FILES["episode"]["tmp_name"]["new_mp3"]); 92 93 if ($this->episode->update_attributes($this->params["episode"])) { 94 $this->add_flash_success("Successfully updated episode " . 95 h($this->episode->episode)); 96 97 if ($this->episode->needs_chapter_updating) 98 $this->add_flash_success("Updated chapters in MP3 file"); 99 100 $this->flush_cache(); 101 102 return $this->redirect_to(ADMIN_ROOT_URL . "episodes/edit/" 103 . $this->episode->episode); 104 } 105 else { 106 return $this->render(array("action" => "edit")); 107 } 108 } 109 110 public function md_preview() { 111 $this->episode = new Episode(); 112 $this->episode->notes = $this->params["preview_text"]; 113 114 return $this->render(array("partial" => "preview", "layout" => false)); 115 } 116 117 public function tweet() { 118 $json = json_decode(Twitter::oauth_request("/1.1/statuses/update.json?" 119 . "include_entities=1&wrap_links=true", "POST", 120 array("status" => $this->params["tweet"])), true); 121 122 if ($json["id"]) { 123 $tweet = "https://twitter.com/" 124 . Settings::fetch()->twitter_username . "/status/" 125 . $json["id"]; 126 127 $this->add_flash_success(raw("Successfully Tweeted: <a href=\"" 128 . $tweet . "\" target=\"_blank\">" . $tweet . "</a>")); 129 } 130 else { 131 \HalfMoon\Log::error_log_r($json); 132 $this->add_flash_error("Could not send tweet"); 133 } 134 135 return $this->redirect_to(ADMIN_ROOT_URL); 136 } 137} 138 139?>