function postSong_flags($overwriteIfExists, $artist, $song, $lyrics, $onAlbums, $flags = "") { return postSong($overwriteIfExists, $artist, $song, $lyrics, $onAlbums, $flags); }
/** * Rest endpoint for creating/updating a song page via the postSong() method. * * The array of onAlbums can either contain strings (of album names) or arrays with keys * 'artist', 'album', and 'year'. Technically the array is a safer way to go since the * parsing will be thrown off by artists with colons in their name. */ function rest_postSong($overwriteIfExists, $artist, $song, $lyrics, $onAlbums, $language, $fmt) { if (empty($fmt)) { $fmt = 'html'; } // Split each item in onAlbums into artist/album/year. for ($cnt = 0; $cnt < count($onAlbums); $cnt++) { $album = $onAlbums[$cnt]; if (!is_array($album)) { $matches = array(); // Parse the album parts out of the string. if (0 < preg_match("/^(.*?):(.*)[ _]\\(([0-9]{4})\\)\$/i", $album, $matches)) { $albumArtist = $matches[1]; $albumAlbum = $matches[2]; $albumYear = $matches[3]; } else { if (0 < preg_match("/^(.*)[ _]\\(([0-9]{4})\\)\$/i", $album, $matches)) { $albumArtist = $artist; $albumAlbum = $matches[1]; $albumYear = $matches[2]; } else { // TODO: HOW DO WE HANDLE AN ALBUM THAT DOESN'T PARSE? (basically means that there was no Year found) $albumArtist = $albumAlbum = $albumYear = ""; } } $onAlbums[$cnt] = array('artist' => $albumArtist, 'album' => $albumAlbum, 'year' => $albumYear); } } $result = postSong($overwriteIfExists, $artist, $song, $lyrics, $onAlbums, "", $language); switch ($fmt) { case 'php': print serialize($result); break; case 'text': // TODO: IMPLEMENT // TODO: IMPLEMENT break; case 'xml': header('Content-Type: application/xml', true); print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; $result = array("postSongResponse" => $result); $this->dumpXml_hacky($result); break; case 'json': case 'realjson': $this->writeRealJSON($result); break; case 'html': default: // TODO: IMPLEMENT // TODO: IMPLEMENT /* $result = getHometown($artist); $hometown = getVal($result, 'hometown'); $state = getVal($result, 'state'); $country = getVal($result, 'country'); $this->htmlHead("$artist:$song posted"); print "<h3><a href='$this->root".$this->linkEncode($artist)."'>$artist</a></h3>\n"; print "<ul>\n"; print "<li>Hometown: <a href='{$this->root}Category:Hometown/$country/$state/$hometown'>$hometown</a></li>\n"; print "<li>State: <a href='{$this->root}Category:Hometown/$country/$state'>$state</a></li>\n"; print "<li>Country: <a href='{$this->root}Category:Hometown/$country'>$country</a></li>\n"; print "</ul>\n"; print "</body>\n</html>\n"; */ break; } // TODO: IMPLEMENT /* // NOTE: THIS IS CODE FROM THE SOAP CLIENT. // If the artist is left blank it defaults to the artist of the song. Left out here to conserve space. //$onAlbums[] = array('artist'=>'', 'album'=>'Another Happy Ending', 'year' => 2002); //$onAlbums[] = array('artist'=>'', 'album'=>'Between Now And Then - Retrospective', 'year' => 2005); //$onAlbums[] = array('artist'=>'', 'album'=>'Still Live', 'year' => 2006); // My version of nuSOAP seems to have a problem with nested arrays. This compensates by converting the sub-array to a string initially. $onAlbums[] = albumResult('', "Another Happy Ending", 2002); $onAlbums[] = albumResult('Pittsburgh Rock Compilation', "Between Now And Then - Retrospective", 2005); $onAlbums[] = albumResult('', "Still Live", 2006); $onAlbums = array(); $overwriteIfExists = true; $result = $proxy->postSong($overwriteIfExists, $artist, $song, $lyrics, $onAlbums); function albumResult($artist, $album, $year){ return "<artist xsi:type=\"xsd:string\">$artist</artist><album xsi:type=\"xsd:string\">$album</album><year xsi:type=\"xsd:int\">$year</year>"; } */ }