(Post_Serving);
}
///
/// An event that handles ServingEventArgs
///
///
///
private void Post_Serving(object sender, ServingEventArgs e)
{
if (!string.IsNullOrEmpty(e.Body))
{
// only process the posts
if (e.Location == ServingLocation.PostList || e.Location == ServingLocation.SinglePost)
{
string regex = @"\[flv:.*?\.flv]";
MatchCollection matches = Regex.Matches(e.Body, regex);
if (matches.Count > 0)
{
//AddJsToTheHeader();
string filename = string.Empty;
string filepath = string.Empty;
string player = string.Empty;
foreach (Match match in matches)
{
filename = match.Value.Replace("[flv:", "").Replace("]", "").Trim();
player = PlayerObject(filename);
//player = "";
e.Body = e.Body.Replace(match.Value, player);
}
}
}
}
}
///
/// Inject JavaScript file into the header of the post
///
private void AddJsToTheHeader()
{
// get a page handler
System.Web.UI.Page pg = (System.Web.UI.Page)HttpContext.Current.CurrentHandler;
bool added = false;
// check if script already added to the page header
foreach (Control ctl in pg.Header.Controls)
{
if (ctl.GetType() == typeof(HtmlGenericControl))
{
HtmlGenericControl gc = (HtmlGenericControl)ctl;
if (gc.Attributes["src"] != null)
{
if (gc.Attributes["src"].Contains(_jsfile))
{
added = true;
}
}
}
}
if (!added)
{
HtmlGenericControl js = new HtmlGenericControl("script");
js.Attributes.Add("type", "text/javascript");
js.Attributes.Add("src", AudioRoot() + _jsfile);
pg.Header.Controls.Add(js);
}
}
///
/// Build object tag
///
/// Name of the mp3 file ("my song.mp3")
/// Flash object markup
private string PlayerObject(string soundFile)
{
string sFile = string.Empty;
string[] sFiles = soundFile.Split(",".ToCharArray());
foreach (string file in sFiles)
{
if (file.Substring(0, 7) == "http://")
{
sFile += file;
}
else
{
sFile += AudioRoot() + file;
}
sFile += ",";
}
sFile = sFile.Substring(0, sFile.Length - 1);
sFile = HttpUtility.UrlEncode(sFile);
string s = ""
+ ""
+ "
";
_cnt++;
return String.Format(s, AudioRoot(), _cnt, sFile);
}
///
/// Virtual path to audio folder
///
/// Path to the audio folder
private string AudioRoot()
{
string VirtualPath = HttpContext.Current.Request.Path;
string audioRoot = VirtualPath.Substring(0, VirtualPath.LastIndexOf("/") + 1) + _audioroot;
return audioRoot;
}
}