We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1900
    • 3 Posts
    One of my clients wants to be able to add posts to their Ditto blog (on a version 0.9.6.3 install) by sending an email to a designated address. I’ve written a class that enables this by checking a specified account and processing the messages with php’s imap functions and then inserting the content from each message as a new record in the site content table. This all works fine, the new documents show up in the manager document tree, but the documents don’t appear Ditto listings until we manually refresh the site cache. (It makes no difference whether the snippet calls are cached or uncached or on a cached or uncached page.)

    I think this is because I can’t run the sync cache processor from within my script. My first question is whether this is in fact the cause of the problem.

    I haven’t been able to see a way of triggering a cache sync from outside modx. Would it be possible to instantiate a new DocumentParser in my script and trigger the cache sync that way? I’ve cursorily tried modifying some of the code from /manager/index.php to do this, but ran into some initial problems (no errors, but the script exits once the document parser class is included), and didn’t want to pursue it further till I knew it was even possible or advisable.

    Any other suggestions?

    Thanks a lot,

    Aaron
      • 7231
      • 4,205 Posts
      Maybe this article can help: http://sottwell.com/email-posting.html
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don't know what it is.
        Do you, Mr. Jones? - [bob dylan]
      • I didn’t get into it all that much; it was just an interesting idea that I thought could be improved on if somebody liked the idea.

        I would be inclined to use a modified save_content.processor.php file. You would need to modify where the data comes from (instead of POST values).

        It would be much the same as an AJAX application http://wiki.modxcms.com/index.php/Use_AJAX_with_modxAPI

        If you make it a snippet in a document, you’ll have the $modx object and all of its object functions available. If it’s a stand-alone .php file, then you’ll need to include the config.inc.php file and the document.parser.class.inc.php file.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 1900
          • 3 Posts
          Thanks, these hints got me over the hump. I ended up switching over to using the beta "CakeMODx" API (http://modxcms.com/forums/index.php?topic=35663.0) for creating the new documents. The API also happens to have an "updateCache" method, which solved my problems. It’s all working great now.

          -Aaron
            • 7231
            • 4,205 Posts
            Cool solution...how did you like the CakeMODx API? Did you only need the Cake class without having to load up the MODx engine?
              [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

              Something is happening here, but you don't know what it is.
              Do you, Mr. Jones? - [bob dylan]
              • 1900
              • 3 Posts
              Quote from: dev_cw at Jul 02, 2009, 05:59 PM

              Cool solution...how did you like the CakeMODx API? Did you only need the Cake class without having to load up the MODx engine?

              I didn’t play around with the API too much, but it certainly worked perfectly for what I needed. Was very easy to set up and use. The class assumes the existence of the $modx variable, referring to a DocumentParser object, so you do have to load that up before including the API class, e.g.

              // Setup the MODx API
              define('MODX_API_MODE', true);
              // initiate a new document parser
              include_once(MODX_MANAGER_PATH.'/includes/document.parser.class.inc.php');
              $modx = new DocumentParser;
               
              $modx->db->connect(); // provide the MODx DBAPI
              $modx->getSettings(); // provide the $modx->documentMap and user settings