Phpxml operation class (custom)
/**
- Php xml operations
- Link: http://bbs.it-home.org
- */
- Class requirelog
- {
- Protected static $ requirelog;
// Get ready for xml, if xml is not found, create xml
- Static function _ initializeLog ()
- {
- If (file_exists ('requirelog. XML '))
- {
Self: $ requirelog = DOMDocument: load ('requirelog. XML ');
- }
- Else
- {
- Self: $ requirelog = new DOMDocument ('1. 0', 'ISO-8859-1 ');
- Self: $ requirelog-> loadXML (' ');
- Self: $ requirelog-> save ('requirelog. XML ');
- }
- }
- // Obtain all nodes whose finish field is all 0
- Public static function get_entrys ()
- {
- Self: _ initializeLog ();
- $ Entrys = self: $ requirelog-> getElementsByTagName ('entry ');
- $ Entry_arrays = array ();
- Foreach ($ entrys as $ entry)
- {
- If ($ entry-> getElementsByTagName ('finish ')-> item (0)-> nodeValue = 0)
- {
- $ Entry_array = array ();
- $ Entry_array ['id'] = $ entry-> getElementsByTagName ('id')-> item (0)-> nodeValue;
- $ Entry_array ['Time'] = $ entry-> getElementsByTagName ('time')-> item (0)-> nodeValue;
- $ Entry_array ['operator'] = $ entry-> getElementsByTagName ('operator')-> item (0)-> nodeValue;
- $ Entry_array ['byoperator'] = $ entry-> getElementsByTagName ('byoperator')-> item (0)-> nodeValue;
- $ Entry_array ['parameters1'] = $ entry-> getElementsByTagName ('parameters1')-> item (0)-> nodeValue;
- $ Entry_array ['parameters2'] = $ entry-> getElementsByTagName ('parameters2')-> item (0)-> nodeValue;
- $ Entry_array ['parameters3'] = $ entry-> getElementsByTagName ('parameters3')-> item (0)-> nodeValue;
$ Entry_array ['type'] = $ entry-> getElementsByTagName ('type')-> item (0)-> nodeValue;
- $ Entry_array ['module'] = $ entry-> getElementsByTagName ('module')-> item (0)-> nodeValue;
- $ Entry_array ['finish '] = $ entry-> getElementsByTagName ('finish')-> item (0)-> nodeValue;
- $ Entry_arrays [] = $ entry_array;
- }
- }
- Return $ entry_arrays;
- }
-
- // Obtain all nodes
- Public static function get_count_entrys ()
- {
- Self: _ initializeLog ();
- $ Entrys = self: $ requirelog-> getElementsByTagName ('entry ');
- $ Entry_arrays = array ();
- Foreach ($ entrys as $ entry)
- {
$ Entry_array = array ();
- $ Entry_array ['id'] = $ entry-> getElementsByTagName ('id')-> item (0)-> nodeValue;
- $ Entry_array ['Time'] = $ entry-> getElementsByTagName ('time')-> item (0)-> nodeValue;
- $ Entry_array ['operator'] = $ entry-> getElementsByTagName ('operator')-> item (0)-> nodeValue;
- $ Entry_array ['byoperator'] = $ entry-> getElementsByTagName ('byoperator')-> item (0)-> nodeValue;
- $ Entry_array ['parameters1'] = $ entry-> getElementsByTagName ('parameters1')-> item (0)-> nodeValue;
- $ Entry_array ['parameters2'] = $ entry-> getElementsByTagName ('parameters2')-> item (0)-> nodeValue;
- $ Entry_array ['parameters3'] = $ entry-> getElementsByTagName ('parameters3')-> item (0)-> nodeValue;
$ Entry_array ['type'] = $ entry-> getElementsByTagName ('type')-> item (0)-> nodeValue;
- $ Entry_array ['module'] = $ entry-> getElementsByTagName ('module')-> item (0)-> nodeValue;
- $ Entry_array ['finish '] = $ entry-> getElementsByTagName ('finish')-> item (0)-> nodeValue;
- $ Entry_arrays [] = $ entry_array;
}
- Return $ entry_arrays;
- }
// Obtain the node by ID
- Public static function get_entry ($ id)
- {
- Self: _ initializeLog ();
- $ Count = count (self: get_count_entrys ());
- If ($ count> 0)
- {
- $ Entrys = self: $ requirelog-> getElementsByTagName ('entry ');
- Foreach ($ entrys as $ entry)
- {
- If ($ id = $ entry-> getElementsByTagName ('id')-> item (0)-> nodeValue)
- {
- $ Entry_array = array ();
- $ Entry_array ['id'] = $ entry-> getElementsByTagName ('id')-> item (0)-> nodeValue;
- $ Entry_array ['Time'] = $ entry-> getElementsByTagName ('time')-> item (0)-> nodeValue;
- $ Entry_array ['operator'] = $ entry-> getElementsByTagName ('operator')-> item (0)-> nodeValue;
- $ Entry_array ['byoperator'] = $ entry-> getElementsByTagName ('byoperator')-> item (0)-> nodeValue;
- $ Entry_array ['parameters1'] = $ entry-> getElementsByTagName ('parameters1')-> item (0)-> nodeValue;
- $ Entry_array ['parameters2'] = $ entry-> getElementsByTagName ('parameters2')-> item (0)-> nodeValue;
- $ Entry_array ['parameters3'] = $ entry-> getElementsByTagName ('parameters3')-> item (0)-> nodeValue;
$ Entry_array ['type'] = $ entry-> getElementsByTagName ('type')-> item (0)-> nodeValue;
- $ Entry_array ['module'] = $ entry-> getElementsByTagName ('module')-> item (0)-> nodeValue;
- $ Entry_array ['finish '] = $ entry-> getElementsByTagName ('finish')-> item (0)-> nodeValue;
- Return $ entry_array;
- }
- }
- }
- Else
- Return null;
- }
// After the user request is executed, change the finsh field
- Public static function do_finsh ($ id)
- {
- Self: _ initializeLog ();
- $ Entrys = self: $ requirelog-> getElementsByTagName ('entry ');
- $ Entry_arrays = array ();
- Foreach ($ entrys as $ entry)
- {
- If ($ entry-> getElementsByTagName ('id')-> item (0)-> nodeValue = $ id)
- {
- $ Entry-> getElementsByTagName ('finish ')-> item (0)-> nodeValue = 1;
- }
- }
Self: $ requirelog-> save ('requirelog. XML ');
- }
// Add a new node. $ operator is the operator, $ byoperator is the object to be operated, $ parameters1, 2 and 3 are extensible parameters, $ type is the type, and $ module is the affected module.
- Static function add_entry ($ operator, $ byoperator, $ parameters1, $ parameters2, $ parameters3, $ type, $ module)
- {
- // $ Contents = self: $ restlog-> getElementsByTagName ('contents ');
Self: _ initializeLog ();
- $ Count = count (self: get_count_entrys ());
$ Entry = self ::$ requirelog-> createElement ('entry ');
$ Id = self ::$ requirelog-> createElement ('id ');
- $ Idvalue = self: $ requirelog-> createTextNode ($ count + 1 );
- $ Id-> appendChild ($ idvalue );
$ Time = self: $ requirelog-> createElement ('time ');
- $ Timevalue = self ::$ requirelog-> createTextNode (date ("Y-m-d H: I: s", time ()));
- $ Time-> appendChild ($ timevalue );
$ Op = self ::$ requirelog-> createElement ('operator ');
- $ Opvalue = self: $ requirelog-> createTextNode ($ operator );
- $ Op-> appendChild ($ opvalue );
$ Bop = self ::$ requirelog-> createElement ('byoperator ');
- $ Bopvalue = self: $ requirelog-> createTextNode ($ byoperator );
- $ Bop-> appendChild ($ bopvalue );
$ Ps1 = self: $ requirelog-> createElement ('parameters1 ');
- $ Ps1value = self: $ requirelog-> createTextNode ($ parameters1 );
- $ Ps1-> appendChild ($ ps1value );
$ Ps2 = self: $ requirelog-> createElement ('parameters2 ');
- $ Ps2value = self: $ requirelog-> createTextNode ($ parameters2 );
- $ Ps2-> appendChild ($ ps2value );
$ Ps3 = self ::$ requirelog-> createElement ('parameters3 ');
- $ Ps3value = self: $ requirelog-> createTextNode ($ parameters3 );
- $ Ps3-> appendChild ($ ps3value );
- $ Tp = self ::$ requirelog-> createElement ('type ');
- $ Tpvalue = self: $ requirelog-> createTextNode ($ type );
- $ Tp-> appendChild ($ tpvalue );
$ Md = self ::$ requirelog-> createElement ('module ');
- $ Mdvalue = self: $ requirelog-> createTextNode ($ module );
- $ Md-> appendChild ($ mdvalue );
$ Fi = self ::$ requirelog-> createElement ('finish ');
- $ Fivalue = self: $ requirelog-> createTextNode (0 );
- $ Fi-> appendChild ($ fivalue );
$ Entry-> appendChild ($ id );
- $ Entry-> appendChild ($ time );
- $ Entry-> appendChild ($ op );
- $ Entry-> appendChild ($ bop );
- $ Entry-> appendChild ($ ps1 );
- $ Entry-> appendChild ($ ps2 );
- $ Entry-> appendChild ($ ps3 );
- $ Entry-> appendChild ($ tp );
- $ Entry-> appendChild ($ md );
- $ Entry-> appendChild ($ fi );
Self: $ requirelog-> documentElement-> appendChild ($ entry );
- Self: $ requirelog-> save ('requirelog. XML ');
Return 1;
- }
- }
- ?>
2. the requirelog. xml file is in the following format:
-
-
-
- 1
- 16:56:33
- Peng. zhou
- Zxcxzcxzczxcxz
- Cxzcxzc
-
-
- Add_group
- Cn_group
- 1
-
-
- 2
- 16:56:53
- Peng. zhou
- Sales
-
-
-
- Add_member
- Mail_group
- 1
-
|