Esempio n. 1
15
 /**
  * Emits list of links to all songs in the directory.
  * @method buildFileList
  * @return (song array)
  */
 private function buildFileList($files)
 {
     $list = new SongListPlus_Pvm();
     foreach ($files as $fname) {
         $s = preg_replace(Config::FileNamePattern, '$1', $fname);
         $content = FileHelper::getFile(Config::$SongDirectory . $fname);
         $parsed = SongHelper::parseSong($content);
         $song = new SongLinkPlus_Pvm();
         $song->Uri = Ugs::MakeUri(Actions::Song, $s);
         $song->HasInfo = strlen($parsed->title) + strlen($parsed->artist) > 0;
         $song->Title = $this->fixLeadingArticle(strlen($parsed->title) > 0 ? $parsed->title : $this->filenameToTitle($s));
         $song->Subtitle = $parsed->subtitle;
         $song->Album = $parsed->album;
         $song->Artist = $parsed->artist;
         $list->SongList[] = $song;
     }
     return $list->Sort();
 }
Esempio n. 2
0
 public function Build()
 {
     $viewModel = new JsonResponse_Vm();
     $viewModel->HasErrors = true;
     if (!$this->SiteUser->MayEdit || !$this->SiteUser->IsAuthenticated) {
         return $viewModel;
     }
     if ($_SERVER['REQUEST_METHOD'] != "POST") {
         return $viewModel;
     }
     $json = Ugs::GetJsonObject();
     $viewModel->Id = $json->filename;
     $song = $json->song;
     if (strlen($viewModel->Id) < 1 || strlen($song) < 1) {
         $viewModel->Message = 'JSON data is missing.';
         return $viewModel;
     }
     $fullFilePath = Config::$SongDirectory . $viewModel->Id;
     if (!file_exists($fullFilePath)) {
         $viewModel->Message = 'Song file not found; can\'t update.';
         return $viewModel;
     }
     file_put_contents($fullFilePath, $song);
     $viewModel->HasErrors = false;
     $viewModel->Message = 'Success!';
     return $viewModel;
 }
Esempio n. 3
0
 function __construct()
 {
     parent::__construct();
     $title = defined('Config::SongbookHeadline') ? Config::SongbookHeadline : 'The BIG UKE Book';
     $this->EditAjaxUri = Ugs::MakeUri(Actions::AjaxNewSong);
     $this->LogoutUri = Ugs::MakeUri(Actions::Logout);
     $this->Headline = $title;
     $this->SubHeadline = defined('Config::SongbookSubHeadline') ? Config::SongbookSubHeadline : 'Sample Styled Songbook &raquo;';
     $this->PageTitle = $title . ' ' . Config::PageTitleSuffix;
 }
Esempio n. 4
0
 /**
  * Populates SongList View Model by reading and parsing filenames in the source directory
  * @return SongList_Vm
  */
 public function Build()
 {
     $files = FileHelper::getFilenames(Config::$SongDirectory);
     $viewModel = new SongList_Vm();
     foreach ($files as $filename) {
         // Parse the filename (to make a Title) and create URL.
         $s = preg_replace(Config::FileNamePattern, '$1', $filename);
         $viewModel->Add($this->getTitle($s), Ugs::MakeUri(Actions::Song, $s));
     }
     $viewModel->Sort();
     return $viewModel;
 }
Esempio n. 5
0
 /**
  * Parses file (using URL query param) and attempts to load View Model
  * @return Song_Vm
  */
 public function Build()
 {
     $filename = FileHelper::getFilename();
     $fileContent = FileHelper::getFile(Config::$SongDirectory . $filename);
     $song = SongHelper::parseSong($fileContent);
     $title = htmlspecialchars($song->isOK ? $song->title . (strlen($song->subtitle) > 0 ? ' | ' . $song->subtitle : '') : 'Not Found');
     $viewModel = new Song_Vm();
     $viewModel->PageTitle = $this->MakePageTitle($song, $filename);
     $viewModel->SongTitle = htmlspecialchars($song->title);
     $viewModel->Subtitle = htmlspecialchars($song->subtitle);
     $viewModel->Artist = $song->artist;
     $viewModel->Album = $song->album;
     // htmlspecialchars();
     $viewModel->Body = $song->body;
     $viewModel->UgsMeta = $song->meta;
     $viewModel->SourceUri = Ugs::MakeUri(Actions::Source, $filename);
     $viewModel->EditUri = Ugs::MakeUri(Actions::Edit, $filename);
     $viewModel->Id = $filename;
     $viewModel->IsUpdateAllowed = $this->SiteUser->MayEdit && $this->SiteUser->IsAuthenticated;
     $viewModel->EditorSettingsJson = $this->getSettings();
     return $viewModel;
 }
Esempio n. 6
0
 private function CreateSongFile($title, $artist, $viewModel)
 {
     if (strlen($title) < 1) {
         $viewModel->HasErrors = true;
         $viewModel->Message = 'Song title is required, sorry.';
         return false;
     }
     try {
         $fWriter = new FileWriter();
         $viewModel->Id = $fWriter->MakeFile($title, $artist);
         $viewModel->HasErrors = strlen($viewModel->Id) < 1;
         if ($viewModel->HasErrors) {
             $viewModel->Message = '(e:803) Something\'s gone wrong whilst saving.';
             return false;
         }
     } catch (Exception $e) {
         $viewModel->Message = '(e:805) Something\'s gone wrong whilst saving.';
         return false;
     }
     $viewModel->ContinueUri = Ugs::MakeUri(Actions::Edit, $viewModel->Id);
     return true;
 }
Esempio n. 7
0
 function __construct()
 {
     parent::__construct();
     $this->SongbooktUri = Ugs::MakeUri(Actions::Songbook);
 }
Esempio n. 8
0
 function __construct()
 {
     parent::__construct();
     $this->FormPostUri = Ugs::MakeUri(Actions::Login);
 }
Esempio n. 9
0
 function __construct()
 {
     parent::__construct();
     $this->UpdateAjaxUri = Ugs::MakeUri(Actions::AjaxUpdateSong);
 }