We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14778
    • 13 Posts
    I’ve been working on some custom scripting to handle a dynamic news section on a clients site. Their site is using modX Evo 1.0.3. About half of the scripting is external from modx iteself, but here’s a rundown of what I have and what I need to get done:

    Completed

    • A cron script scrapes articles from various external sources.
    • An email is sent to the user displaying article information with a link after each to "publish document"
    • Once link is clicked, user is directed to a staging page where article information is populated into various form fields (publish date, title, description, etc).

    Here’s where I need some help. On form submit, I’d like it to run a snippet, where a document is created in the news section of the page tree (I already have this set up in the page tree that manually-created articles are distributed to smaller sections using Ditto). I looked through the API and couldn’t find anything like what I was looking for (I was thinking of like a modx->createResource haha). Is something like this possible? Would it be easier to just directly inject information into the DB? Any help would be greatly appreciated. The site is http://www.keystonebiofuels.com if that helps give a better idea of how the articles are being displayed. Hopefully this all makes sense, if more information is needed please just ask!

    Thanks!
      • 3749
      • 24,544 Posts
      Take a look at the NewsPublisher snippet: http://modxcms.com/forums/index.php/topic,3220.0.html

      The blog code from kp52 also creates documents: http://modxcms.com/forums/index.php/topic,38685.0.html

      BTW, since you are pretty much rolling your own stuff here, you might consider switching to MODx Revolution where creating resources and assigning them to containers is easier:

      <?php
      $containerID='12';
      
      $object = $modx->newObject('modDocument');
      $object->set('name', 'MyDocument');
      $object->set('published', '0');
      $object->setContent('This will be the content of the new doc.');
      $object->set('description', 'I created this doc in a snippet');
      $object->set('parent', $containerID);
      $object->save(); 

        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 16278
        • 928 Posts
        PubKitBlog and PubKit actually use ur001’s DocManager (Document class) to create new resources. It sounds a good match for your requirement. Just watch out for the short PHP tag at the start, which can cause problems if you don’t replace it.
        smiley KP
          • 14778
          • 13 Posts
          Thanks guys,

          I actually found pubKit yesterday and tried it out, but after taking a look at pubKitBlog I think that will be a better fit, don’t need all the features of pubKit. I’ll let you know how I do, Thanks for the help!