We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7575
    • 85 Posts
    Did this ever get worked out?
    greatings

    Djemmers
      www.tornooi.net online database for (sport) events in dutch.
      To be redesigned, rewritten to modx with multiple languages...
      ANY help appreciated, I cannot offer money but I can offer free advertising on the site. just message me.
      • 29635
      • 361 Posts
      http://pastie.org/1113330
      That’s the code. You’ll have to edit the $username and the TV IDs (find the "edit" string halfway through), but it works. Sorry it’s not all nice and documented and packaged and such, but it works really well once you get it going.
        Need MODx Ecommerce? Try FoxyCart!
        • 19309
        • 49 Posts
        Anyone made any progress with this?

        I just landed here searching Google for something like the “WP-o-Matic” WordPress plugin for MODx. But it seems that there is no ready to use extension yet which can import RSS content into documents.
          • 37516
          • 4 Posts
          I have developed a script that can do this! It's configured to my needs, but it's pretty straight forward. Hopefully you can find it useful!

          Note: spiefeed is required for this. If you don't want to install the spiefeed package, just get simplepie and update line 5 to point to the class file.

          <?php
          
            ini_set('display_errors', 1);
          
            require_once(MODX_CORE_PATH . 'components/spiefeed/includes/simplepie/simplepie_1.3.mini.php');
          
            $feeds = $modx->getCollection('modWebLink', [
              'parent' => 127
            ]);
          
            $added = 0;
          
            foreach($feeds as $feed) {
              $rss = new SimplePie();
              $rss->set_cache_location(MODX_CORE_PATH . 'components/spiefeed/cache');
              $rss->set_feed_url($feed->content);
              $rss->init();
              foreach($rss->get_items() as $item) {
                $query = $modx->newQuery('modResource');
                $query->where([
                  'parent' => $feed->id,
                  'longtitle' => $item->get_id(true)
                ]);
                $exists = $modx->getCount('modResource', $query);
                if(!$exists) {
                  $page = $modx->newObject('modResource');
                  $page->set('pagetitle', $item->get_title());
                  $page->set('longtitle', $item->get_id(true));
                  $page->set('description', $item->get_description(true));
                  $page->set('alias', $page->cleanAlias($item->get_title()));
                  $page->set('published', 1);       
                  $page->set('parent', $feed->id);
                  $page->set('content', $item->get_content(true));
                  $page->set('template', 10); // RSS Item
                  $page->set('createdby', 1);
                  $page->set('createdon', time());
                  $page->set('publishedby', 1);
                  $page->set('publishedon', strtotime($item->get_date()));
                  $page->set('hidemenu', 1);
          
                  echo $page->save() ? "Saved {$item->get_id(true)} to {$feed->id}.<br />" : "Error";
          
                  // rssUid 15
                  $page->setTVValue(15, $item->get_id());
          
                  libxml_use_internal_errors(true); // Yeah if you are so worried about using @ with warnings
                  $doc = new DomDocument();
                  $doc->loadHTML(file_get_contents(html_entity_decode($item->get_id())));
                  $xpath = new DOMXPath($doc);
                  $query = '//*/meta[starts-with(@property, \'og:\')]';
                  $metas = $xpath->query($query);
                  foreach ($metas as $meta) {
                      $property = $meta->getAttribute('property');
                      $content = $meta->getAttribute('content');
                      $rmetas[$property] = $content;
                  }
          
                  // rssImgUrl 16
                  $page->setTVValue(16, $rmetas['og:image']);
          
                  foreach($item->get_categories() as $category)
                    $tagString = $category->get_label().", ";
                  $tagString = substr($tagString, 0, -2);
          
                  // rssTags 17
                  $page->setTVValue(17, $tagString);
          
                  $added++;
          
                  if($added == 5)
                    die();
          
                }
              }
            }
          


          This is a snippet, and I execute it using cron manager.