芝麻web文件管理V1.00
编辑当前文件:/home/projzpbv/www/wp-content/plugins/calculated-fields-form/inc/cpcff_revisions.inc.php
_db = $wpdb; $this->_table = $wpdb->prefix . CP_CALCULATEDFIELDSF_FORMS_REVISIONS_TABLE; $this->_form_obj = $form_obj; } // End construct. /** * Returns the list of revisions rows in the database as array */ public function revisions_list() { if ( empty( $this->_revisions ) ) { $results = $this->_db->get_results( $this->_db->prepare( 'SELECT * FROM ' . $this->_table . ' WHERE formid=%d ORDER BY time DESC', $this->_form_obj->get_id() ), ARRAY_A ); $this->_revisions = array(); foreach ( $results as $revision ) { $this->_revisions[ $revision['id'] ] = $revision; } } return $this->_revisions; } // End revisions_list. /** * Creates a new entry in the revisions table, if there are more than _max revisions remove the older. * * @return int returns the revision's id or false if fails. */ public function create_revision() { $form_data = $this->_form_obj->get_raw_data(); $data = array( 'formid' => $this->_form_obj->get_id(), 'time' => current_time( 'mysql' ), 'revision' => serialize( $form_data ), ); if ( $this->_db->insert( $this->_table, $data, array( '%d', '%s', '%s' ) ) ) { $this->revisions_list(); $data['id'] = $this->_db->insert_id; $this->_revisions[ $data['id'] ] = $data; krsort( $this->_revisions ); if ( $this->_max < count( $this->_revisions ) ) { array_splice( $this->_revisions, $this->_max ); $this->_delete_older(); } return $data['id']; } return false; } // End create_revision. /** * Returns the form data unserialized or an empty array * * @param integer $revision_id revision id. */ public function data( $revision_id ) { $this->revisions_list(); if ( ! empty( $this->_revisions ) && isset( $this->_revisions[ $revision_id ] ) ) { return unserialize( $this->_revisions[ $revision_id ]['revision'] ); } return array(); } // End data. /** * Deletes the list of revisions belonging to the form */ public function delete_form() { $this->_db->delete( $this->_table, array( 'formid' => $this->_form_obj->get_id() ), array( '%d' ) ); $this->_revisions = array(); } // End delete_form. /*********************************** PRIVATE METHODS ********************************************/ /** * Deletes the older revisions, leaving only the _max */ private function _delete_older() { $formid = $this->_form_obj->get_id(); $revisionid = $this->_db->get_var( $this->_db->prepare( 'SELECT id FROM ' . $this->_table . ' WHERE formid=%d ORDER BY id DESC LIMIT %d,1', $formid, $this->_max ) ); if ( ! empty( $revisionid ) ) { $this->_db->query( $this->_db->prepare( 'DELETE FROM ' . $this->_table . ' WHERE formid=%d AND id < %d', $formid, $revisionid ) ); } } // End _delete_older. } // End CPCFF_REVISIONS. }