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.
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.