Loading ...
Sorry, an error occurred while loading the content.

Re: [SimplePie] How to do item paging?

Expand Messages
  • Ryan Parman
    http://simplepie.pastebin.com/m33410d3b doesn t exist anymore. Can you re-post it? -- Ryan Parman
    Message 1 of 7 , Nov 30, 2008
    View Source
    • 0 Attachment
      http://simplepie.pastebin.com/m33410d3b doesn't exist anymore. Can you
      re-post it?

      --
      Ryan Parman
      <http://ryanparman.com>







      On Nov 20, 2008, at 8:55 AM, ojsimon3000 wrote:

      > Hi
      >
      > I am wanting to do as in this tutorial
      >
      > http://simplepie.org/wiki/tutorial/how_to_do_item_paging
      >
      > however the code i am running is different. I have tried putting
      > bits of the
      > code together but
      > with only basic php skills have been unable to make it work. Here is
      > my code, I
      > would really appreciate any advice or help from anyone
      >
      > http://simplepie.pastebin.com/m33410d3b?
      >
      > Thanks
      >
      >
      > ------------------------------------
      >
      > Yahoo! Groups Links
      >
      >
      >
    • ojsimon3000
      Pastebin is not working now. here is the code
      Message 2 of 7 , Dec 2, 2008
      View Source
      • 0 Attachment
        Pastebin is not working now. here is the code


        <?php
        /*
        Here is the sequence:
        1. Initialize SP
        2. Store required feed data into an array.
        2. Sort array with your custom sort.
        3. Loop and display your newly sorted items.
        */
        require_once('simplepie.inc');
        $feed = new SimplePie();
        $feed->set_feed_url(array(
        'http://gdata.youtube.com/feeds/api/videos?q=seeing%20doc',
        'http://www.metacafe.com/tags/seeing%20doc/relevance/rss.xml',
        'http://rss.break.com/keyword/nokia/',
        ));
        $feed->init();
        if($feed->error)
        exit('<p>'.$feed->error().'</p>');
        $feed->handle_content_type();
        $sp_items = $feed->get_items();
        $items = array();
        foreach($sp_items as $item)
        {
        $i['title'] = $item->get_title();
        $i['link'] = $item->get_link();
        $i['content'] = $item->get_content();
        $items[] = $i;
        }
        usort($items,'custom_sort');
        foreach($items as $item)
        {
        //
        // your code
        //
        echo '<p>';
        echo '<a href="',$item['link'],'">',$item['title'],'</a>';
        echo '<br>';
        echo $item['content'];
        echo '</p>';
        }
        function custom_sort($a,$b)
        {
        // assign numerical value so we can sort on
        // whether "term" is in title or content or neither
        $term = 'troops';
        $x = 0;
        if (stripos($a['title'],$term))
        $x = 2;
        elseif(stripos($a['content'],$term))
        $x = 1;
        $y = 0;
        if(stripos($b['title'],$term))
        $y = 2;
        elseif(stripos($b['content'],$term))
        $y = 1;
        return $x <= $y;
        }
        ?>
      • ojsimon3000
        pastebin works again here it is http://simplepie.pastebin.com/mc514d5e Thanks
        Message 3 of 7 , Dec 4, 2008
        View Source
        • 0 Attachment
          pastebin works again here it is http://simplepie.pastebin.com/mc514d5e

          Thanks
        • Ryan Parman
          1) Set default values for $start and $length values 2) Pass the $start and $length values to get_items() 3) Add the HTML controls at the bottom
          Message 4 of 7 , Dec 6, 2008
          View Source
          • 0 Attachment
            1) Set default values for $start and $length values
            2) Pass the $start and $length values to get_items()
            3) Add the HTML controls at the bottom

            http://pastie.org/332991

            --
            Ryan Parman
            <http://ryanparman.com>







            On Dec 4, 2008, at 9:10 AM, ojsimon3000 wrote:

            > pastebin works again here it is http://simplepie.pastebin.com/mc514d5e
            >
            > Thanks
            >
            >
            > ------------------------------------
            >
            > Yahoo! Groups Links
            >
            >
            >
          • ojsimon3000
            Thanks for that much appreciated set_feed_url(array(
            Message 5 of 7 , Dec 7, 2008
            View Source
            • 0 Attachment
              Thanks for that much appreciated






              <?php
              error_reporting(E_ALL);
              require_once('../simplepie.inc');

              $feed = new SimplePie();
              $feed->set_feed_url(array(
              'http://gdata.youtube.com/feeds/api/videos?q=seeing%20doc',
              'http://www.metacafe.com/tags/seeing%20doc/relevance/rss.xml',
              'http://rss.break.com/keyword/nokia/',
              ));
              $feed->init();

              if ($feed->error) exit('<p>'.$feed->error().'</p>');

              $feed->handle_content_type();



              /////////////////////////////////////////////////////////////////////
              // NEW FOR PAGING!

              // Set our paging values
              $start = (isset($_GET['start']) && !empty($_GET['start'])) ? $_GET['start'] : 0; // Where do we
              start?
              $length = (isset($_GET['length']) && !empty($_GET['length'])) ? $_GET['length'] : 5; // How
              many per page?
              $max = $feed->get_item_quantity(); // Where do we end?

              /////////////////////////////////////////////////////////////////////



              /////////////////////////////////////////////////////////////////////
              // CHANGED FOR PAGING!

              // $sp_items = $feed->get_items();
              $sp_items = $feed->get_items($start, $length); // NEW FOR PAGING!
              $items = array();

              /////////////////////////////////////////////////////////////////////

              foreach($sp_items as $item)
              {
              $i['title'] = $item->get_title();
              $i['link'] = $item->get_link();
              $i['content'] = $item->get_content();
              $items[] = $i;
              }

              usort($items,'custom_sort');

              foreach($items as $item)
              {
              //
              // your code
              //
              echo '<p>';
              echo '<a href="',$item['link'],'">',$item['title'],'</a>';
              echo '<br>';
              echo $item['content'];
              echo '</p>';

              echo '<hr>';
              }

              function custom_sort($a, $b)
              {
              // assign numerical value so we can sort on
              // whether "term" is in title or content or neither
              $term = 'troops';
              $x = 0;
              if (stripos($a['title'],$term))
              $x = 2;
              elseif(stripos($a['content'],$term))
              $x = 1;
              $y = 0;
              if(stripos($b['title'],$term))
              $y = 2;
              elseif(stripos($b['content'],$term))
              $y = 1;
              return $x <= $y;
              }


              /////////////////////////////////////////////////////////////////////
              // NEW FOR PAGING!

              // Let's do our paging controls
              $next = (int) $start + (int) $length;
              $prev = (int) $start - (int) $length;

              // Create the NEXT link
              $nextlink = '<a href="?start=' . $next . '&length=' . $length . '">Next »</a>';
              if ($next > $max)
              {
              $nextlink = 'Next »';
              }

              // Create the PREVIOUS link
              $prevlink = '<a href="?start=' . $prev . '&length=' . $length . '">« Previous</a>';
              if ($prev < 0 && (int) $start > 0)
              {
              $prevlink = '<a href="?start=0&length=' . $length . '">« Previous</a>';
              }
              else if ($prev < 0)
              {
              $prevlink = '« Previous';
              }

              // Normalize the numbering for humans
              $begin = (int) $start + 1;
              $end = ($next > $max) ? $max : $next;
              ?>

              <p>Showing <?php echo $begin; ?>–<?php echo $end; ?> out of <?php echo
              $max; ?> | <?php echo $prevlink; ?> | <?php echo $nextlink; ?> | <a href="<?php echo
              '?start=' . $start . '&length=5'; ?>">5</a>, <a href="<?php echo '?start=' . $start .
              '&length=10'; ?>">10</a>, or <a href="<?php echo '?start=' . $start . '&length=20'; ?
              >">20</a> at a time.</p>
            Your message has been successfully submitted and would be delivered to recipients shortly.