newsriverhacks.opml

Kosso NewsRiver hack for Checkbox toggling
  newsRiverSuite.viewNewsItems
    on viewNewsItems (adrargs=nil, ctStoriesToList=nil)
      Changes:
        10/16/05; 10:58:30 AM by DW
          Began work on this code after a long hiatus.
          Make it work inside the OPML Editor.
        31/12/05; 07:19:00 PM by Kosso
          Added checkbox id parameter and buttons.
          Calls Javascript placed in #template
      local (pta = html.getpagetableaddress ())
      scratchpad.newsparams = pta^
      pta^.title = newsRiverSuite.getString ("aggregator.title")
      local (uri = pta^.uri)
      local (adrdata = newsRiverSuite.init ())
      if ctStoriesToList == nil
        ctStoriesToList = adrdata^.newsRiver.ctStoriesOnNewsPage
      local (htmltext = "", indentlevel = 0)
      on add (s)
        htmltext = htmltext + (string.filledstring ("\t", indentlevel) + s + "\r\n");
      on decodeEntities (s)
        s = string.replaceAll (s, "\r\n", "\r")
        s = string.replaceAll (s, "\n", "\r")
        return (newsRiverSuite.decodeEntities (s, flNeuterJavaScript:false))
      local (flOneService = false, xmlUrl = "", adrservice)
      bundle //parse args
        local (args)
        new (tabletype, @args)
        webserver.parseArgs (pta^.searchArgs, @args)
        if defined (args.xmlUrl)
          flOneService = true
          xmlurl = args.xmlUrl
          adrservice = @adrdata^.services.[xmlurl]
          if defined (adrservice^.compilation.channeltitle) //avoid errors for non-compliant channels

            add ("Channel: " + decodeEntities (adrservice^.compilation.channeltitle) + "
            ")

            pta^.title = "Channel: " + decodeEntities (adrservice^.compilation.channeltitle)
      local (adrcache = @adrdata^.cache.[this], adrincache, defaultcachename = "default")
      if not defined (adrcache^) //make sure the cache table is defined
        new (tabletype, adrcache)
      bundle //set adrincache
        if adrdata^.newsRiver.flCacheNewsItemsPage
          local (cachename = defaultcachename)
          if sizeof (xmlUrl) > 0
            cachename = xmlUrl
          adrincache = @adrcache^.[cachename]
      bundle //catch post
        if pta^.method == "POST"
          local (args)
          new (tabletype, @args)
          webserver.parseArgs (pta^.requestBody, @args)
          scratchpad.args = args; edit (@scratchpad.args)
          if defined (args.formName)
            if string.lower (args.formName) == "editstories"
              delete (@args.formName)
              if defined (args.unsubscribe)
                local (args)
                new (tabletype, @args)
                args.xmlUrl = xmlUrl
                if defined (adrdata^.services.[xmlUrl])
                adrargs^.redirect = newsRiverData.systemUrls.unsub + "?" + webserver.encodeargs (@args)
                return ("")
              local (adrdefaultcache = @adrcache^.[defaultcachename])
              for adrarg in @args
                local (name = string.padwithzeros (number (nameof (adrarg^)), 8))
                local (adrstory = @adrdata^.stories.[name])
                if defined (adrstory^)
                adrdata^.trash.[name] = adrstory^
                delete (adrstory)
                if adrdata^.newsRiver.flCacheNewsItemsPage
                if defined (adrcache^)
                if defined (adrincache^) //posting invalidates the cache
                delete (adrincache)
                if adrdefaultcache == adrincache //02/24/2001 JES: delete the cache for the service
                if defined (adrstory^)
                local (adrservicecache = @adrcache^.["xmlUrl=" + string.urlEncode (adrstory^.url)])
                if defined (adrservicecache^)
                delete (adrservicecache)
                else //02/24/2001 JES: we're on the service page -- delete the default cache
                if defined (adrdefaultcache^)
                delete (adrdefaultcache)
      bundle //see if we can serve from the cache
        if defined (adrcache^)
          if defined (adrincache^)
            return (adrincache^)
      local (globeimg, xmlimg, searchimg, checkmarkimg, mediaimg, commentimg, postbuttonimg, permalinkimg)
      bundle //precalc img refs
        globeimg = dotOpmlSuite.mdiWindow.imageRef ("newsRiver/qbullet/remote")
        xmlimg = dotOpmlSuite.mdiWindow.imageRef ("newsRiver/icons/xml")
        searchimg = dotOpmlSuite.mdiWindow.imageRef ("newsRiver/qbullet/search")
        checkmarkimg = dotOpmlSuite.mdiWindow.imageRef ("newsRiver/icons/checkmark")
        postbuttonimg = dotOpmlSuite.mdiWindow.imageRef ("newsRiver/icons/post")
        mediaimg = dotOpmlSuite.mdiWindow.imageRef ("newsRiver/qbullet/sound")
        commentimg = dotOpmlSuite.mdiWindow.imageRef ("newsRiver/icons/pencil")
        permalinkimg = dotOpmlSuite.mdiWindow.imageRef ("newsRiver/icons/itemPermalink")
      add (""); indentlevel++
      add ("") //PBS 01/11/01: name the form, so the script doesn't try to process some other script's form

      add ("

      ")

      bundle //message at the top of the page
        if flOneService
          local (t)
          new (tabletype, @t)
          t.channeltitle = decodeEntities (adrservice^.compilation.channeltitle)
          add (newsRiverSuite.getString ("aggregator.oneChannelMessage", @t))
          pta^.title = t.channeltitle
        else
          local (t)
          new (tabletype, @t)
          t.subscriptionurl = newsRiverData.systemUrls.subscriptionList
          add (newsRiverSuite.getString ("aggregator.standardMessage", @t))
        add (newsRiverSuite.getString ("aggregator.clickThePostButton"))
        if adrdata^.newsRiver.flNewsPageDeleteCheckboxesDefault
          add (newsRiverSuite.getString ("aggregator.checkBoxesOnIntro"))
        else
          add (newsRiverSuite.getString ("aggregator.checkBoxesOffIntro"))
        if flOneService
          add (newsRiverSuite.getString ("aggregator.howToUnsubscribe"))
      local (adrtable = @adrdata^.stories, sizetable = sizeof (adrtable^), i)
      Kosso : 123105 : Added Javascript Checkbox toggle
      add (""); indentlevel++
      /Kosso

      add ("

      "); indentlevel++

      add ("
      "); indentlevel++

      local (lastchanneltitle = "", ctstories = 0)
      bundle //loop over the news items
        for i = sizetable downto 1
          local (adritem = @adrdata^.stories [i])
          bundle //skip missing or empty stories
            if not defined (adritem^.storyText) //skip this story -- this can happen if the scan is interrupted
              continue
            if (string.trimWhiteSpace (searchEngine.stripMarkup (adrItem^.storyText)) == "") and (not (string.lower (adrItem^.storyText) contains "<img ")) //PBS 02/12/01: skip empty stories
              continue
          if flOneService
            local (flskip = true)
            if adritem^.url == xmlUrl
              flskip = false
            if flskip
              continue
          bundle //only show items with enclosures after the enclosure has been downloaded
            if defined (adritem^.enclosure)
              if not defined (adritem^.enclosure.f)
                if string.lower (adritem^.url) != "local" //I want to see my local items with enclosures
                continue
          local (adrservice = @adrdata^.services.[adritem^.url])
          if not defined (adrservice^)
            continue
          ctstories++
          if ctstories > ctStoriesToList
            break
          if adritem^.channeltitle != lastchanneltitle //display channel title
            local (globe = "")
            try //link the globe to the HTML rendering of the channel
              with adrservice^.compilation
                local (desc = searchengine.stripmarkup (channeldescription))
                globe = "" + globeimg + "" //PBS 02/12/01: fix bug where quotes and carets in a channel description would mess up rendering -- an example was Dave Winer: Two-Way Web, which has a description of You're soaking in it! ";->"
            local (xmllink)
            bundle //link the XML icon to the source XML file for the channel
              xmllink = "" + xmlimg + ""
            local (magglass = "")
            bundle //load up the magnifying glass with some HTML
              if not flOneService
                local (url, args)
                new (tabletype, @args)
                args.xmlUrl = adritem^.url
                url = "?" + webserver.encodeArgs (@args)
                magglass = " " + searchimg + ""

            add ("

            " + globe + " " + decodeEntities (adrItem^.channelTitle) + ", " + adritem^.time + "." + magglass + "

            " + xmllink + "

            ")

            lastchanneltitle = adritem^.channeltitle
          bundle //add story

            add ("
            "); indentlevel++

            bundle //add checkbox
              local (checkboxtext = " ")
              if adrdata^.newsRiver.flItemCheckboxes
                local (name = number (nameof (adritem^)))
                local (checkboxval = "xxx ")
                if adrdata^.newsRiver.flNewsPageDeleteCheckboxesDefault
                checkboxval = checkboxval
                Kosso : 123105 : Added checkbox id parameter
                checkboxtext = ""

              add ("
              " + checkboxtext + "
              ")

            add ("

            " + adritem^.storytext + "

            ")

            bundle //add POST button, checkmark
              local (url)
              bundle //set url
                local (args); new (tabletype, @args)
                if adrdata^.newsRiver.flNewsPageReturnAfterPost //add referer arg to redirect back to this item after posting it to your weblog
                if pta^.searchargs != ""
                args.referer = uri + "?" + pta^.searchargs + "#" + i
                else
                args.referer = uri + "#" + i
                args.idStory = number (nameof (adritem^))
                url = newsRiverData.systemUrls.postToWeblog + "?" + webserver.encodeArgs (@args)
              local (checkmark = "", enclosure = "", comments = "", permalink = "")
              bundle //an item has a checkmark if it's been blogged
                if defined (adritem^.adrBlogPost)
                checkmark = " " + checkmarkimg + ""
              bundle //if it has an enclosure add a media link
                if defined (adritem^.enclosure)
                if not defined (adritem^.enclosure.error)
                local (url)
                if defined (adritem^.enclosure.f)
                url = html.getfileurl (adritem^.enclosure.f)
                else
                url = adritem^.enclosure.url
                enclosure = " " + mediaimg + ""
              bundle //if it has comments add a comment link
                if defined (adritem^.comments)
                local (onclick = "window.open (this.href, \'comments\', \'width=515, height=480, location=0, resizable=1, scrollbars=1, status=0, toolbar=0, directories=0\'); return(false);")
                local (tooltip = newsRiverSuite.getString ("misc.clickToCommentOnThisPost"))

                comments = "
                " + commentimg + "
                "

              bundle //if it has permalink add a permalink link
                if defined (adritem^.permalink)
                permalink = "" + permalinkimg + ""
              local (icons = "")
              bundle //set icons
                if (sizeof (checkmark) > 0) or (sizeof (enclosure) > 0) or (sizeof (permalink) > 0) or (sizeof (comments) > 0)

                icons = "
                " + comments + checkmark + enclosure + permalink + "
                "

              add ("
              " + postbuttonimg + "" + icons + "
              ")

            add ("
            "); indentlevel--

      if ctstories == 0

        add ("

        " + newsRiverSuite.getString ("viewNewsItems.noStories") + "

        ")

      add ("
      "); indentlevel--

      add ("
      "); indentlevel--

      local (flDeleteButtonAdded = false)
      if flOneService
        if defined (adrservice^)

          add ("

          ")

          flDeleteButtonAdded = true
      if not flDeleteButtonAdded
        Kosso 123105 : Added Javascript Checkbox toggle

        add ("

        ")

        /Kosso
      add (""); indentlevel--
      if adrdata^.newsRiver.flCacheNewsItemsPage
        adrincache^ = htmltext
      return (htmltext)
  #template
        Kosso's NewsRiver: {title}
        {metaTags ()}
        comment?
          var checkflag = 'false';
          function check(field) \{
            if (checkflag == 'false') \{
              for (i = 0; i < field.length; i++) {
                field[i].checked = true;
              }
              checkflag = 'true';
              return 'Uncheck All';
          } else {
            for (i = 0; i < field.length; i++) {
              field[i].checked = false;
            }
            checkflag = 'false';
            return 'Check All';
          }
          }
      {bodyTag ()}
          Kosso's NewsRiver: {title}
          {bodytext}