We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36686
    • 165 Posts
    Creating a blog in MODx seems pretty straight forward if following the guide at http://rtfm.modx.com/display/revolution20/Creating+a+Blog+in+MODx+Revolution

    It would be awesome to be able to upload photos etc to the blog using a mobile phone/by email. Any ideas about how this could be achieved? If someone wants to develop a snippet for this I’m prepared to pay for it!
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      Little late, perhaps. But this is an amazing resource (as well as the follow up article) to publish via email: http://sottwell.com/email-posting.html
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 36686
        • 165 Posts
        Thanks a lot for the tip Mark, not too late at all! Does that mean I can just take Susan’s final code (http://sottwell.com/assets/files/downloads/parsemail3.txt), adjust with my own email address etc. and put it into a snippet that I then call - or how do I make it work...? Will it still work with Revo?
          • 18373 ☆ A M B ☆
          • 3,141 Posts
          Oops, sorry. Didn’t realize that was an Evo example.

          Most of it will work out of the box as it’s simply connecting to the IMAP server and parsing the data. Things you’ll need to change are:
                  // won't be needed when this is made into a module
                  include "manager/includes/config.inc.php";
                  $conn = mysql_connect($database_server, $database_user, $database_password) or die(mysql_error());
                  $db = mysql_select_db(trim($dbase, '`')) or die(mysql_error());

          In Revo, this should do the trick:
          require_once '/absolute/path/to/modx/config.core.php';
          require_once MODX_CORE_PATH.'config/'.MODX_CONFIG_KEY.'.inc.php';
          require_once MODX_CORE_PATH.'model/modx/modx.class.php';
          $modx = new modX();
          $modx->initialize('web');

          (from http://rtfm.modx.com/display/revolution20/Loading+MODx+Externally)
          Remember to change your parth to the config.core.php file. I also think you’ll need to change $modx->initialize(’web’); to $modx->initialize(’mgr’); to add new objects (we’ll come to that).

          The cleaning up part is fine, although I believe xPDO handles cleaning up data sent to it also. But can’t hurt to do it extra I guess. (If when you’re trying this your resources are getting escaped values, get rid of the cleaning up part and try again).

          Next:
                  // get submitter's ID
                  $sql = "SELECT internalKey FROM " . $table_prefix . "user_attributes WHERE fullname = '$createdby'";
                  $res = mysql_query($sql) or die(mysql_error());
                  $num = mysql_num_rows($res);
                  if($num == 1) { // there had better be one and only one
                      $createdby = mysql_result($res, 0);
                      $sql = "INSERT INTO " . $table_prefix . "site_content (pagetitle, introtext, content, parent, template, createdon, createdby) VALUES ('$pagetitle', '$introtext', '$content', $parent, $template, time(), $createdby)";
                      mysql_query($sql) or die(mysql_error());
                  }

          This is where the big differences will be. As a random thought, I’m not sure if you can access anything without some form of authentification but I hope someone can add to that.

          First off, to fetch the user id, you’d do something like this:
          $u = $modx->getObject('modUserProfile', array(
            'fullname' => $createdby));
            $uu = $u->getOne('modUser');
            $uid = $uu->get('id');

          Maybe id should be internalKey, could not find that as fast as I wanted, lol.

          Then if you want to save your new resource:
          $res = $modx->newObject('modDocument');
          $res->set('pagetitle',$pagetitle);
          $res->set('createdby',$uid);
          $res->set('introtext',$introtext);
          $res->setContent($content);
          $res->set('parent',$parent);
          $res->set('template',$template);
          
          //And don't forget to save
          $res->save();


          Totally untested, but hopefully should get you started on making it Revo proof.

          I made a few notes in this post I’m not really sure of, so I hope someone else knows the answer to those questions.. or you can try and find out, hehe. tongue

          You’d probably need to set up a cron job to check the email, or put a snippet with that code (minus the first part) on your site somewhere so you can use that as a trigger to check it.
            Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

            Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
            • 36686
            • 165 Posts
            Thanks Mark, I’ll give this a go. But where do I put all the code once I’m done...? In a snippet? Where do I call the snippet? Or do I upload a file somewhere? Sorry for being thick...
              • 18373 ☆ A M B ☆
              • 3,141 Posts
              All is possible.

              If you put it in a seperate .php file you’ll need this:
              require_once '/absolute/path/to/modx/config.core.php';
              require_once MODX_CORE_PATH.'config/'.MODX_CONFIG_KEY.'.inc.php';
              require_once MODX_CORE_PATH.'model/modx/modx.class.php';
              $modx = new modX();
              $modx->initialize('web');

              If you put it in a snippet on a page in the front-end you wont, but I’m not sure on how the manager permissions work when doing that.

              If you put it in an external file (so outside of MODx) you’ll need to find a way to call it to check if there’s any messages for you, which is very well possible with a CRON job (a server-side timer, sort of).
                Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                • 36686
                • 165 Posts
                Great, I’ll get back onto this after the holidays. Merry x-mas!!!