add('name', PLUGIN_EVENT_AUTOSAVE_TITLE); $propbag->add('description', PLUGIN_EVENT_AUTOSAVE_DESC); $propbag->add('stackable', false); $propbag->add('author', 'Jay Bertrand'); $propbag->add('requirements', array( 'serendipity' => '0.9', 'smarty' => '2.6.7', 'php' => '4.1.0' )); $propbag->add('version', '0.3'); $propbag->add('configuration', array()); $propbag->add('event_hooks', array( 'backend_entryform' => true, 'external_plugin' => true, 'backend_entry_presave' => true, 'backend_save' => true )); $propbag->add('configuration', array('frequency','path')); $propbag->add('groups', array('BACKEND_EDITOR')); } function introspect_config_item($name, &$propbag) { switch($name) { case 'frequency': $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_EVENT_AUTOSAVE_INTERVAL); $propbag->add('description', PLUGIN_EVENT_AUTOSAVE_INTERVAL_DESC); $propbag->add('validate', '/^[0-9]+$/'); $propbag->add('validate_error', PLUGIN_EVENT_AUTOSAVE_INTERVAL_ERROR); $propbag->add('default', '300'); break; case 'path': $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_EVENT_AUTOSAVE_HTTPATH); $propbag->add('description', PLUGIN_EVENT_AUTOSAVE_HTTPATH_DESC); $propbag->add('validate', '/[^\\*|]/'); $propbag->add('validate_error', PLUGIN_EVENT_AUTOSAVE_HTTPATH_ERROR); $propbag->add('default', 'plugins/serendipity_event_autosave'); break; default: return false; break; } return true; } function generate_content(&$title) { $title = PLUGIN_EVENT_AUTOSAVE_TITLE; } function event_hook($event, &$bag, &$eventData, $addData = null) { global $serendipity; $hooks = &$bag->get('event_hooks'); if (isset($hooks[$event])) { switch($event) { case 'backend_entry_presave': if(isset($serendipity['POST']['shadowed']) && is_numeric($serendipity['POST']['shadowed'])) // update last_modified to make sure the shadow copy is more recent than the original post $eventData['last_modified'] = time(); break; case 'backend_save': // dirty hack to confirm an entry has been saved $this->saveSuccessfull = true; // entry has been successfully saved, delete shadow copies of it (if any) // REM: this hook is also called when saving the shadow copy $ret = serendipity_db_query("SELECT value FROM {$serendipity['dbPrefix']}entryproperties ". "WHERE entryid={$eventData['id']} AND property='".PLUGIN_EVENT_AUTOSAVE_PROP_SHADOW."'", true /*single*/); if(is_array($ret)) { // drop shadow copy and extra properties serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}entries WHERE id=".(int)current($ret)); serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}entryproperties ". "WHERE entryid={$eventData['id']} AND property='".PLUGIN_EVENT_AUTOSAVE_PROP_SHADOW."'", true /*single*/); } break; case 'backend_entryform': if (version_compare(serendipity_getCoreVersion($serendipity['version']), "2.0", ">=")) { // Autosave plugin no longer supported echo '
The serendipity_event_autosave Plugin is no longer supported in Serendipity 2.0 - you should remove it from your installation.
'; echo 'Please note that Serendipity 2.0 will save your written entry in the browser, and restore it upon crash.
'; return true; } ?>