Скрипт для навигации по-умолчанию
Code: Select all
const
csPageHeader = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'#13#10 +
'<html xmlns="http://www.w3.org/1999/xhtml">'#13#10 +
'<head>'#13#10 +
'<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'#13#10 +
'<link href="/presentation/css/styles1.css" rel="stylesheet" type="text/css"/>'#13#10 +
'<title>Домашний медиа-сервер (UPnP, DLNA) - %s</title>'#13#10 +
'</head>'#13#10 +
'<body>'#13#10 +
'<img class="imagelogo" src="/presentation/images/hms48x48.png" align="left"/>'#13#10 +
'<br/><h1>%s</h1><br/>'#13#10;
csPageFooter = '<p class="copyright">'#13#10 +
'<a class="copyright" title="Домашний медиа-сервер (UPnP, DLNA)" href="http://www.homemediaserver.ru">'#13#10 +
''#13#10 +
'Домашний медиа-сервер (UPnP, DLNA)</a>'#13#10 +
'<br/><a class="copyright" title="Copyright © 2008-2015 Evgeny Lachinov" href="http://www.homemediaserver.ru">'#13#10 +
''#13#10 +
'Copyright © 2008-2015 Evgeny Lachinov</a>'#13#10 +
'</p>'#13#10 +
'</body>'#13#10 +
'</html>'#13#10;
csUrlTemplate = '/MediaServer/Folders/%s?start=%d;count=%d';
procedure WriteString(const aStr: string);
begin
if aStr <> '' then
WebPageText := WebPageText + aStr
end;
procedure WriteLine(const aText: string);
begin
WriteString(aText + #13#10)
end;
procedure WriteImage(const aImage, aImageClass, aHint: string; aWidth, aHeight: Integer);
var
sWidthHeight: string;
begin
if (aWidth > 0) and (aHeight > 0) then
sWidthHeight := Format(' width=%d height=%d', [aWidth, aHeight])
else
sWidthHeight := '';
WriteString(Format('<img class="%s" src="%s" alt="%s" hspace=2%s/>',
[aImageClass, aImage, HmsHtmlEncode(aHint), sWidthHeight]));
end;
procedure WriteLink(const aTitle, aTitleClass, aLink, aImage, aImageClass: string;
aImageWidth, aImageHeight: Integer; aImageOnly: Boolean = False);
begin
if (aImage <> '') and not aImageOnly then
WriteImage(aImage, aImageClass, aTitle, aImageWidth, aImageHeight);
WriteLine(Format('<a class="' + aTitleClass + '" title="%s" href="%s">', [HmsHtmlEncode(aTitle), aLink]) + #13#10);
if aImageOnly then
WriteImage(aImage, aImageClass, aTitle, aImageWidth, aImageHeight)
else
WriteString(HmsHtmlEncode(aTitle));
WriteLine('</a>');
end;
function GetCountClass(aCurrent: Boolean): string;
begin
if aCurrent then
Result := 'a'
else
Result := ''
end;
function GetCountValue(aIndex: Integer): Integer;
begin
case aIndex of
0: Result := 5;
1: Result := 10;
2: Result := 15;
3: Result := 20;
4: Result := 50;
else
Result := 0
end
end;
function GetCountLabel(aIndex: Integer): string;
var
iCount: Integer;
begin
iCount := GetCountValue(aIndex);
if iCount = 0 then
Result := 'Все'
else
Result := IntToStr(iCount)
end;
procedure WriteHeader;
var
i: Integer;
FolderItem: THmsScriptMediaItem;
FolderList: TList;
sWebLink: string;
begin
WriteString(Format(csPageHeader, [ServerName, ServerName]));
if CurrentMediaItem <> nil then begin
FolderList := TList.Create;
try
FolderItem := CurrentMediaItem;
while FolderItem <> nil do begin
FolderList.Add(FolderItem);
FolderItem := FolderItem.ItemParent;
end;
WriteLine('<div>');
for i := FolderList.Count - 1 downto 0 do begin
FolderItem := THmsScriptMediaItem(FolderList[i]);
sWebLink := FolderItem.WebLink(FolderItem);
sWebLink := sWebLink + Format('?start=0;count=%d', [RequestItemCount]);
WriteLink(FolderItem.Properties[mpiTitle], 'history',
sWebLink, '/presentation/images/bulletgreen8.png', 'imagehistory', 0, 0);
end;
WriteLine('</div>');
WriteLine('<br/><div>' + 'Строк на странице: ');
for i := 0 to 5 do
WriteLink(GetCountLabel(i), 'itemcount' + GetCountClass(GetCountValue(i) = RequestItemCount),
Format(csUrlTemplate, [CurrentMediaItem.ItemID, 0, GetCountValue(i)]), '', '', 0, 0);
WriteLine('</div>')
finally
FolderList.Free
end
end
end;
procedure WriteBody;
var
i, iEnd, iImageWidth, iImageHeight: Integer;
Item: THmsScriptMediaItem;
sImageLink, sWebLink: string;
begin
if CurrentMediaItemList <> nil then begin
if RequestItemCount = 0 then
iEnd := CurrentMediaItemList.Count
else
iEnd := Min(CurrentMediaItemList.Count, RequestItemStart + RequestItemCount);
if iEnd > RequestItemStart then begin
WriteLine('<ul>');
if RequestItemStart = 0 then begin
Item := nil;
for i := 0 to CurrentMediaItemList.Count - 1 do begin
Item := CurrentMediaItemList[i];
if Item.IsFolder or (Item.MediaType = mtImage) or Item.IsServiceItem or
(Item.ItemOrigin.MediaType = mtImage) or Item.ItemOrigin.IsServiceItem then
Item := nil
else
Break
end;
if Item <> nil then begin
WriteLine('<li>');
sWebLink := Item.ItemOrigin.WebLink(Item.ItemParent);
sImageLink := '/presentation/images/note24.png';
WriteLink('Воспроизведение Всех', 'medialist', sWebLink, sImageLink, 'imagelist', 0, 0);
WriteLine('</li>');
end
end;
for i := RequestItemStart to iEnd - 1 do begin
Item := CurrentMediaItemList[i];
WriteLine('<li>');
sWebLink := Item.WebLink(Item);
if Item.IsFolder then
sWebLink := sWebLink + Format('?start=0;count=%d', [RequestItemCount]);
if HmsThumbnailsSupported(Item.MediaType) and cfgWebThumbnails and Item.ThumbnailExists then begin
sImageLink := '/MediaServer/WebThumbnails/' + Item.ThumbnailID;
iImageWidth := cfgWebThumbnailWidth;
iImageHeight := cfgWebThumbnailHeight;
end else begin
sImageLink := '/presentation/images/' + Item.WebImageName;
iImageWidth := 0; iImageHeight := 0;
end;
WriteLink(Item.Properties[mpiTitle], 'medialist', sWebLink,
sImageLink, 'imagelist', iImageWidth, iImageHeight);
WriteLine('</li>')
end;
WriteString('</ul>');
end
end
end;
function GetNavImageName(aIndex: Integer; aEnabled: Boolean): string;
begin
case aIndex of
0: Result := 'first24';
1: Result := 'previous24';
2: Result := 'next24';
3: Result := 'last24'
end;
if aEnabled then
Result := Result + '_h.png'
else
Result := Result + '_d.png'
end;
function GetNavLabel(aIndex: Integer): string;
begin
case aIndex of
0: Result := 'Первая страница';
1: Result := 'Предыдущая страница';
2: Result := 'Следующая страница';
3: Result := 'Последняя страница';
end;
end;
procedure WriteFooter;
var
i, iPageNo, iPageCount: Integer;
procedure WriteNavLink(aIndex: Integer);
var
bEnabled: Boolean;
iStart: Integer;
sImage: string;
begin
iStart := RequestItemStart;
case aIndex of
0: iStart := 0;
1: if (iPageNo > 1) and (RequestItemCount > 0) then
iStart := (iPageNo - 2) * RequestItemCount;
2: if (iPageNo < iPageCount) and (RequestItemCount > 0) then
iStart := iPageNo * RequestItemCount;
3: iStart := (iPageCount - 1) * RequestItemCount
end;
if aIndex in [0..1] then
bEnabled := iPageNo > 1
else
bEnabled := iPageNo < iPageCount;
sImage := '/presentation/images/' + GetNavImageName(aIndex, bEnabled);
if bEnabled and (CurrentMediaItem <> nil) then
WriteLink(GetNavLabel(aIndex), 'navigate', Format(csUrlTemplate, [CurrentMediaItem.ItemID, iStart, RequestItemCount]),
sImage, 'imagenavigate', 0, 0, True)
else
WriteImage(sImage, 'imagenavigate', GetNavLabel(aIndex), 0, 0)
end;
begin
if (CurrentMediaItemList <> nil) and (CurrentMediaItem <> nil) then begin
if RequestItemCount > 0 then begin
iPageNo := (RequestItemStart div RequestItemCount) + 1;
iPageCount := ((CurrentMediaItemList.Count - 1) div RequestItemCount) + 1;
end else begin
iPageNo := 1;
iPageCount := 1;
end;
WriteLine('<div>');
for i := 0 to 1 do
WriteNavLink(i);
WriteLine(Format('Страница %d из %d', [iPageNo, iPageCount]));
for i := 2 to 3 do
WriteNavLink(i);
WriteLine('</div>')
end;
WriteString(csPageFooter)
end;
begin
WebPageText := '';
WriteHeader;
WriteBody;
WriteFooter;
WebPageText := HmsUtf8Encode(WebPageText)
end.