*Experimental* Patch: AJAX Auto-backup pages to your Email while Editing
Posted: Sat Jun 21, 2008 1:00 am
I've just spent a couple hours making this experimental patch for admin/editcontent.php which automatically emails you the contents of the editcontent.php form every 3 minutes:
The code still has debugging "alert()" statements in it so you'll want to remove those so you don't get annoyed every 3 minutes. 
Make sure you find this line and change it to your email:
I'm attaching my modified admin/editcontent.php if you want to try it out instead of using the above patch.
What do you think?
It'd be cool if we could work together to improve this.
Maybe I'll get around to improving it later. We'll see.
Now I'll be able to edit pages with less worry of losing more than 3 minutes of work.

Be careful! Some web hosts might not want you sending emails every 3 minutes while editing a page.
Enjoy,
Elijah Lofgren
Code: Select all
Index: editcontent.php
===================================================================
--- editcontent.php (revision 5)
+++ editcontent.php (working copy)
-34,8 +34,10 @@
$xajax = new xajax();
$xajax->registerFunction('ajaxpreview');
+$xajax->registerFunction('ajaxemailbackup');
+
$xajax->processRequests();
-$headtext = $xajax->getJavascript('../lib/xajax')."\n";
+$headtext = $xajax->getJavascript('../lib/xajax');
if (isset($_POST["cancel"]))
{
-62,14 +64,77 @@
$apply = false;
if (isset($_POST["applybutton"])) $apply = true;
+
+if (isset($_POST["ajaxemailbackup"])) {
+
+
+
+ global $gCms;
+ $config =& $gCms->GetConfig();
+ $contentops =& $gCms->GetContentOperations();
+
+ $content_type = $params['content_type'];
+ $contentops->LoadContentType($content_type);
+ $contentobj = UnserializeObject($_POST["serialized_content"]);
+
+
+
+/*
+ #Fill contentobj with parameters
+ $contentobj->FillParams($_POST);
+ $error = $contentobj->ValidateData();
+
+ if (isset($_POST["ownerid"]))
+ {
+ $contentobj->SetOwner($_POST["ownerid"]);
+ }
+
+ #Fill Additional Editors (kind of kludgy)
+ if (isset($_POST["additional_editors"]))
+ {
+ $addtarray = array();
+ foreach ($_POST["additional_editors"] as $addt_user_id)
+ {
+ $addtarray[] = $addt_user_id;
+ }
+ $contentobj->SetAdditionalEditors($addtarray);
+ }
+ else if ($adminaccess)
+ {
+ $contentobj->SetAdditionalEditors(array());
+ }
+
+*/
+
+
+
+
+
+
+
+ $cmsmailer =& $gCms->modules['CMSMailer']['object'];
+ $cmsmailer->AddAddress('YOUR_EMAIL@example.com');
+ $cmsmailer->SetBody(print_r($contentobj,true));
+ $cmsmailer->IsHTML(false);
+ $cmsmailer->SetSubject('Test Email Backup for CMSMs');
+ $cmsmailer->Send();
+exit("it worked to email");
+
+
+
+}
+
$ajax = false;
if (isset($_POST['ajax']) && $_POST['ajax']) $ajax = true;
+
+
if ($preview || $apply)
{
$CMS_EXCLUDE_FROM_RECENT=1;
}
+
function ajaxpreview($params)
{
global $gCms;
-356,6 +421,62 @@
$headtext .= <<<EOSCRIPT
<__script__ type="text/javascript">
+
+Edit_Content_EmailBackup = function() {
+
+ alert("backing up");
+
+ var data = new Array();
+ data.push('ajaxemailbackup=1');
+
+ var elements = Form.getElements($('contentform'));
+ for (var cnt = 0; cnt < elements.length; cnt++)
+ {
+ var elem = elements[cnt];
+ if (elem.type == 'submit')
+ {
+ continue;
+ }
+ var query = Form.Element.serialize(elem);
+ data.push(query);
+ }
+
+ new Ajax.Request(
+ '{$_SERVER['REQUEST_URI']}'
+ , {
+ method: 'post'
+ , parameters: data.join('&')
+ , onSuccess: function(t)
+ {
+ alert("backup worked");
+ }
+ , onFailure: function(t)
+ {
+ alert('Could not save: ' + t.status + ' -- ' + t.statusText);
+ }
+ }
+ );
+
+ return false;
+
+
+}
+
+function StartTimer()
+{
+every_millisecs = 180000
+ var Timer = setInterval("DoAJAXEmailBackup()", every_millisecs);
+}
+
+function DoAJAXEmailBackup()
+{
+ $('ajaxbackupbutton').onclick();
+}
+
+
+StartTimer();
+
+
window.Edit_Content_Apply = function(button)
{
$addlScriptSubmit
-515,6 +636,10 @@
*/
$submit_buttons .= ' <input type="submit" name="cancel" value="'.lang('cancel').'" class="pagebutton" onclick="return confirm(\''.lang('confirmcancel').'\');" onmouseover="this.className=\'pagebuttonhover\'" onmouseout="this.className=\'pagebutton\'" title="'.lang('canceldescription').'" />';
$submit_buttons .= ' <input type="submit" onclick="return window.Edit_Content_Apply(this);" name="applybutton" value="'.lang('apply').'" class="pagebutton" onmouseover="this.className=\'pagebuttonhover\'" onmouseout="this.className=\'pagebutton\'" title="'.lang('applydescription').'" />
+<input type="submit" onclick="return window.Edit_Content_EmailBackup(this);" name="ajaxbackupbutton" id="ajaxbackupbutton" value="Backup via Email" class="pagebutton"
+onmouseover="this.className=\'pagebuttonhover\'" onmouseout="this.className=\'pagebutton\'" title="'.lang('applydescription').'" />
+
+
</p>
</div>';
//echo $submit_buttons;

Make sure you find this line and change it to your email:
Code: Select all
+ $cmsmailer->AddAddress('YOUR_EMAIL@example.com');
What do you think?
It'd be cool if we could work together to improve this.

Maybe I'll get around to improving it later. We'll see.

Now I'll be able to edit pages with less worry of losing more than 3 minutes of work.



Be careful! Some web hosts might not want you sending emails every 3 minutes while editing a page.

Enjoy,
Elijah Lofgren