Wild media server (UPnP, DLNA, HTTP)
http://wildmediaserver.com/forum/

Default script for Web-navigation pages
http://wildmediaserver.com/forum/viewtopic.php?f=19&t=742
Page 1 of 1

Author:  Eugene [ Sat Nov 06, 2010 10:37 am ]
Post subject:  Default script for Web-navigation pages

Version 1.07.1 (http://www.wildmediaserver.com/forum/vi ... f=19#p4269) adds the ability to use a script to create Web-navigation pages (Settings - Devices - your device - Settings - Additional - "Web-navigation" - Script)

Default script (required version 1.72)
Code:
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="%spresentation/css/styles1.css" rel="stylesheet" type="text/css"/>'#13#10 +
                 '<title>Wild Media Server (UPnP, DLNA, HTTP) - %s</title>'#13#10 +
                 '</head>'#13#10 +
                 '<body>'#13#10 +
                 '<img class="imagelogo" src="%spresentation/images/wms48x48.png" align="left"/>'#13#10 +
                 '<br/><h1>%s</h1><br/>'#13#10;
  csPageFooter = '<p class="copyright">'#13#10 +
                 '<a class="copyright" title="Wild Media Server (UPnP, DLNA, HTTP)" href="http://www.wildmediaserver.com">'#13#10 +
                 ''#13#10 +
                 'Wild Media Server (UPnP, DLNA, HTTP)</a>'#13#10 +
                 '<br/><a class="copyright" title="Copyright © 2009-2015 Evgeny Lachinov" href="http://www.wildmediaserver.com">'#13#10 +
                 ''#13#10 +
                 'Copyright © 2009-2015 Evgeny Lachinov</a>'#13#10 +
                 '</p>'#13#10 +
                 '</body>'#13#10 +
                 '</html>'#13#10;                 

  csRuntimeMessages = 'WmsRuntimeMessages';

  csUrlTemplate   = '%sMediaServer/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, WmsHtmlEncode(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">', [WmsHtmlEncode(aTitle), aLink]) + #13#10);
  if aImageOnly then
    WriteImage(aImage, aImageClass, aTitle, aImageWidth, aImageHeight)
  else
    WriteString(WmsHtmlEncode(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 := WmsLocalizationString(csRuntimeMessages, 'rsWebRowsPerPageAll', 'All')   
  else 
    Result := WmsLocalizationString(csRuntimeMessages, 'rsWebRowsPerPage' + IntToStr(iCount), IntToStr(iCount))   
end;

procedure WriteHeader;
var
  i: Integer;
  FolderItem: TWmsScriptMediaItem;
  FolderList: TList;
  sWebLink: string;
begin
  WriteString(Format(csPageHeader, [ServerRootFolder, ServerName, ServerRootFolder, 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 := TWmsScriptMediaItem(FolderList[i]);
        sWebLink := FolderItem.WebLink(FolderItem);
        sWebLink := sWebLink + Format('?start=0;count=%d', [RequestItemCount]);
        WriteLink(FolderItem.Properties[mpiTitle], 'history',
               sWebLink, ServerRootFolder + 'presentation/images/bulletgreen8.png', 'imagehistory', 0, 0);
      end;
      WriteLine('</div>');
      WriteLine('<br/><div>' + WmsLocalizationString(csRuntimeMessages, 'rsWebRowsOnPage', 'Lines per page: '));
      for i := 0 to 5 do
        WriteLink(GetCountLabel(i), 'itemcount' + GetCountClass(GetCountValue(i) = RequestItemCount),
                  Format(csUrlTemplate, [ServerRootFolder, CurrentMediaItem.ItemID, 0, GetCountValue(i)]), '', '', 0, 0);
      WriteLine('</div>')
    finally
      FolderList.Free
    end
  end
end;

procedure WriteBody;
var
  i, iEnd, iImageWidth, iImageHeight: Integer;
  Item: TWmsScriptMediaItem;
  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 := ServerRootFolder + 'presentation/images/note24.png';
          WriteLink(WmsLocalizationString(csRuntimeMessages, 'rsWebPlayAll', 'Play All'), '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 WmsThumbnailsSupported(Item.MediaType) and cfgWebThumbnails and Item.ThumbnailExists then begin
          sImageLink := ServerRootFolder + 'MediaServer/WebThumbnails/' + Item.ThumbnailID;
          iImageWidth  := cfgWebThumbnailWidth;
          iImageHeight := cfgWebThumbnailHeight;
        end else begin
          sImageLink := ServerRootFolder + '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 := WmsLocalizationString(csRuntimeMessages, 'rsWebNavFirstPage', 'First Page');
    1: Result := WmsLocalizationString(csRuntimeMessages, 'rsWebNavPrevPage',  'Previous Page');
    2: Result := WmsLocalizationString(csRuntimeMessages, 'rsWebNavNextPage', 'Next Page');
    3: Result := WmsLocalizationString(csRuntimeMessages, 'rsWebNavLastPage', 'Last Page');   
  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 := ServerRootFolder + 'presentation/images/' + GetNavImageName(aIndex, bEnabled);
    if bEnabled and (CurrentMediaItem <> nil) then
      WriteLink(GetNavLabel(aIndex), 'navigate', Format(csUrlTemplate, [ServerRootFolder, 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(WmsLocalizationString(csRuntimeMessages, 'rsWebPageNo', 'Page %d of %d'), [iPageNo, iPageCount]));
    for i := 2 to 3 do
      WriteNavLink(i);
    WriteLine('</div>')
  end;

  WriteString(csPageFooter)
end;

begin
  WebPageText := '';
  WriteHeader; 
  WriteBody;
  WriteFooter;     
  WebPageText := WmsUtf8Encode(WebPageText)
end.

Author:  ds1001 [ Sun Sep 11, 2011 6:02 pm ]
Post subject:  Re: Default script for Web-navigation pages

Does this feature work for a Samsung TV? Do i have to buy and get the license before it will work or should it be working in the demo?

Author:  Eugene [ Sun Sep 11, 2011 6:11 pm ]
Post subject:  Re: Default script for Web-navigation pages

Web-navigation is free of charge

Author:  ds1001 [ Sun Sep 11, 2011 6:41 pm ]
Post subject:  Re: Default script for Web-navigation pages

How does it work. I installed the default script but i don't see anything on my TV suggesting web navigation. What should i be looking for on my TV?

Author:  Eugene [ Sun Sep 11, 2011 6:55 pm ]
Post subject:  Re: Default script for Web-navigation pages

The TV have Internet Browser ?

Author:  ds1001 [ Sun Sep 11, 2011 7:08 pm ]
Post subject:  Re: Default script for Web-navigation pages

That explains it. My Samsung doesn't have a browser. I was being too hopeful.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Limited
https://www.phpbb.com/